In a device driver source in the Linux tree, I saw dev_dbg(...)
and dev_err(...)
, where do I find the logged message?
One reference suggest to add #define DEBUG
. The other reference involves dynamic debug and debugfs, and I got lost.
upon the kernel booted and the prompt appear to enable debug level messages by executing either dmesg -n 8 or echo 8 > /proc/sys/kernel/printk.
To activate debug messages for core code and built-in modules during the boot process, even before userspace and debugfs exists, use dyndbg="QUERY" , module. dyndbg="QUERY" , or ddebug_query="QUERY" ( ddebug_query is obsoleted by dyndbg , and deprecated).
pr_debug() Some files call pr_debug(), which is ordinarily an empty macro that discards its arguments at compile time. To enable debugging output, build the appropriate file with -DDEBUG by adding CFLAGS_[filename].o := -DDEBUG. to the makefile.
dev_dbg()
expands to dynamic_dev_dbg()
, dev_printk()
, or no-op depending on the compilation flags.
#if defined(CONFIG_DYNAMIC_DEBUG)
#define dev_dbg(dev, format, ...) \
do { \
dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
} while (0)
#elif defined(DEBUG)
#define dev_dbg(dev, format, arg...) \
dev_printk(KERN_DEBUG, dev, format, ##arg)
#else
#define dev_dbg(dev, format, arg...) \
({ \
if (0) \
dev_printk(KERN_DEBUG, dev, format, ##arg); \
})
#endif
dynamic_dev_dbg()
and dev_printk()
call dev_printk_emit()
which calls vprintk_emit()
.
This very same function is called in a normal mode when you just do a printk()
. Just note here, that the rest functions like dev_err()
will end up in the same function.
Thus, obviously, the buffer is all the same, i.e. kernel intrenal buffer.
The logged message at the end is printed to
dmesg
command.Note, data in 2 is kept as long as there still room in the buffer. Since it's limited and circular, newer data preempts old one.
Additional information how to enable Dynamic Debug.
First of all, be sure you have CONFIG_DYNAMIC_DEBUG=y
in the kernel configuration.
Assume we would like to enable all debug prints in the built-in module with name 8250. To achieve that we simple add to the kernel command line the following 8250.dyndbg=+p
.
If the same driver is compiled as loadable module we may either add options 8250 dyndbg
to the modprobe configuration or to the shell command line when do it manually, like modprobe 8250 dyndbg
.
More details are described in the Dynamic Debug documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With