編譯gdb/gdbserver
編譯arm-linux-gdb
下載gdb-7.12,解壓縮進入目錄
./configure --target=arm-linux --program-prefix=arm-linux- --prefix=/opt/arm-linux-gdb/
修改gdb/remote.c
//==================================
如果gdb提示:GDB7.6 Remote 'g' packet reply is too long
修改gdb/remote.c文件,屏蔽process_g_packet函數中的下列兩行:
if (buf_len > 2 * rsa->sizeof_g_packet)
error (_(“Remote ‘g’ packet reply is too long: %s”), rs->buf);
在其后添加:
if (buf_len > 2 * rsa->sizeof_g_packet) {
rsa->sizeof_g_packet = buf_len ;
for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
{
if (rsa->regs[i].pnum == -1)
continue;
if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
rsa->regs[i].in_g_packet = 0;
else
rsa->regs[i].in_g_packet = 1;
}
}
編譯gdbserver
進入gdb/gdbserver目錄
./configure --target=arm-linux --host=arm-linux
修改生成的makefile,將CC AR GXX都修改為交叉編譯工具鏈中的工具
make
將生成的gdbserver移植到目標機即可
目標機:arm
假設正在運行的程序名字為hello,其進程ID 為6622,目標機IP為192.168.0.11,那么在目標機端開啟gdbserver的命令格式:
#命令格式 gdbserver IP:PORT --attach PID
具體到目標機開啟的命令為:
[root@test ~]# gdbserver 192.168.0.11:8888 --attach 6622 Attached; pid = 6622 Listening on port 8888
調試機:PC
root@liangwode:# arm-linux-gdb GNU gdb (GDB) 7.12 Copyright (C) 2016 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-pc-linux-gnu --target=arm-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://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". (gdb) target remote 192.168.0.11:8888 Remote debugging using 192.168.0.11:8888 warning: Can not parse XML target description; XML support was disabled at compile time Reading /home/storm/ftp/hello from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /home/storm/ftp/hello from remote target... Reading symbols from target:/home/storm/ftp/hello...done. Reading /lib/libc.so.6 from remote target... Reading /lib/ld-linux-armhf.so.3 from remote target... Reading symbols from target:/lib/libc.so.6...done. Reading symbols from target:/lib/ld-linux-armhf.so.3...done. 0x76f0a8d4 in nanosleep () at ../sysdeps/unix/syscall-template.S:84 84 ../sysdeps/unix/syscall-template.S: No such file or directory.