Linux debug


proc文件系統中可以查看一些正在運行的變量如device-tree

sh-3.2# cat /proc/device-tree/ #address-cells fixedregulator@9/ #size-cells gpio-keys/ atf_logger/ interrupt-parent chosen/ lcm/ clocks/ mediatek,connectivity-combo/ compatible memory@00000000/ cpus/ model cust_accel@0/ mt8167_audio_codec/ cust_gyro@0/ mtcpufreq/ cust_mag@0/ name ethernet@11180000/ opp_table0/ fixedregulator@0/ panel@0/ fixedregulator@1/ pmu/ fixedregulator@10/ psci/ fixedregulator@11/ reserved-memory/ fixedregulator@12/ sdio@11130000/ fixedregulator@2/ soc/ fixedregulator@4/ sound/ fixedregulator@5/ timer/ fixedregulator@6/ tlv320/ fixedregulator@7/ tonly-power-leds/ fixedregulator@8/ vibrator@0/ sh-3.2# cat /proc/device-tree/gpio-keys/ button@0/ button@2/ button@4/ name pinctrl-names button@1/ button@3/ compatible pinctrl-0 sh-3.2# cat /proc/device-tree/gpio-keys/compatible gpio-keys sh-3.2#

module_param值修改方法

module_param(musbfsh_debug, int, 0644);

修改方法

echo 1 > sys/module/musbfsh_core/parameters/musbfsh_debug

編譯時判斷宏變量是否定義:編譯時打印宏變量

#ifdef CONFIG_DWMAC_MESON #pragma message("CONFIG_DWMAC_MESON active\n") 編譯的時候的打印會有提示,搜索即可: note: #pragma message: CONFIG_DWMAC_MESON active #pragma message("CONFIG_DWMAC_MESON active\n")

重定義打印宏,顯示特定打印結構

#ifdef pr_debug #undef pr_debug #define pr_debug(fmt, ...) \ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) #else #define pr_debug(fmt, ...) \ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) #endif

#ifdef pr_debug #undef pr_debug #define pr_debug(fmt,...) printk(KERN_INFO"%s:%s :%d\n "fmt, __FILE__ , __FUNCTION__ , __LINE__ , ##__VA_ARGS__) #else #define pr_debug(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) #endif

  1) VA_ARGS 是一個可變參數的宏,很少人知道這個宏,這個可變參數的宏是新的C99規范中新增的,目前似乎只有gcc支持(VC6.0的編譯器不支持)。宏前面加上##的作用在於,當可變參數的個數為0時,這里的##起到把前面多余的”,”去掉的作用,否則會編譯出錯, 你可以試試。
  2) FILE 宏在預編譯時會替換成當前的源文件名
  3) LINE宏在預編譯時會替換成當前的行號
  4) FUNCTION宏在預編譯時會替換成當前的函數名稱

#ifndef _OSD_LOG_H_ #define _OSD_LOG_H_ #include <stdarg.h> #include <linux/printk.h> #define OSD_LOG_LEVEL_NULL 0 #define OSD_LOG_LEVEL_DEBUG 1 #define OSD_LOG_LEVEL_DEBUG2 2 #define OSD_LOG_LEVEL_DEBUG3 3 extern unsigned int osd_log_level; #undef pr_fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define osd_log_info(fmt, ...) \ pr_info(fmt, ##__VA_ARGS__) #define osd_log_err(fmt, ...) \ pr_err(fmt, ##__VA_ARGS__) #define osd_log_dbg(fmt, ...) \ do { \ if (osd_log_level >= OSD_LOG_LEVEL_DEBUG) { \ pr_info(fmt, ##__VA_ARGS__); \ } \ } while (0) #define osd_log_dbg2(fmt, ...) \ do { \ if (osd_log_level >= OSD_LOG_LEVEL_DEBUG2) { \ pr_info(fmt, ##__VA_ARGS__); \ } \ } while (0) #define osd_log_dbg3(fmt, ...) \ do { \ if (osd_log_level >= OSD_LOG_LEVEL_DEBUG3) { \ pr_info(fmt, ##__VA_ARGS__); \ } \ } while (0) #endif

通過menuconfig配置將打印打開:

+CONFIG_DEBUG_OBJECTS=y +CONFIG_DEBUG_OBJECTS_TIMERS=y +CONFIG_DEBUG_OBJECTS_WORK=y +CONFIG_SLUB_DEBUG_ON=y +CONFIG_DEBUG_STACK_USAGE=y +CONFIG_DEBUG_MEMORY_INIT=y +CONFIG_DEBUG_PER_CPU_MAPS=y +CONFIG_DEBUG_SHIRQ=y +CONFIG_LOCKUP_DETECTOR=y +CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y +CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_PANIC_ON_OOPS=y +CONFIG_DEBUG_KOBJECT=y +CONFIG_DEBUG_DRIVER=y
<7>[ 2.625859@0] kobject: 'rtc-hym8563' (ffffffc0246c78c0): kobject_uevent_env <7>[ 2.625876@0] kobject: 'rtc-hym8563' (ffffffc0246c78c0): fill_kobj_path: path = '/bus/i2c/drivers/rtc-hym8563' <7>[ 2.626050@0] bus: 'amba': add driver rtc-pl031 <7>[ 2.626066@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): kobject_add_internal: parent: 'drivers', set: 'drivers' <7>[ 2.626121@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): kobject_uevent_env <7>[ 2.626136@0] kobject: 'rtc-pl031' (ffffffc0246c66c0): fill_kobj_path: path = '/bus/amba/drivers/rtc-pl031' <6>[ 2.626267@0] i2c /dev entries driver <7>[ 2.629519@0] device class 'i2c-dev': registering <7>[ 2.629534@0] kobject: 'i2c-dev' (ffffffc0244bc398): kobject_add_internal: parent: 'class', set: 'class' <7>[ 2.629555@0] kobject: 'i2c-dev' (ffffffc0244bc398): kobject_uevent_env <7>[ 2.629568@0] kobject: 'i2c-dev' (ffffffc0244bc398): fill_kobj_path: path = '/class/i2c-dev' <7>[ 2.629724@0] device: 'i2c-2': device_add <7>[ 2.629737@0] kobject: 'i2c-dev' (ffffffc0246f5200): kobject_add_internal: parent: 'i2c-2', set: '(null)'

