調(diào)試過程中,經(jīng)常通過pr_debug/dev_debug來動態(tài)打開關(guān)閉log輸出,記錄一下常用的使用方式陈哑,詳細(xì)的請查看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. 查看所有調(diào)試打印信息
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#打開指定函數(shù)"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?#關(guān)閉指定文件"gt1x.c" log 輸出
echo -n 'file gt1x.c -p' > /sys/kernel/debug/dynamic_debug/control#?打開指定文件"gt1x.c" log 輸出,輸出模塊名顿苇,函數(shù)名峭咒,行號,線程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?