Commit 0494e08281d08f0a3dc442eb5e5cecc125b53b27
Committed by
Catalin Marinas
1 parent
008139d914
Exists in
master
and in
4 other branches
kmemleak: Printing of the objects hex dump
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>
Showing 1 changed file with 39 additions and 0 deletions Side-by-side Diff
mm/kmemleak.c
... | ... | @@ -162,6 +162,15 @@ |
162 | 162 | /* flag set on newly allocated objects */ |
163 | 163 | #define OBJECT_NEW (1 << 3) |
164 | 164 | |
165 | +/* number of bytes to print per line; must be 16 or 32 */ | |
166 | +#define HEX_ROW_SIZE 16 | |
167 | +/* number of bytes to print at a time (1, 2, 4, 8) */ | |
168 | +#define HEX_GROUP_SIZE 1 | |
169 | +/* include ASCII after the hex output */ | |
170 | +#define HEX_ASCII 1 | |
171 | +/* max number of lines to be printed */ | |
172 | +#define HEX_MAX_LINES 2 | |
173 | + | |
165 | 174 | /* the list of all allocated objects */ |
166 | 175 | static LIST_HEAD(object_list); |
167 | 176 | /* the list of gray-colored objects (see color_gray comment below) */ |
... | ... | @@ -259,6 +268,35 @@ |
259 | 268 | } while (0) |
260 | 269 | |
261 | 270 | /* |
271 | + * Printing of the objects hex dump to the seq file. The number of lines to be | |
272 | + * printed is limited to HEX_MAX_LINES to prevent seq file spamming. The | |
273 | + * actual number of printed bytes depends on HEX_ROW_SIZE. It must be called | |
274 | + * with the object->lock held. | |
275 | + */ | |
276 | +static void hex_dump_object(struct seq_file *seq, | |
277 | + struct kmemleak_object *object) | |
278 | +{ | |
279 | + const u8 *ptr = (const u8 *)object->pointer; | |
280 | + int i, len, remaining; | |
281 | + unsigned char linebuf[HEX_ROW_SIZE * 5]; | |
282 | + | |
283 | + /* limit the number of lines to HEX_MAX_LINES */ | |
284 | + remaining = len = | |
285 | + min(object->size, (size_t)(HEX_MAX_LINES * HEX_ROW_SIZE)); | |
286 | + | |
287 | + seq_printf(seq, " hex dump (first %d bytes):\n", len); | |
288 | + for (i = 0; i < len; i += HEX_ROW_SIZE) { | |
289 | + int linelen = min(remaining, HEX_ROW_SIZE); | |
290 | + | |
291 | + remaining -= HEX_ROW_SIZE; | |
292 | + hex_dump_to_buffer(ptr + i, linelen, HEX_ROW_SIZE, | |
293 | + HEX_GROUP_SIZE, linebuf, sizeof(linebuf), | |
294 | + HEX_ASCII); | |
295 | + seq_printf(seq, " %s\n", linebuf); | |
296 | + } | |
297 | +} | |
298 | + | |
299 | +/* | |
262 | 300 | * Object colors, encoded with count and min_count: |
263 | 301 | * - white - orphan object, not enough references to it (count < min_count) |
264 | 302 | * - gray - not orphan, not marked as false positive (min_count == 0) or |
... | ... | @@ -308,6 +346,7 @@ |
308 | 346 | object->pointer, object->size); |
309 | 347 | seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n", |
310 | 348 | object->comm, object->pid, object->jiffies); |
349 | + hex_dump_object(seq, object); | |
311 | 350 | seq_printf(seq, " backtrace:\n"); |
312 | 351 | |
313 | 352 | for (i = 0; i < object->trace_len; i++) { |