$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
$ qemu-system-arm --version
QEMU emulator version 2.0.0 (Debian 2.0.0+dfsg-2ubuntu1.27), Copyright (c) 2003-2008 Fabrice Bellard
$ arm-none-eabi-gdb --version
GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20160923-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl
...
commit hash: 14b24726a81b719b35fee70c8ba8be2d682a7313
##Linux kernel環境設定
我目前只打開加入debug資訊的選項。接下來重編,編譯的方式請參考這邊
依照下面兩個步驟執行
基本上就是原本的指令加入兩個選項
假設你在buildroot最上層,就可以使用下面指令執行qemu 並使用gdb 除錯
qemu-system-arm -M versatilepb \
-kernel /tmp/kernel/arch/arm/boot/zImage \
-drive file=output/images/rootfs.ext2,if=scsi,format=raw \
-append "root=/dev/sda console=ttyAMA0,115200" \
-serial stdio -net nic,model=rtl8139 -net user -s -S
##gdb
這邊有點瑣碎,先講一下步驟
1和2可以一起使用如下
arm-none-eabi-gdb -ex "file ./vmlinux" -ex "target remote :1234"
現在看一下操作範例
$ arm-none-eabi-gdb -ex "file ./vmlinux" -ex "target remote :1234"
GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20160923-cvs
...
Reading symbols from ./vmlinux...done.
Remote debugging using :1234
0x60000000 in ?? ()
(gdb) b printk
Breakpoint 1 at 0x800a2260: file kernel/printk/printk.c, line 1900.
(gdb) c
Continuing.
Breakpoint 1, printk (fmt=0x0 <__vectors_start>) at kernel/printk/printk.c:1900
1900 {
(gdb) bt
#0 printk (fmt=0x0 <__vectors_start>) at kernel/printk/printk.c:1900
#1 0x806178e0 in start_kernel () at init/main.c:508
#2 0x6000807c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
另外如果有興趣使用Linux kernel提供的指令,在kernel config設定打開gdb script後,可以使用下面的方式在啟動gdb時載入,只要把下面的描述加到你的~/.gdbinit即可
add-auto-load-safe-path /tmp/kernel/scripts/gdb/vmlinux-gdb.py
那麼你就可以使用Linux kernel提供的gdb script,詳細的設定和指令說明在這邊。
##參考資料
##補充
當初犯了蠢事載入不正確的kernel image導致一堆不必要的除錯。不過多學到一個gdb Python script除錯指令,當Python script發生exception時可以用下面的指令印出Python錯誤call stack