Linux Dynamic Debug

調(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宏也未定義透典,則不打印。

device.h

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末凑队,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子幔翰,更是在濱河造成了極大的恐慌漩氨,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件导匣,死亡現(xiàn)場離奇詭異才菠,居然都是意外死亡,警方通過查閱死者的電腦和手機贡定,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門赋访,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人缓待,你說我怎么就攤上這事蚓耽。” “怎么了旋炒?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵步悠,是天一觀的道長。 經(jīng)常有香客問我瘫镇,道長鼎兽,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任铣除,我火速辦了婚禮谚咬,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘尚粘。我一直安慰自己择卦,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著秉继,像睡著了一般祈噪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上尚辑,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天辑鲤,我揣著相機與錄音,去河邊找鬼腌巾。 笑死遂填,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的澈蝙。 我是一名探鬼主播吓坚,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼灯荧!你這毒婦竟也來了泡态?” 一聲冷哼從身側(cè)響起甥材,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后馋记,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體跨晴,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡兼犯,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年乳规,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片擦秽。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡码荔,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出感挥,到底是詐尸還是另有隱情缩搅,我是刑警寧澤,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布触幼,位于F島的核電站硼瓣,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏置谦。R本人自食惡果不足惜堂鲤,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望媒峡。 院中可真熱鬧瘟栖,春花似錦、人聲如沸丝蹭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽奔穿。三九已至镜沽,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間贱田,已是汗流浹背缅茉。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留男摧,地道東北人蔬墩。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像耗拓,于是被迫代替她去往敵國和親拇颅。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,843評論 2 354