KDB調試Linux4.2.6內核過程記錄

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的開發板。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章