本文编译的gdb版本为8.3。
一、系统编译环境搭建
编译之前请自行安装gcc等相关编译环境,而且还要安装 texinfo 这个工具,否则会出现如下错误
/home/jack/Downloads/gdb-8.3/missing: 81: /home/jack/Downloads/gdb-8.3/missing: makeinfo: not found
WARNING: 'makeinfo' is missing on your system.
You should only need it if you modified a '.texi' file, or
any other file indirectly affecting the aspect of the manual.
You might want to install the Texinfo package:
<http://www.gnu.org/software/texinfo/>
The spurious makeinfo call might also be the consequence of
using a buggy 'make' (AIX, DU, IRIX), in which case you might
want to install GNU make:
<http://www.gnu.org/software/make/>
Makefile:486: recipe for target 'gdb.info' failed
make[5]: *** [gdb.info] Error 127
make[5]: Leaving directory '/home/jack/Downloads/gdb-8.3/gdb/doc'
Makefile:1994: recipe for target 'subdir_do' failed
make[4]: *** [subdir_do] Error 1
make[4]: Leaving directory '/home/jack/Downloads/gdb-8.3/gdb'
Makefile:1752: recipe for target 'install-only' failed
make[3]: *** [install-only] Error 2
make[3]: Leaving directory '/home/jack/Downloads/gdb-8.3/gdb'
Makefile:1749: recipe for target 'install' failed
make[2]: *** [install] Error 2
make[2]: Leaving directory '/home/jack/Downloads/gdb-8.3/gdb'
Makefile:9155: recipe for target 'install-gdb' failed
make[1]: *** [install-gdb] Error 2
make[1]: Leaving directory '/home/jack/Downloads/gdb-8.3'
Makefile:2222: recipe for target 'install' failed
make: *** [install] Error 2
执行以下命令安装即可
sudo apt-get install texinfo
二、GDB源代码修改
环境安装成功后,将源代码解压出来
tar -zxvf ./gdb-8.3.tar.gz
如果要进行gdb远程调试,则需要对remote.c文件中的代码进行修改。
将
if (buf_len > 2 * rsa->sizeof_g_packet)
error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
"bytes): %s"),
rsa->sizeof_g_packet, buf_len / 2,
rs->buf.data ());
修改为
#if 0
if (buf_len > 2 * rsa->sizeof_g_packet)
error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
"bytes): %s"),
rsa->sizeof_g_packet, buf_len / 2,
rs->buf.data ());
#else
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;
}
}
#endif
三、配置脚本及编译安装
执行如下指令
./configure --target=arm-linux --program-prefix=arm-linux- --prefix=`pwd`/output/
make && make install
如无问题,在gdb的编译目录下面可以看到output文件夹,相关的执行文件在这里面。
四、未解之谜
目前发现如果使用git管理gdb源代码(从gitlab仓库中拉取代码),然后通过步骤三进行编译,会出现报错,而且这些错误都是随机的。
解决方式,通过解压 gdb-8.3.tar.gz 这个压缩包覆盖仓库代码(被修改过的文件,无需覆盖),然后重新编译即可。