To use the dynamic debug functionality in the Linux kernel, follow these steps:
- Make sure your kernel is compiled with dynamic debugging (CONFIG_DYNAMIC_DEBUG).
- Mount the debug filesystem if it hasn't already been mounted:
$ mount -t debugfs nodev /sys/kernel/debug
- Configure the debug through the dynamic_debug/control folder. It accepts a whitespace-separated sequence of words:
-
- func <function name>
- file <filename>
- module <module name>
- format <pattern>
- line <line or line range>
- + <flag>: This adds the specified flag
- - <flag>: This removes the specified flag
- = <flag>: This sets the specified flag
The flags are defined as follows:
-
- f: This flag includes the function name in the message
- l: This flag includes the line number in the message
- m: This flag includes the module name in the message
- p: This flag enables the debug message
- t: This flag includes the thread ID in non-interrupt context messages
By default, all debug messages are disabled. The control file contains all the available debug points and, by default, they have no flags enabled (marked as =_).
To enable all debug statements in a file, type the following:
$ echo -n 'file <filename> +p' >
/sys/kernel/debug/dynamic_debug/control
Or to just enable a specific debug statement, type the following:
$ echo -n 'file <filename> line nnnn +p' >
/sys/kernel/debug/dynamic_debug/control
- To list all enabled debug statements, use the following command:
$ awk '$3 != "=_"' /sys/kernel/debug/dynamic_debug/control
To make the debug changes persistent, we can pass dyndbg="<query>" or module.dyndbg="<query>" for modules to the kernel in the command-line arguments.
Note that the query string needs to be passed surrounded by quotes so that it is correctly parsed. You can concatenate more than one query in the command-line argument by using a semicolon to separate them, for example:
dyndbg="file mxc_v4l2_capture.c +pfl; file ipu_bg_overlay_sdc.c +pfl"
If, for example, we are using the bootargs U-Boot argument to pass kernel command-line arguments, we would do the following:
> env set bootargs 'dyndbg=\"file one.c +pfl; file two.c +pfl; file three.c +pfl; file four.c +pfl\"'