打開pr_debug的打印,修改打印級別:

kernel/printk/printk.c

#define DEFAULT_CONSOLE_LOGLEVEL 8 /* anything MORE serious than KERN_DEBUG */ 或在include/linux/printk.h中打開宏,則系統增加全局pr_debug打印 #define DEBUG

利用動態打印,在內核中添加配置,並重新編譯燒錄內核

CONFIG_DYNAMIC_DEBUG=y

在文件系統中生成如下節點

/sys/kernel/debug/dynamic_debug/control

查看支持的動態調試選項

/sys/kernel/debug/dynamic_debug # cat control # filename:lineno [module]function flags format init/main.c:712 [main]initcall_blacklist =p "blacklisting initcall %s\012" init/main.c:736 [main]initcall_blacklisted =p "initcall %s blacklisted\012" init/initramfs.c:483 [initramfs]unpack_to_rootfs =_ "Detected %s compressed data\012" arch/arm/vfp/vfpmodule.c:456 [vfp]vfp_pm_suspend =_ "%s: saving vfp state\012" arch/arm/vfp/vfpmodule.c:304 [vfp]vfp_emulate_instruction =_ "VFP: emulate: INST=0x%08x SCR=0x%08x\012" arch/arm/vfp/vfpmodule.c:260 [vfp]vfp_raise_exceptions =_ "VFP: raising exceptions %08x\012" arch/arm/vfp/vfpmodule.c:340 [vfp]VFP_bounce =_ "VFP: bounce: trigger %08x fpexc %08x\012" arch/arm/vfp/vfpsingle.c:51 [vfp]vfp_single_dump =_ "VFP: %s: sign=%d exponent=%d significand=%08x\012" arch/arm/vfp/vfpsingle.c:849 [vfp]vfp_single_multiply =_ "VFP: swapping M <-> N\012" arch/arm/vfp/vfpsingle.c:694 [vfp]vfp_single_ftosi =_ "VFP: ftosi: d(s%d)=%08x exceptions=%08x\012" arch/arm/vfp/vfpsingle.c:615 [vfp]vfp_single_ftoui =_ "VFP: ftoui: d(s%d)=%08x exceptions=%08x\012" arch/arm/vfp/vfpsingle.c:145 [vfp]__vfp_single_normaliseround =_ "VFP: rounding increment = 0x%08x\012" arch/arm/vfp/vfpsingle.c:1059 [vfp]vfp_single_fdiv =_ "VFP: s%u = %08x\012" arch/arm/vfp/vfpsingle.c:996 [vfp]vfp_single_fnmul =_ "VFP: s%u = %08x\012" arch/arm/vfp/vfpsingle.c:1020 [vfp]vfp_single_fadd =_ "VFP: s%u = %08x\012" arch/arm/vfp/vfpsingle.c:973 [vfp]vfp_single_fmul =_ "VFP: s%u = %08x\012" arch/arm/vfp/vfpsingle.c:902 [vfp]vfp_single_multiply_accumulate =_ "VFP: s%u = %08x\012" arch/arm/vfp/vfpsingle.c:916 [vfp]vfp_single_multiply_accumulate =_ "VFP: s%u = %08x\012"

如下操作,使能對應的打印 

echo -n 'file svcsock.c line 1603 +p' > <debugfs>/dynamic_debug/control 打開某個文件某一行的日志 // enable all the messages in file svcsock.c 打開某個文件的所有日志 nullarbor:~ # echo -n 'file svcsock.c +p' > <debugfs>/dynamic_debug/control // enable all the messages in the NFS server module 打開某個模塊的所有日志 nullarbor:~ # echo -n 'module nfsd +p' > <debugfs>/dynamic_debug/control // enable all 12 messages in the function svc_process() 打開某個函數的所有日志 nullarbor:~ # echo -n 'func svc_process +p' > <debugfs>/dynamic_debug/control // disable all 12 messages in the function svc_process() 關閉某個文件的所有日志 nullarbor:~ # echo -n 'func svc_process -p' > <debugfs>/dynamic_debug/control // enable messages for NFS calls READ, READLINK, READDIR and READDIR+. nullarbor:~ # echo -n 'format "nfsd: READ" +p' > <debugfs>/dynamic_debug/control

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM