背景
上一章介紹了如何使用QEMU 運行RISC-V 程序, GDB 作爲強大的代碼調試工具,對軟件開發至關重要,本章介紹如何啓動GDB 調試
CSDNhttps://mp.csdn.net/mp_blog/creation/editor/132522853
開啓GDB 服務
QEMU 啓動時添加-s參數, 代碼啓用本地GDB 服務, 默認端口號爲1234.
qemu-system-riscv32 -nographic -machine virt -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -bios none -smp 4 -s -kernel ~/project/freeRTOS/FreeRTOS_main/FreeRTOS/Demo/RISC-V-Qemu-virt_GCC/build/RTOSDemo.axf
連接GDB 調試
開啓一個新的終端, 啓用gdb 客戶端,
/opt/riscv/bin/riscv64-unknown-elf-gdb ~/project/freeRTOS/FreeRTOS_main/FreeRTOS/Demo/RISC-V-Qemu-virt_GCC/build/RTOSDemo.axf
連接GDB 服務,開啓debug
gdb 窗口輸入如下命令, 連接到GDB Server, GDB 連接成功,
如下圖所示, 輸入bt, 可顯示函數運行調用栈, enjoy it
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x80001b5c in freertos_risc_v_trap_handler ()
(gdb) bt
#0 0x80001b5c in freertos_risc_v_trap_handler ()
#1 0x80003c58 in _vfprintf_r ()
#2 0x80001f2a in printf ()
#3 0x8000191a in test_list_main ()
#4 0x00000000 in ?? ()