交叉编译运行arm版本的gdb
下载源码
https://ftp.gnu.org/gnu/gdb/ 下载gdb-11.2.tar.gz,版本最好同local交叉编译器的对齐。
arm-linux-gnueabi-gdb -v
GNU gdb (GDB) 11.2
查看 README.android
export CC='/xxx/xxx/xxx/usr/bin/arm-linux-gnueabi-gcc --sysroot=/xxx/xxx/xxx/'
export CXX='/xxx/xxx/xxx/usr/bin/arm-linux-gnueabi-gcc --sysroot=/xxx/xxx/xxx/'
export LD='/xxx/xxx/xxx/usr/bin/arm-linux-gnueabi-ld --sysroot=/xxx/xxx/xxx/'
export AR='/xxx/xxx/xxx/usr/bin/arm-linux-gnueabi-ar'
./configure --prefix=`pwd`/output --host=arm-linux
make -j4
make install
运行gdb
1.编译测试程序
#include <stdio.h>
int main()
{
printf("hello gdb\n");
return 0;
}
arm-linux-gnueabi-gcc -g main.c -o test
2.拷贝install目录下的bin/gdb和test以及main.c拷贝到u盘
# ./gdb ./test
warning: Found custom handler for signal 4 (Illegal instruction) preinstalled.
warning: Found custom handler for signal 6 (Aborted) preinstalled.
warning: Found custom handler for signal 7 (Bus error) preinstalled.
warning: Found custom handler for signal 8 (Floating point exception) preinstalled.
warning: Found custom handler for signal 11 (Segmentation fault) preinstalled.
warning: Found custom handler for signal 16 (Stack fault) preinstalled.
Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN)
won't be propagated to spawned programs.
GNU gdb (GDB) 11.2
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(gdb) l
1 #include <stdio.h>
2
3 int main()
4 {
5
6 printf("hello stone\n");
7 return 0;
8 }
(gdb) b main
Breakpoint 1 at 0x6f8: file main.c, line 6.
(gdb) r
Starting program: /tmp/usb/sda/sda1/nagra/mem/test
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Breakpoint 1, main () at main.c:6
6 printf("hello gdb\n");
(gdb) n
hello gdb
7 return 0;
(gdb)
8 }
(gdb)
__libc_start_call_main (main=main@entry=0x4006f5 <main>, argc=argc@entry=1, argv=0xfffef584, argv@entry=0xf7f44e3c) at ../sysdeps/nptl/libc_start_call_main.h:74
74 ../sysdeps/nptl/libc_start_call_main.h: No such file or directory.
(gdb)
[Inferior 1 (process 994) exited normally]
(gdb) q
#
运行gdbserver
1.板子上运行gdbserver指定端口12345
# ./gdbserver :12345 ./test
warning: Found custom handler for signal 4 (Illegal instruction) preinstalled.
warning: Found custom handler for signal 6 (Aborted) preinstalled.
warning: Found custom handler for signal 7 (Bus error) preinstalled.
warning: Found custom handler for signal 8 (Floating point exception) preinstalled.
warning: Found custom handler for signal 11 (Segmentation fault) preinstalled.
warning: Found custom handler for signal 16 (Stack fault) preinstalled.
Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN)
won't be propagated to spawned programs.
Process ./test created; pid = 1070
Listening on port 12345
2.服务器上运行gdb
arm-linux-gnueabi-gdb ./test
GNU gdb (GDB) 11.2
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux --target=arm-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(gdb) target remote 192.168.1.148:12345
Remote debugging using 192.168.1.148:12345
Reading /lib/ld-linux.so.3 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /lib/ld-linux.so.3 from remote target...
Reading symbols from target:/lib/ld-linux.so.3...
0xf7fcf81c in _start () from target:/lib/ld-linux.so.3
(gdb)
3.gdb server会显示已经连接
Remote debugging from host ::ffff:192.168.1.10, port 47970
4.server gdb开始debug
(gdb) l
1 #include <stdio.h>
2
3 int main()
4 {
5
6 printf("hello stone\n");
7 return 0;
8 }
(gdb) b main
Breakpoint 1 at 0x4006f8: file main.c, line 6.
(gdb) c
Continuing.
Reading /lib/libSegFault.so from remote target...
Reading /lib/libgcc_s.so.1 from remote target...
Reading /lib/libc.so.6 from remote target...
Reading /usr/lib/libunwind-arm.so.8 from remote target...
Reading /usr/lib/libunwind.so.8 from remote target...
Reading /lib/.debug/libSegFault.so from remote target...
Breakpoint 1, main () at main.c:6
6 printf("hello stone\n");
(gdb) n
7 return 0;
(gdb) n
8 }
(gdb)
__libc_start_call_main (main=main@entry=0x4006f5 <main>, argc=argc@entry=1, argv=0xfffef5e4, argv@entry=0xf7f44e3c) at ../sysdeps/nptl/libc_start_call_main.h:74
74 ../sysdeps/nptl/libc_start_call_main.h: No such file or directory.
(gdb) q