Linux Dynamic Debug

调试过程中,经常通过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宏也未定义,则不打印。

device.h

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/control

The 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 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 223,567评论 6 521
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 95,644评论 3 401
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 170,540评论 0 366
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 60,466评论 1 300
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 69,481评论 6 399
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 53,026评论 1 314
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 41,414评论 3 426
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 40,376评论 0 278
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,914评论 1 322
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,967评论 3 343
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 41,104评论 1 354
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,758评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 42,429评论 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,920评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 34,038评论 1 275
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,586评论 3 380
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 46,129评论 2 362