本文編譯的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 這個壓縮包覆蓋倉庫代碼(被修改過的文件,無需覆蓋),然後重新編譯即可。