diff options
author | Vladimir Kondratiev <qca_vkondrat@qca.qualcomm.com> | 2012-12-05 16:48:27 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-17 15:19:09 -0500 |
commit | 7a555613eb77c69eb6e48b61bc5f72dd42fa1780 (patch) | |
tree | fd2c5ef59a77ba532a5957923f9919fa170027f9 | |
parent | f657fd21e16e3ab7432c03008e19069c2ef8e150 (diff) |
dynamic_debug: dynamic hex dump
Introduce print_hex_dump_debug() that can be dynamically controlled, similar to
pr_debug.
Also, make print_hex_dump_bytes() dynamically controlled
Implement only 'p' flag (_DPRINTK_FLAGS_PRINT) to keep it simple since hex dump prints
multiple lines and long prefix would impact readability.
To provide line/file etc. information, use pr_debug or similar
before/after print_hex_dump_debug()
Signed-off-by: Vladimir Kondratiev <qca_vkondrat@qca.qualcomm.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | Documentation/dynamic-debug-howto.txt | 15 | ||||
-rw-r--r-- | include/linux/dynamic_debug.h | 11 | ||||
-rw-r--r-- | include/linux/printk.h | 17 | ||||
-rw-r--r-- | lib/hexdump.c | 4 |
4 files changed, 44 insertions, 3 deletions
diff --git a/Documentation/dynamic-debug-howto.txt b/Documentation/dynamic-debug-howto.txt index 6e1684981da2..72322c6d7352 100644 --- a/Documentation/dynamic-debug-howto.txt +++ b/Documentation/dynamic-debug-howto.txt | |||
@@ -6,8 +6,16 @@ This document describes how to use the dynamic debug (dyndbg) feature. | |||
6 | 6 | ||
7 | Dynamic debug is designed to allow you to dynamically enable/disable | 7 | Dynamic debug is designed to allow you to dynamically enable/disable |
8 | kernel code to obtain additional kernel information. Currently, if | 8 | kernel code to obtain additional kernel information. Currently, if |
9 | CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() calls can | 9 | CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() and |
10 | be dynamically enabled per-callsite. | 10 | print_hex_dump_debug()/print_hex_dump_bytes() calls can be dynamically |
11 | enabled per-callsite. | ||
12 | |||
13 | If CONFIG_DYNAMIC_DEBUG is not set, print_hex_dump_debug() is just | ||
14 | shortcut for print_hex_dump(KERN_DEBUG). | ||
15 | |||
16 | For print_hex_dump_debug()/print_hex_dump_bytes(), format string is | ||
17 | its 'prefix_str' argument, if it is constant string; or "hexdump" | ||
18 | in case 'prefix_str' is build dynamically. | ||
11 | 19 | ||
12 | Dynamic debug has even more useful features: | 20 | Dynamic debug has even more useful features: |
13 | 21 | ||
@@ -202,6 +210,9 @@ The flags are: | |||
202 | t Include thread ID in messages not generated from interrupt context | 210 | t Include thread ID in messages not generated from interrupt context |
203 | _ No flags are set. (Or'd with others on input) | 211 | _ No flags are set. (Or'd with others on input) |
204 | 212 | ||
213 | For print_hex_dump_debug() and print_hex_dump_bytes(), only 'p' flag | ||
214 | have meaning, other flags ignored. | ||
215 | |||
205 | For display, the flags are preceded by '=' | 216 | For display, the flags are preceded by '=' |
206 | (mnemonic: what the flags are currently equal to). | 217 | (mnemonic: what the flags are currently equal to). |
207 | 218 | ||
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 6dd4787a798a..2fe93b26b42f 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h | |||
@@ -95,6 +95,17 @@ do { \ | |||
95 | ##__VA_ARGS__); \ | 95 | ##__VA_ARGS__); \ |
96 | } while (0) | 96 | } while (0) |
97 | 97 | ||
98 | #define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ | ||
99 | groupsize, buf, len, ascii) \ | ||
100 | do { \ | ||
101 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ | ||
102 | __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ | ||
103 | if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ | ||
104 | print_hex_dump(KERN_DEBUG, prefix_str, \ | ||
105 | prefix_type, rowsize, groupsize, \ | ||
106 | buf, len, ascii); \ | ||
107 | } while (0) | ||
108 | |||
98 | #else | 109 | #else |
99 | 110 | ||
100 | #include <linux/string.h> | 111 | #include <linux/string.h> |
diff --git a/include/linux/printk.h b/include/linux/printk.h index 9afc01e5a0a6..02c95cf872cd 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h | |||
@@ -321,8 +321,13 @@ extern void hex_dump_to_buffer(const void *buf, size_t len, | |||
321 | extern void print_hex_dump(const char *level, const char *prefix_str, | 321 | extern void print_hex_dump(const char *level, const char *prefix_str, |
322 | int prefix_type, int rowsize, int groupsize, | 322 | int prefix_type, int rowsize, int groupsize, |
323 | const void *buf, size_t len, bool ascii); | 323 | const void *buf, size_t len, bool ascii); |
324 | #if defined(CONFIG_DYNAMIC_DEBUG) | ||
325 | #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \ | ||
326 | dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true) | ||
327 | #else | ||
324 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | 328 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
325 | const void *buf, size_t len); | 329 | const void *buf, size_t len); |
330 | #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ | ||
326 | #else | 331 | #else |
327 | static inline void print_hex_dump(const char *level, const char *prefix_str, | 332 | static inline void print_hex_dump(const char *level, const char *prefix_str, |
328 | int prefix_type, int rowsize, int groupsize, | 333 | int prefix_type, int rowsize, int groupsize, |
@@ -336,4 +341,16 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | |||
336 | 341 | ||
337 | #endif | 342 | #endif |
338 | 343 | ||
344 | #if defined(CONFIG_DYNAMIC_DEBUG) | ||
345 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ | ||
346 | groupsize, buf, len, ascii) \ | ||
347 | dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ | ||
348 | groupsize, buf, len, ascii) | ||
349 | #else | ||
350 | #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ | ||
351 | groupsize, buf, len, ascii) \ | ||
352 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ | ||
353 | groupsize, buf, len, ascii) | ||
354 | #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ | ||
355 | |||
339 | #endif | 356 | #endif |
diff --git a/lib/hexdump.c b/lib/hexdump.c index 6540d657dca4..3f0494c9d57a 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c | |||
@@ -227,6 +227,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, | |||
227 | } | 227 | } |
228 | EXPORT_SYMBOL(print_hex_dump); | 228 | EXPORT_SYMBOL(print_hex_dump); |
229 | 229 | ||
230 | #if !defined(CONFIG_DYNAMIC_DEBUG) | ||
230 | /** | 231 | /** |
231 | * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params | 232 | * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params |
232 | * @prefix_str: string to prefix each line with; | 233 | * @prefix_str: string to prefix each line with; |
@@ -246,4 +247,5 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type, | |||
246 | buf, len, true); | 247 | buf, len, true); |
247 | } | 248 | } |
248 | EXPORT_SYMBOL(print_hex_dump_bytes); | 249 | EXPORT_SYMBOL(print_hex_dump_bytes); |
249 | #endif | 250 | #endif /* !defined(CONFIG_DYNAMIC_DEBUG) */ |
251 | #endif /* defined(CONFIG_PRINTK) */ | ||