Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does dev_dbg writes log to?

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.

like image 672
golopot Avatar asked May 13 '17 07:05

golopot


People also ask

How do I enable debug logs in kernel?

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.

How to enable dynamic debug in kernel?

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).

What is Pr_debug?

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.


1 Answers

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

  1. Current console if kernel loglevel value (can be changed via kernel command line or via procfs) is high enough for certain message, here KERN_DEBUG.
  2. Internal buffer which can be read by running 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.

like image 69
0andriy Avatar answered Oct 08 '22 17:10

0andriy