Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 157415
b: refs/heads/master
c: 0494e08
h: refs/heads/master
i:
  157413: e4e4fcc
  157411: 2ac6eb4
  157407: 264d8e7
v: v3
  • Loading branch information
Sergey Senozhatsky authored and Catalin Marinas committed Aug 27, 2009
1 parent 62d9f24 commit 8bc9db7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 008139d9146f9afee0e58df4b7422d0c9921f8ce
refs/heads/master: 0494e08281d08f0a3dc442eb5e5cecc125b53b27
39 changes: 39 additions & 0 deletions trunk/mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ struct kmemleak_object {
/* flag set on newly allocated objects */
#define OBJECT_NEW (1 << 3)

/* number of bytes to print per line; must be 16 or 32 */
#define HEX_ROW_SIZE 16
/* number of bytes to print at a time (1, 2, 4, 8) */
#define HEX_GROUP_SIZE 1
/* include ASCII after the hex output */
#define HEX_ASCII 1
/* max number of lines to be printed */
#define HEX_MAX_LINES 2

/* the list of all allocated objects */
static LIST_HEAD(object_list);
/* the list of gray-colored objects (see color_gray comment below) */
Expand Down Expand Up @@ -258,6 +267,35 @@ static void kmemleak_disable(void);
kmemleak_disable(); \
} while (0)

/*
* Printing of the objects hex dump to the seq file. The number of lines to be
* printed is limited to HEX_MAX_LINES to prevent seq file spamming. The
* actual number of printed bytes depends on HEX_ROW_SIZE. It must be called
* with the object->lock held.
*/
static void hex_dump_object(struct seq_file *seq,
struct kmemleak_object *object)
{
const u8 *ptr = (const u8 *)object->pointer;
int i, len, remaining;
unsigned char linebuf[HEX_ROW_SIZE * 5];

/* limit the number of lines to HEX_MAX_LINES */
remaining = len =
min(object->size, (size_t)(HEX_MAX_LINES * HEX_ROW_SIZE));

seq_printf(seq, " hex dump (first %d bytes):\n", len);
for (i = 0; i < len; i += HEX_ROW_SIZE) {
int linelen = min(remaining, HEX_ROW_SIZE);

remaining -= HEX_ROW_SIZE;
hex_dump_to_buffer(ptr + i, linelen, HEX_ROW_SIZE,
HEX_GROUP_SIZE, linebuf, sizeof(linebuf),
HEX_ASCII);
seq_printf(seq, " %s\n", linebuf);
}
}

/*
* Object colors, encoded with count and min_count:
* - white - orphan object, not enough references to it (count < min_count)
Expand Down Expand Up @@ -308,6 +346,7 @@ static void print_unreferenced(struct seq_file *seq,
object->pointer, object->size);
seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n",
object->comm, object->pid, object->jiffies);
hex_dump_object(seq, object);
seq_printf(seq, " backtrace:\n");

for (i = 0; i < object->trace_len; i++) {
Expand Down

0 comments on commit 8bc9db7

Please sign in to comment.