gdb 遠端qemu arm除錯

2021-06-22 12:08:49 字數 2049 閱讀 7449

把 c 編譯成 arm 指令的可執行檔案

/usr/bin/arm-linux-gnueabi-g++ hello.cpp 

cat hello.cpp 

#include void crash()

int main()

直接執行報錯,因為 host 是 linux x86

$ ./a.out 

-bash: ./a.out: cannot execute binary file

需要用 qemu-arm 來執行, 結果是期望的

qemu-arm -l  /usr/arm-linux-gnueabi/  a.out 

hello world

qemu: uncaught target signal 11 (segmentation fault) - core dumped

segmentation fault (core dumped)

進行遠端除錯(關鍵是增加 -g 引數,指定埠為1235) 

qemu-arm -g 1235

-l  /usr/arm-linux-gnueabi/  a.out 

執行用 linux-x86 的 gdb 並不能列印 symbol

(gdb) target remote :1235

remote debugging using :1235

(gdb) c

continuing.

program received signal sigsegv, segmentation fault.

0x00000000 in ?? ()

(gdb) bt

#0 0x00000000 in ?? ()

cannot access memory at address 0x0

(gdb) file /home/payne/hello/a.out

a program is being debugged already.

are you sure you want to change the file? (y or n) y

reading symbols from /home/payne/hello/a.out...(no debugging symbols found)...done.

(gdb) bt

#0 0x00000000 in ?? ()

cannot access memory at address 0x0

(gdb)

懷疑要使用 arm 的 gdb 

參見 編譯了 arm 的gdb, 執行後定位到 crash()

qemu-arm -l  /usr/arm-linux-gnueabi/  ./gdb 

(gdb) target remote :1235

remote debugging using :1235

warning: can not parse xml target description; xml support was disabled at compile time

0x40801c40 in ?? ()

(gdb) file /home/payne/hello/a.out

a program is being debugged already.

are you sure you want to change the file? (y or n) y

reading symbols from /home/payne/hello/a.out...(no debugging symbols found)...done.

(gdb) c

continuing.

program received signal sigsegv, segmentation fault.

0x0000841e in crash() ()

(gdb)

結論:

難道說 arm 的 gdbserver, 就只能用 arm 的 gdb?

gdb 遠端qemu arm除錯

把 c 編譯成 arm 指令的可執行檔案 usr bin arm linux gnueabi g hello.cpp cat hello.cpp include void crash int main 直接執行報錯。由於 host 是 linux x86 a.out bash a.out canno...

GDB遠端除錯

3.建立配置檔案 編譯 gdb允許把編譯配置和編譯結果放到任意的目錄,因此可以在gdb目錄之外建立乙個專門存放編譯結果的目錄。cd opt mkdir p arm gdb build cd arm gdb build opt gdb 6.6 configure target arm linux pr...

遠端gdb除錯

在主機上準備目標機的gdb,例如目標機為arm,則準備arm linux gdb 目標機上需要安裝gdbserver 在目標機上用gdbserver執行程式 gdbserver 127.0.0.1 2345 test 注意,待除錯的程式編譯時需要加上 g 引數。在主機上發起鏈結和除錯 進入gdb g...