linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: kmemleak hexdump proposal
Date: Sun, 28 Jun 2009 20:36:32 +0300	[thread overview]
Message-ID: <20090628173632.GA3890@localdomain.by> (raw)

Hello.
What do you think about ability to 'watch' leaked region? (hex + ascii).
(done via lib/hexdump.c)

To turn on hex dump:
echo "hexdump=on" > /sys/kernel/debug/kmemleak

/**
Or (as alternative):
echo "hexdump=f6aac7f8" > /sys/kernel/debug/kmemleak
where f6aac7f8 - object's pointer.
**/

cat /sys/kernel/debug/kmemleak

unreferenced object 0xf6aac7f8 (size 32):
  comm "swapper", pid 1, jiffies 4294877610
HEX dump:
70 6e 70 20 30 30 3a 30 61 00 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a a5  pnp 00:0a.ZZZZZZZZZZZZZZZZZZZZZ.

  backtrace:
    [<c10e92eb>] kmemleak_alloc+0x11b/0x2b0
    [<c10e4b91>] kmem_cache_alloc+0x111/0x1c0
    [<c12c424e>] reserve_range+0x3e/0x1b0
    [<c12c4454>] system_pnp_probe+0x94/0x140
    [<c12baf84>] pnp_device_probe+0x84/0x100
    [<c12f1919>] driver_probe_device+0x89/0x170
    [<c12f1a99>] __driver_attach+0x99/0xa0
    [<c12f1028>] bus_for_each_dev+0x58/0x90
    [<c12f1764>] driver_attach+0x24/0x40
    [<c12f0804>] bus_add_driver+0xc4/0x290
    [<c12f1e10>] driver_register+0x70/0x130
    [<c12bacd6>] pnp_register_driver+0x26/0x40
    [<c15d4620>] pnp_system_init+0x1b/0x2e
    [<c100115f>] do_one_initcall+0x3f/0x1a0
    [<c15aa4af>] kernel_init+0x13e/0x1a6
    [<c1003e07>] kernel_thread_helper+0x7/0x10
unreferenced object 0xf63f4d18 (size 192):
  comm "swapper", pid 1, jiffies 4294878292
