架好了qemu的環境後,接下來當然就是要好好利用這個環境來認識aarch64 Linux kernel啦
這邊介紹如何使用gdb來做簡單的debug
之前是打入以下的指令來啟動qemu:
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-image/Image --append "console=ttyAMA0"
接著,我們透過加入-s, -S來進行debug,-s的功能是加入 gdb debug的功能,-S是讓kernel停在第一行指令,不要往下跑。
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-image/Image --append "console=ttyAMA0" -s -S
開啟另一個視窗,進到kernel tree中,設定好cross compiler toolchain(download link)的PATH,打入以下指令
$aarch64-linux-gnu-gdb vmlinux
(gdb) target remote localhost:1234
接著出現以下的字串,表示連線成功了。
這邊介紹如何使用gdb來做簡單的debug
之前是打入以下的指令來啟動qemu:
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-image/Image --append "console=ttyAMA0"
接著,我們透過加入-s, -S來進行debug,-s的功能是加入 gdb debug的功能,-S是讓kernel停在第一行指令,不要往下跑。
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-image/Image --append "console=ttyAMA0" -s -S
開啟另一個視窗,進到kernel tree中,設定好cross compiler toolchain(download link)的PATH,打入以下指令
$aarch64-linux-gnu-gdb vmlinux
(gdb) target remote localhost:1234
接著出現以下的字串,表示連線成功了。
Remote debugging using localhost:1234
0x0000000040000000 in ?? ()
接下來就可以開開心心(誤?)的trace aarch64 Linux kernel了。
以下是常用的gdb 指令:
列印系統registers
(gdb) info register
建立斷點
(gdb) break SYMBOL/ADDRESS
列印斷點資訊
(gdb) info break
刪除斷點1
(gdb) delete break 1
free run直接到中斷
(gdb) continue
單步執行
(gdb) stepin
列印目前pc附近的source code以及disassemly code
(gdb) disassemble /m
列印 address開始的16個value
(gdb) x/16 ADDRESS
gdb+qemu有太多可以玩的東西了,對於沒有版子但又想要學習aarch64平台的人來說,是一個很好的方式。
大家可以參考Jserv神之前的大作:快快樂樂學 GNU Debugger (gdb)
1 則留言:
Hello, thanks for this tutorial.
I have another question about gdb.
How to use gdb or other ways to show the bootloader assembly code when I use qemu-system-aarch64 to run your image?
Thanks
張貼留言