Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vladimir Kondratiev and committed by
Greg Kroah-Hartman
7a555613 f657fd21

+44 -3
+13 -2
Documentation/dynamic-debug-howto.txt
··· 6 6 7 7 Dynamic debug is designed to allow you to dynamically enable/disable 8 8 kernel code to obtain additional kernel information. Currently, if 9 - CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() calls can 10 - be dynamically enabled per-callsite. 9 + CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() and 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 20 Dynamic debug has even more useful features: 13 21 ··· 209 201 m Include module name in the printed message 210 202 t Include thread ID in messages not generated from interrupt context 211 203 _ No flags are set. (Or'd with others on input) 204 + 205 + For print_hex_dump_debug() and print_hex_dump_bytes(), only 'p' flag 206 + have meaning, other flags ignored. 212 207 213 208 For display, the flags are preceded by '=' 214 209 (mnemonic: what the flags are currently equal to).
+11
include/linux/dynamic_debug.h
··· 95 95 ##__VA_ARGS__); \ 96 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 109 #else 99 110 100 111 #include <linux/string.h>
+17
include/linux/printk.h
··· 321 321 extern void print_hex_dump(const char *level, const char *prefix_str, 322 322 int prefix_type, int rowsize, int groupsize, 323 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 328 extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, 325 329 const void *buf, size_t len); 330 + #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ 326 331 #else 327 332 static inline void print_hex_dump(const char *level, const char *prefix_str, 328 333 int prefix_type, int rowsize, int groupsize, ··· 340 335 } 341 336 342 337 #endif 338 + 339 + #if defined(CONFIG_DYNAMIC_DEBUG) 340 + #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ 341 + groupsize, buf, len, ascii) \ 342 + dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ 343 + groupsize, buf, len, ascii) 344 + #else 345 + #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ 346 + groupsize, buf, len, ascii) \ 347 + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ 348 + groupsize, buf, len, ascii) 349 + #endif /* defined(CONFIG_DYNAMIC_DEBUG) */ 343 350 344 351 #endif
+3 -1
lib/hexdump.c
··· 227 227 } 228 228 EXPORT_SYMBOL(print_hex_dump); 229 229 230 + #if !defined(CONFIG_DYNAMIC_DEBUG) 230 231 /** 231 232 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params 232 233 * @prefix_str: string to prefix each line with; ··· 247 246 buf, len, true); 248 247 } 249 248 EXPORT_SYMBOL(print_hex_dump_bytes); 250 - #endif 249 + #endif /* !defined(CONFIG_DYNAMIC_DEBUG) */ 250 + #endif /* defined(CONFIG_PRINTK) */