Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a555613 authored by Vladimir Kondratiev's avatar Vladimir Kondratiev Committed by Greg Kroah-Hartman
Browse files

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: default avatarVladimir Kondratiev <qca_vkondrat@qca.qualcomm.com>
Signed-off-by: default avatarJason Baron <jbaron@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f657fd21
Loading
Loading
Loading
Loading
+13 −2
Original line number Original line Diff line number Diff line
@@ -6,8 +6,16 @@ This document describes how to use the dynamic debug (dyndbg) feature.


Dynamic debug is designed to allow you to dynamically enable/disable
Dynamic debug is designed to allow you to dynamically enable/disable
kernel code to obtain additional kernel information.  Currently, if
kernel code to obtain additional kernel information.  Currently, if
CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() calls can
CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() and
be dynamically enabled per-callsite.
print_hex_dump_debug()/print_hex_dump_bytes() calls can be dynamically
enabled per-callsite.

If CONFIG_DYNAMIC_DEBUG is not set, print_hex_dump_debug() is just
shortcut for print_hex_dump(KERN_DEBUG).

For print_hex_dump_debug()/print_hex_dump_bytes(), format string is
its 'prefix_str' argument, if it is constant string; or "hexdump"
in case 'prefix_str' is build dynamically.


Dynamic debug has even more useful features:
Dynamic debug has even more useful features:


@@ -202,6 +210,9 @@ The flags are:
  t    Include thread ID in messages not generated from interrupt context
  t    Include thread ID in messages not generated from interrupt context
  _    No flags are set. (Or'd with others on input)
  _    No flags are set. (Or'd with others on input)


For print_hex_dump_debug() and print_hex_dump_bytes(), only 'p' flag
have meaning, other flags ignored.

For display, the flags are preceded by '='
For display, the flags are preceded by '='
(mnemonic: what the flags are currently equal to).
(mnemonic: what the flags are currently equal to).


+11 −0
Original line number Original line Diff line number Diff line
@@ -95,6 +95,17 @@ do { \
				     ##__VA_ARGS__);		\
				     ##__VA_ARGS__);		\
} while (0)
} while (0)


#define dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
			 groupsize, buf, len, ascii)		\
do {								\
	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor,		\
		__builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\
	if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT))	\
		print_hex_dump(KERN_DEBUG, prefix_str,		\
			       prefix_type, rowsize, groupsize,	\
			       buf, len, ascii);		\
} while (0)

#else
#else


#include <linux/string.h>
#include <linux/string.h>
+17 −0
Original line number Original line Diff line number Diff line
@@ -321,8 +321,13 @@ extern void hex_dump_to_buffer(const void *buf, size_t len,
extern void print_hex_dump(const char *level, const char *prefix_str,
extern void print_hex_dump(const char *level, const char *prefix_str,
			   int prefix_type, int rowsize, int groupsize,
			   int prefix_type, int rowsize, int groupsize,
			   const void *buf, size_t len, bool ascii);
			   const void *buf, size_t len, bool ascii);
#if defined(CONFIG_DYNAMIC_DEBUG)
#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len)	\
	dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
#else
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
				 const void *buf, size_t len);
				 const void *buf, size_t len);
#endif /* defined(CONFIG_DYNAMIC_DEBUG) */
#else
#else
static inline void print_hex_dump(const char *level, const char *prefix_str,
static inline void print_hex_dump(const char *level, const char *prefix_str,
				  int prefix_type, int rowsize, int groupsize,
				  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,


#endif
#endif


#if defined(CONFIG_DYNAMIC_DEBUG)
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,	\
			     groupsize, buf, len, ascii)	\
	dynamic_hex_dump(prefix_str, prefix_type, rowsize,	\
			 groupsize, buf, len, ascii)
#else
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize,		\
			     groupsize, buf, len, ascii)		\
	print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,	\
		       groupsize, buf, len, ascii)
#endif /* defined(CONFIG_DYNAMIC_DEBUG) */

#endif
#endif
+3 −1
Original line number Original line Diff line number Diff line
@@ -227,6 +227,7 @@ void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
}
}
EXPORT_SYMBOL(print_hex_dump);
EXPORT_SYMBOL(print_hex_dump);


#if !defined(CONFIG_DYNAMIC_DEBUG)
/**
/**
 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
 * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
 * @prefix_str: string to prefix each line with;
 * @prefix_str: string to prefix each line with;
@@ -246,4 +247,5 @@ void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
		       buf, len, true);
		       buf, len, true);
}
}
EXPORT_SYMBOL(print_hex_dump_bytes);
EXPORT_SYMBOL(print_hex_dump_bytes);
#endif
#endif /* !defined(CONFIG_DYNAMIC_DEBUG) */
#endif /* defined(CONFIG_PRINTK) */