调试过程中,经常通过pr_debug/dev_debug来动态打开关闭log输出,记录一下常用的使用方式,详细的请查看kernel官方文档Dynamic debug — The Linux Kernel documentation
Dynamic debug has even more useful features:
* Simple query language allows turning on and off debuggingstatements by matching any combination of 0 or 1 of:
- source filename
- function name
- line number (including ranges of line numbers)
- module name
- format string* Provides a debugfs control file: <debugfs>/dynamic_debug/control which can be read to display the complete list of known debug statements, to help guide you
如果没有使用CONFIG_DYNAMIC_DEBUG,定义DEBUG宏,那么此时pr_debug就退化为了printk,如果DEBUG宏也未定义,则不打印。
1. 查看所有调试打印信息
xxxxx:/ # cat /sys/kernel/debug/dynamic_debug/control | grep gt1x
# filename:lineno [module]function flags format
drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:251 [gt1]gt1x_report_touch_up =_ "<<GTP-DBG>>[%s:%d]gt1x_report_touch
_up++++\012"
drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:402 [gt1]gt1x_power_switch =_ "<<GTP-DBG>>[%s:%d]GTP power on.\012"
drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:406 [gt1]gt1x_power_switch =_ "<<GTP-DBG>>[%s:%d]GTP power off.\012"
drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:489 [gt1]gt1x_request_irq =_ "<<GTP-DBG>>[%s:%d]INT trigger type:%x\0
12
2. 打开log输出
# 打开指定文件"gt1x.c" log 输出
echo -n 'file gt1x.c +p' > /sys/kernel/debug/dynamic_debug/control#打开指定文件"gt1x.c" 406行 log 输出
echo -n 'file gt1x.c line 406 +p' > /sys/kernel/debug/dynamic_debug/control#打开指定函数"gt1x_report_touch_up" log 输出
echo -n 'func gt1x_report_touch_up +p' > /sys/kernel/debug/dynamic_debug/control#打开指定模块"gt1" log 输出
echo -n 'module gt1+p' > /sys/kernel/debug/dynamic_debug/control#关闭指定文件"gt1x.c" log 输出
echo -n 'file gt1x.c -p' > /sys/kernel/debug/dynamic_debug/control# 打开指定文件"gt1x.c" log 输出,输出模块名,函数名,行号,线程ID等信息
echo -n 'file gt1x.c +flmtp' > /sys/kernel/debug/dynamic_debug/controlThe flags specification comprises a change operation followed by one or more flag characters. The change operation is one of the characters:
- remove the given flags
+ add the given flags
= set the flags to the given flags
The flags are:
p enables the pr_debug() callsite.
f Include the function name in the printed message
l Include line number in the printed message
m Include module name in the printed message
t Include thread ID in messages not generated from interrupt context_ No flags are set. (Or'd with others on input)Note the regexp ^[-+=][flmpt_]+$ matches a flags specification. To clear all flags at once, use =_ or -flmpt.
3. 启动过程输出log
在cmdline添加 dyndbg='file dsi_panel.c +p' gt1.dyndbg='+p'
xxxxx:/ # cat /proc/cmdline
rcupdate.rcu_expedited=1 rcu_nocbs=0-7 cgroup.memory=nokmem,nosocket console=ttyMSM0,115200n8 earlycon=msm_geni_serial,0 xa90000 androidboot.hardware=qcom androidboot.console=ttyMSM0 androidboot.memcg=1 lpm_levels.sleep_disabled=1 video=vfb: 640x400,bpp=32,memsize=3072000 msm_rtb.filter=0x237 service_locator.enable=1 swiotlb=2048 firmware_class.path=/vendor/fi rmware_mnt/image loop.max_part=7 androidboot.usbcontroller=a600000.dwc3 dyndbg='file dsi_panel.c +p' gt1.dyndbg='+p' pri ntk.devkmsg=on buildvariant=userdebug androidboot.verifiedbootstate=orange androidboot.keymaster=1 root=PARTUUID=5432305 6-438b-a2c0-8b6b-bd567227e452 androidboot.vbmeta.device=PARTUUID=420ffbe8-d8a5-b9fa-d0b4-c57783dd923f androidboot.vbmeta .avb_version=1.0 androidboot.vbmeta.device_state=unlocked androidboot.vbmeta.hash_alg=sha256 androidboot.vbmeta.size=844 8 androidboot.vbmeta.digest=e08c341db7b87b5e7d0b1055e0ecfd97a0791cbe3b13ada9f4011e038ac08adf androidboot.veritymode=disa bled androidboot.bootdevice=1d84000.ufshc androidboot.serialno=123456789ABCDEF androidboot.baseband=msm msm_drm.dsi_disp lay0=dsi_s6e3fc2x01_sumsung_amoled_cmd_display: skip_initramfs rootwait ro init=/init androidboot.dtbo_idx=14
dyndbg='file dsi_panel.c +p' //dsi_panel.c Debug级别log无法输出
xxxxx:/d/dynamic_debug # cat control | grep dsi_panel.c
drivers/gpu/drm/msm/dsi-staging/dsi_panel.c:636 [msm_drm]dsi_panel_set_backlight =_ "backlight type:%d lvl:%d\012" drivers/gpu/drm/msm/dsi-staging/dsi_panel.c:2935 [msm_drm]dsi_panel_parse_esd_reg_read_configs =_ "error reading panel s tatus values\012" drivers/gpu/drm/msm/dsi-staging/dsi_panel.c:3170 [msm_drm]dsi_panel_get =_ "failed to get dms info, rc=%d\012" drivers/gpu/drm/msm/dsi-staging/dsi_panel.c:3174 [msm_drm]dsi_panel_get =_ "failed to parse esd config, rc=%d\012"
gt1.dyndbg='+p' // 启动时,pr_debug级别可以输出
xxxxx:/d/dynamic_debug # cat control | grep gt1 drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:251 [gt1]gt1x_report_touch_up =p "<<GTP-DBG>>[%s:%d]gt1x_report_touch _up++++\012" drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:402 [gt1]gt1x_power_switch =p "<<GTP-DBG>>[%s:%d]GTP power on.\012" drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:406 [gt1]gt1x_power_switch =p "<<GTP-DBG>>[%s:%d]GTP power off.\012" drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:489 [gt1]gt1x_request_irq =p "<<GTP-DBG>>[%s:%d]INT trigger type:%x\0 12" drivers/input/touchscreen/gt1x_v1.6_generic/gt1x.c:182 [gt1]gt1x_ts_irq_handler =p "<<GTP-DBG>>[%s:%d]disable_irq_nosync
启动log:
[ 11.978363] [<7>][1, swapper/0]<<GTP-DBG>>[gt1x_power_switch:402]GTP power on. [ 12.173505] [<6>][1, swapper/0]<<GTP-DBG>>[gt1x_send_cfg:564]Driver send config, length:239[ 12.173511] [<6>][1, swapper/0]<<GTP-DBG>>[gt1x_send_cfg:623]Config checksum: 0xF231
[ 12.379974] [<3>][1, swapper/0]<<GTP-DBG>>[gt1x_send_cfg:634]Send config successfully!
[ 12.429901] [<6>][1, swapper/0]<<GTP-DBG>>[gt1x_request_irq:489]INT trigger type:1