uboot有兩個階段,重定位之前和重定位之后,這兩個階段的符號表是不一樣的,因此需關注是調試重定位之前的uboot還是重定位之后的uboot(以riscv版uboot為例)
1. 調試重定位之前的uboot
1.1 使用qemu啟動uboot,並進入調試模式
$ qemu-system-riscv64 -nographic -machine virt -m 512 -kernel <opensbi>/build/platform/qemu/virt/firmware/fw_jump.elf -device loader,file=<uboot>/u-boot.bin -s -S
1.2 調試重定位之前的uboot
$ riscv64-unknown-linux-gnu-gdb <uboot>/u-boot
(gdb) target remote :1234
(gdb) b board_init_f
(gdb) c
2. 調試重定位之后的uboot
2.1 使用qemu啟動uboot,並進入調試模式(同1.1)
2.2 調試重定位之前的uboot
2. 調試重定位之后的uboot
2.1 使用qemu啟動uboot,並進入調試模式(同1.1)
2.2 調試重定位之前的uboot
$ riscv64-unknown-elf-gdb(riscv64-unknown-linux-gnu-gdb) <uboot>/u-boot
(gdb) target remote :1234
//獲取重定位之后uboot在內存中的地址
(gdb) b relocate_code (relocate_code函數的參數指定了重定位之后的uboot地址)
(gdb) c
(gdb) c
(gdb) info register a2
0x8ff64000
(gdb) b call_board_init_r
(gdb) symbol-file (delete old symbols)
Discard symbol table `~/u-boot` (y or n) y
//
加載重定位之后的符號表
(gdb) add-symbol-file <uboot>/u-boot
0x8ff64000
add symbol table file from "~/u-boot" at
.text_addr = 0x8ff64000
(y or n) y
(gdb) b board_init_r
(gdb) c