From: Catalin Marinas <catalin.marinas@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
Subject: [PATCH 6/8] kmemleak: Printing of the objects hex dump
Date: Fri, 24 Jul 2009 17:12:35 +0100 [thread overview]
Message-ID: <20090724161235.5752.34490.stgit@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20090724161026.5752.52503.stgit@pc1117.cambridge.arm.com>
From: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
Introducing 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 is less than or equal to (HEX_MAX_LINES * HEX_ROW_SIZE).
(slight adjustments by Catalin Marinas)
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@mail.by>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
mm/kmemleak.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 7dcb898..983f3f6 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -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) */
@@ -259,6 +268,35 @@ static void kmemleak_disable(void);
} 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)
* - gray - not orphan, not marked as false positive (min_count == 0) or
@@ -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++) {
next prev parent reply other threads:[~2009-07-24 16:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-24 16:12 [PATCH 0/8] Kmemleak patches for 2.6.32 Catalin Marinas
2009-07-24 16:12 ` [PATCH 1/8] kmemleak: Dump object information on request Catalin Marinas
2009-07-24 16:12 ` [PATCH 2/8] kmemleak: Allow rescheduling during an object scanning Catalin Marinas
2009-07-24 16:12 ` [PATCH 3/8] kmemleak: Mark the early log buffer as __initdata Catalin Marinas
2009-07-24 16:12 ` [PATCH 4/8] kmemleak: Save the stack trace for early allocations Catalin Marinas
2009-07-24 16:12 ` [PATCH 5/8] kmemleak: Do not report alloc_bootmem blocks as leaks Catalin Marinas
2009-07-24 16:12 ` Catalin Marinas [this message]
2009-07-24 16:12 ` [PATCH 7/8] kmemleak: Inform kmemleak about kernel stack allocation Catalin Marinas
2009-07-24 16:12 ` [PATCH 8/8] kmemleak: Always scan the task stacks Catalin Marinas
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=20090724161235.5752.34490.stgit@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sergey.senozhatsky@mail.by \
/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
all inboxes | Powered by JetHome®