HEX dump:
3c 06 00 00 00 00 00 00 78 69 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00  <.......xi......................
25 0c 00 00 00 00 00 00 25 0c 00 00 00 00 00 00 32 05 00 00 00 00 00 00 60 54 00 00 00 00 00 00  %.......%.......2.......`T......
0a 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 1f 0a 00 00 00 00 00 00 1f 0a 00 00 00 00 00 00  ................................
28 04 00 00 00 00 00 00 48 3f 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00  (.......H?......................
19 08 00 00 00 00 00 00 19 08 00 00 00 00 00 00 1e 03 00 00 00 00 00 00 30 2a 00 00 00 00 00 00  ........................0*......
0a 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 13 06 00 00 00 00 00 00 13 06 00 00 00 00 00 00  ................................

  backtrace:
    [<c10e92eb>] kmemleak_alloc+0x11b/0x2b0
    [<c10e584d>] __kmalloc+0x16d/0x210
    [<c12b5757>] acpi_processor_register_performance+0x28e/0x468
    [<c1016797>] acpi_cpufreq_cpu_init+0x97/0x560
    [<c134d802>] cpufreq_add_dev+0x122/0x580
    [<c12efd47>] sysdev_driver_register+0xa7/0x140
    [<c134ca4e>] cpufreq_register_driver+0x9e/0x170
    [<c15b4e0f>] acpi_cpufreq_init+0x8b/0xcd
    [<c100115f>] do_one_initcall+0x3f/0x1a0
    [<c15aa4af>] kernel_init+0x13e/0x1a6
    [<c1003e07>] kernel_thread_helper+0x7/0x10
    [<ffffffff>] 0xffffffff

To disable hex dump:
echo "hexdump=off" > /sys/kernel/debug/kmemleak

I guess it could safe someone's time.
(May be, showed examples aren't so good. Just to demonstrate the idea.)

(concept. feel free to ask for comments.)

diff -u -p

--- kmemleak.c	2009-06-28 20:18:59.000000000 +0300
+++ linux-2.6-sergey/mm/kmemleak.c	2009-06-28 20:21:29.000000000 +0300
@@ -160,6 +160,13 @@ struct kmemleak_object {
 /* flag set to not scan the object */
 #define OBJECT_NO_SCAN		(1 << 2)
 
+/* number of bytes to print per line; must be 16 or 32 */
+#define HEX_ROW_SIZE 32
+/* 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
+
 /* the list of all allocated objects */
 static LIST_HEAD(object_list);
 /* the list of gray-colored objects (see color_gray comment below) */
@@ -182,6 +189,9 @@ static atomic_t kmemleak_early_log = ATO
 /* set if a fata kmemleak error has occurred */
 static atomic_t kmemleak_error = ATOMIC_INIT(0);
 
+/* set if HEX dump should be printed */
+static atomic_t kmemleak_hex_dump = ATOMIC_INIT(0);
+
 /* minimum and maximum address that may be valid pointers */
 static unsigned long min_addr = ULONG_MAX;
 static unsigned long max_addr;
@@ -290,6 +300,29 @@ static int unreferenced_object(struct km
 			       jiffies_last_scan);
 }
 
+
+static void object_hex_dump(struct seq_file *seq, struct kmemleak_object *object)
+{
+	const u8 *ptr = (const u8*)object->pointer;
+	int len = object->size;
+	int i, linelen, remaining = object->size;
+	unsigned char linebuf[200];
+	
+	seq_printf(seq, "HEX dump:\n");
+	
+	for (i = 0; i < len; i += HEX_ROW_SIZE) {
+		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);	
+	}
+	
+	seq_printf(seq, "\n");
+}
+
+
 /*
  * Printing of the unreferenced objects information to the seq file. The
  * print_unreferenced function must be called with the object->lock held.
@@ -301,10 +334,17 @@ static void print_unreferenced(struct se
 
 	seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n",
 		   object->pointer, object->size);
+
 	seq_printf(seq, "  comm \"%s\", pid %d, jiffies %lu\n",
 		   object->comm, object->pid, object->jiffies);
-	seq_printf(seq, "  backtrace:\n");
 
+	/* check whether hex dump should be printed*/
+	if (atomic_read(&kmemleak_hex_dump))
+		object_hex_dump(seq, object);
+	
+	
+	seq_printf(seq, "  backtrace:\n");
+	
 	for (i = 0; i < object->trace_len; i++) {
 		void *ptr = (void *)object->trace[i];
 		seq_printf(seq, "    [<%p>] %pS\n", ptr, ptr);
@@ -1269,6 +1309,12 @@ static ssize_t kmemleak_write(struct fil
 		start_scan_thread();
 	else if (strncmp(buf, "scan=off", 8) == 0)
 		stop_scan_thread();
+	else if (strncmp(buf, "hexdump=on", 10) == 0) {
+		atomic_set(&kmemleak_hex_dump, 1);
+	}
+	else if (strncmp(buf, "hexdump=off", 11) == 0) {
+		atomic_set(&kmemleak_hex_dump, 0);
+	}
 	else if (strncmp(buf, "scan=", 5) == 0) {
 		unsigned long secs;
 		int err;


	Sergey

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2009-06-28 17:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-28 17:36 Sergey Senozhatsky [this message]
2009-06-29  9:43 ` Pekka Enberg
2009-06-29  9:48   ` Catalin Marinas
2009-06-29 10:19   ` Sergey Senozhatsky
2009-06-29 10:19     ` Pekka Enberg
2009-06-29 10:38       ` Catalin Marinas
2009-06-29 10:42         ` Pekka Enberg
2009-06-29 10:52         ` Sergey Senozhatsky
2009-06-29 20:10         ` Sergey Senozhatsky
2009-07-14 10:07           ` Catalin Marinas
2009-07-14 10:33             ` Sergey Senozhatsky
2009-07-14 10:34               ` Catalin Marinas
2009-07-14 10:57                 ` Sergey Senozhatsky
2009-07-14 13:39                   ` Catalin Marinas
2009-07-14 14:03                     ` Sergey Senozhatsky
2009-07-14 14:17                       ` Catalin Marinas
2009-07-14 15:22                         ` kmemleak: Printing of the objects hex dump Sergey Senozhatsky
2009-06-29 10:45       ` kmemleak hexdump proposal Sergey Senozhatsky
2009-06-29 10:58         ` Catalin Marinas
2009-06-29 11:08           ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090628173632.GA3890@localdomain.by \
    --to=sergey.senozhatsky@mail.by \
    --cc=catalin.marinas@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@cs.helsinki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox