1、最常用的方法是printk插桩;
2、借住proc文件系统查看相关参数:/proc/interrrupts、/proc/timer_list、/proc/cpuinfo等,或者自己创建proc文件,帮助debug;
procfs/sysfs/debugfs:http://tinylab.org/show-the-usage-of-procfs-sysfs-debugfs/
(1)procfs:挂载在/proc,Documentation/filesystems/proc.txt
(2)sysfs:挂载在/sys,Documentation/filesystems/sysfs.txt
(3)debugfs:挂载在/sys/kernel/debug/,Documentation/filesystems/debugfs.txt
3、Sysrq魔法键(Linux Magic System Request Key)
参考Documentation/sysrq.txt文件:
(1)开启Sysrq魔法键功能:在kernel的配置文件中加入:CONFIG_MAFIC_SYSRQ
make menuconfig->Kernel hacking->Magic SysRq key
(2)Enable magic sysrq key function
cat /proc/sys/kernel/sysrq可以查看当前打开的magic sysrq key function
echo "number" > /proc/sys/kernel/sysrq可以打开某项magic sysrq key function,number可以是十进制也可以是十六进制
写入的number可以是以下几个或者几个的或:
0 - disable sysrq completely
1 - enable all functions of sysrq
>1 - bitmask of allowed sysrq functions (see below for detailed function
description):
2 = 0x2 - enable control of console logging level
4 = 0x4 - enable control of keyboard (SAK, unraw)
8 = 0x8 - enable debugging dumps of processes etc.
16 = 0x10 - enable sync command
32 = 0x20 - enable remount read-only
64 = 0x40 - enable signalling of processes (term, kill, oom-kill)
128 = 0x80 - allow reboot/poweroff
256 = 0x100 - allow nicing of all RT tasks
(3)怎么使用magic sysrq key?
X86平台:alt + print screen + "command key"
比较常用的:
alt + print screen + b: reboot system
alt + print screen + '0' ~ '9':设置console log level
4、core dump:主要获取应用程序崩溃时的现场信息,如程序运行时的内存、寄存器状态、堆栈指针、内存管理信息、函数调用堆栈等
(1)ulimit -c查看core dump机制是否使能,若为0则不产生core dump
(2)ulimit -c unlimited使能core dump
具体参考https://www.cnblogs.com/justin-y-lin/p/5598305.html
其他:
1、优秀的内核调试总结网站
https://www.cnblogs.com/justin-y-lin/p/5424529.html