KDB调试内核代码步骤记录:
一、配置内核,内核版本为Linux4.2.6
Kernel hacking --->
printk and dmesg options --->
[*] Show timing information on printks
(4) Default message log level (1-7)
[ ] Delay each boot printk message by N milliseconds
[*] Enable dynamic printk() support
[*] KGDB: kernel debugger --->
<*> KGDB: use kgdb over the serial console
[*] KGDB_KDB: include kdb frontend for kgdb
(0x1) KDB: Select kdb command functions to be enabled by default
[*] KGDB_KDB: keyboard as input device
(0) KDB: continue after catastrophic errors
二、重新编译内核烧写到开发板,并且配置其u-boot参数,在bootargs设置中加上“kgdboc=ttySAC0,115200 kgdbwait kgdbcon”
三、启动系统,最终内核会显示到下面过
[ 0.206841] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled [ 0.208123] 13800000.serial: ttySAC0 at MMIO 0x13800000 (irq = 46, base_baud = 0) is a S3C6400/10 [ 0.834111] console [ttySAC0] enabled [ 0.838058] 13810000.serial: ttySAC1 at MMIO 0x13810000 (irq = 47, base_baud = 0) is a S3C6400/10 [ 0.846849] 13820000.serial: ttySAC2 at MMIO 0x13820000 (irq = 48, base_baud = 0) is a S3C6400/10 [ 0.855689] 13830000.serial: ttySAC3 at MMIO 0x13830000 (irq = 49, base_baud = 0) is a S3C6400/10 [ 0.864861] KGDB: Registered I/O driver kgdboc [ 0.906749] KGDB: Waiting for connection from remote gdb... Entering kdb (current=0xee878000, pid 1) on processor 1 due to Keyboard Entry [1]kdb> |
四、接下来就可以来调试内核了,不过在调试内核之前有两种方式,一种直接使用kdb来调试,一种使用gdb调试vmlinux文件。
第一种方式也就是上面连接成功后直接使用kdb的命令来设置断点,调试。
第二种方式首先也是需要板子启动到KGDB: Waiting for connection from remote gdb...这里来,只不过下面可以使用ubuntu来中来调试。具体步骤如下:
1、首先确认进入到KGDB: Waiting for connection from remote gdb...
2、断开串口,把开发板的串口链接到ubuntu上,链接上来的串口显示/dev/ttyUSB0
(NOTE:也有人直接在ubuntu下开启minicon来显示开发板信息,也一样需要断开,不然会冲突,后面去target remote /dev/ttyUSB0的时候会打印“Ignoring packet error, continuing...”)
3、在Linux源码目录下,先使用arm-linux-gdb vmlinux。接着使用target remote /dev/ttyUSB0
最后就开始各种设置断电,各种单步调试了。如下:
root@ubuntu:/work/a9_board/tiny4412/linux_for_dts/linux-4.2.6# /work/a9_board/tiny4412/buildroot-2015.08/output/host/usr/bin/arm-linux-gdb vmlinux GNU gdb (GDB) 7.8.2 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-buildroot-linux-uclibcgnueabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux...done. (gdb) target remote /dev/ttyUSB0 Remote debugging using /dev/ttyUSB0 0xc008fdc0 in arch_kgdb_breakpoint () at ./arch/arm/include/asm/outercache.h:142 142 outer_cache.sync(); (gdb) b usb4604_init Breakpoint 1 at 0xc0383608: file drivers/usb/host/ehci-exynos.c, line 145. (gdb) c Continuing. [ 38.339126] KGDB: kernel/debug/debug_core.c kgdb_register_io_module 1021... [ 38.362864] [drm] Initialized drm 1.1.0 20060810 [ 38.386095] brd: module loaded [ 38.404344] loop: module loaded [ 38.417272] usbcore: registered new interface driver cdc_ether [ 38.437386] usbcore: registered new interface driver dm9601 [ 38.458694] usbcore: registered new interface driver cdc_subset [ 38.480702] usbcore: registered new interface driver zaurus [ 38.501868] usbcore: registered new interface driver cdc_ncm [ 38.523123] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 38.546737] ehci-exynos: EHCI EXYNOS driver [ 38.564799] drivers/usb/host/ehci-exynos.c ehci_exynos_init 369 [ 38.586865] drivers/usb/host/ehci-exynos.c exynos_ehci_probe 181 [ 38.607813] drivers/usb/host/ehci-exynos.c exynos_ehci_probe 186 [ 38.631819] drivers/usb/host/ehci-exynos.c exynos_ehci_probe 197 [ 38.653826] drivers/usb/host/ehci-exynos.c exynos_ehci_probe 202 [ 38.676898] drivers/usb/host/ehci-exynos.c exynos_ehci_probe 207
Breakpoint 1, exynos_ehci_probe (pdev=0xee9b9400) at drivers/usb/host/ehci-exynos.c:208 208 usb4604_init(); (gdb) n [ 51.127535] usb4604 initialize............ 212 exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); (gdb) s devm_clk_get (dev=0xee9b9410, id=0xc06ea0c0 "usbhost") at drivers/clk/clk-devres.c:18 18 { (gdb)
|
NOTE: 最不好的是在调试的过程中,时间久了会系统会自动复位,找了好久都不知道为什么。最好发现CPU温度非常高,反正只要CPU温度正常KDB怎么调试都行。一旦温度升高到一定程度就自动复位了,使用的板子是TINY4412的开发板。