linux dynamic debug(linux动态调试)

 

https://www.kernel.org/doc/Documentation/admin-guide/dynamic-debug-howto.rst

 

 

Dynamic debug is designed to allow you to dynamically enable/disable

kernel code to obtain additional kernel information. 

Currently, if CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_dbg() and

print_hex_dump_debug()/print_hex_dump_bytes() calls can be dynamically enabled per-callsite.

 

Compiles debug level messages into the kernel, which would not                                                         

otherwise be available at runtime. These messages can then be                                                          

enabled/disabled based on various levels of scope - per source file,                                                   

function, module, format string, and line number. This mechanism                                                       

implicitly compiles in all pr_debug() and dev_dbg() calls, which                                                       

enlarges the kernel text size by about 2%. 

                                                                                                                        

If a source file is compiled with DEBUG flag set, any                                                                  

pr_debug() calls in it are enabled by default, but can be                                                              

disabled at runtime as below.  Note that DEBUG flag is                                                                 

turned on by many CONFIG_*DEBUG* options.

                                                                                                                        

 

 

1. kernel config

Kernel hacking  --->

    printk and dmesg options  --->

        [*] Enable dynamic printk() support

linux dynamic debug(linux动态调试)

 

 

2. usage

Dynamic debugging is controlled via the 'dynamic_debug/control' file,                                                  

which is contained in the 'debugfs' filesystem. Thus, the debugfs                                                      

filesystem must first be mounted before making use of this feature.                                                    

We refer the control file as: <debugfs>/dynamic_debug/control. This                                                    

file contains a list of the debug statements that can be enabled. The                                                  

format for each line of the file is:   

                                                                                

filename:lineno [module]function flags format                                                                    

                                                                                                                        

  • filename : source file of the debug statement                                                                          

  • lineno : line number of the debug statement                                                                            

  • module : module that contains the debug statement                                                                      

  • function : function that contains the debug statement                                                                  

  • flags : '=p' means the line is turned 'on' for printing                                                                

  • format : the format used for the debug statement

 

 

3. test

3.1 enable debugfs

mount -t debugfs none /sys/kernel/debug

 

3.2 view

cat /sys/kernel/debug/dynamic_debug/control

linux dynamic debug(linux动态调试)

 

3.3 test

ensure console loglevel value > 7:

# cat /proc/sys/kernel/printk

8    4    1    7

8 is ok.

 

1) module

enable: echo -n 'module xhci_hcd +p' > /sys/kernel/debug/dynamic_debug/control

disable: echo -n 'module xhci_hcd -p' > /sys/kernel/debug/dynamic_debug/control

 

other usb module: 

# echo -n 'module phy +p' > /sys/kernel/debug/dynamic_debug/control

# echo -n 'module udc_core +p' > /sys/kernel/debug/dynamic_debug/control

# echo -n 'module snps_udc_core +p' > /sys/kernel/debug/dynamic_debug/control

# echo -n 'module libcomposite +p' > /sys/kernel/debug/dynamic_debug/control

 

2) file

enable: echo -n 'file hub.c +p' > /sys/kernel/debug/dynamic_debug/control

disable: echo -n 'file hub.c -p' > /sys/kernel/debug/dynamic_debug/control

linux dynamic debug(linux动态调试)

 

3) function

enable: echo -n 'func hub_event +p' > /sys/kernel/debug/dynamic_debug/control

disable: echo -n 'func hub_event -p' > /sys/kernel/debug/dynamic_debug/control

linux dynamic debug(linux动态调试)