gdb一份代码里包含两个程序,一个是gdb,一个是gdbserver,分别运行在PC主机和开发板上,编译的时候得分开编译。
操作系统:ubuntu-16.04.4-desktop-i386
本地编译器:gcc v5.4.0(ubuntu原配)
交叉编译器:arm-linux-gcc v3.4.5
gdb源码:gdb-7.5.tar.bz2(gdb下载地址)
gdb和gdbserver我已经编译好了,在这里:百度网盘,密码: v36n
进入gdb的源码目录,配置gdb:
gdb-7.5$ ./configure --target=arm-linux
gdb-7.5$ make
出现一个错误:
opncls.c: In function ‘bfd_fopen’:
bfd.h:529:65: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
重新配置一次,忽略这种函数命名不规范导致的错误:
gdb-7.5$ ./configure --target=arm-linux --disable-werror
再次make后又出现错误:
checking for library containing waddstr... no
configure: WARNING: no enhanced curses library found; disabling TUI
checking for library containing tgetent... no
configure: error: no termcap library found
Makefile:8370: recipe for target 'configure-gdb' failed
make[1]: *** [configure-gdb] Error 1
make[1]: Leaving directory '/home/sam/Work/gdb/gdb-7.5'
Makefile:844: recipe for target 'all' failed
make: *** [all] Error 2
安装libncureses5-dev:
gdb-7.5$ sudo apt-get install libncurses5-dev
再次make,通过了。此时gdb位于:gdb-7.5/gdb/gdb。你可以执行make install把gdb安装到/usr/local/bin/里去,由于ubuntu自带了一个gdb,我没有这样做,而是后续自己手动加入,并改了个名,以区分ubuntu自带的那个gdb。
然而,gdbtui并没有编译出来,我也不知道为什么,但是我编译gdb-7.4.1是可以的。
进入gdbserver所在目录:gdb-7.5/gdb/gdbserver,配置gdbserver:
gdb-7.5/gdb/gdbserver$ ./configure --target=arm-linux --host=arm-linux
make后出现错误:
linux-arm-low.c: In function `arm_stopped_by_watchpoint':
linux-arm-low.c:643: error: `PTRACE_GETSIGINFO' undeclared (first use in this function)
linux-arm-low.c:643: error: (Each undeclared identifier is reported only once
linux-arm-low.c:643: error: for each function it appears in.)
Makefile:222: recipe for target 'linux-arm-low.o' failed
make: *** [linux-arm-low.o] Error 1
意思是PTRACE_GETSIGINFO这个宏没有定义,这个宏其实位于交叉编译器的安装目录里:
gcc-3.4.5-glibc-2.3.6$ grep -nrR PTRACE_GETSIGINFO
arm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO 0x4202
arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO 0x4202
distributed/arm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO 0x4202
distributed/arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO 0x4202
修改linux-arm-low.c这个文件,添加#include
/* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
On Bionic elf.h and linux/elf.h have conflicting definitions. */
#ifndef ELFMAG0
#include
#endif
#include
#include
#include
再次make,通过了。
在主机上运行arm-linux-gnueabihf-gdb如果报这个错误:
arm-linux-gnueabihf-gdb: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
解决方法是:
sudo apt-get install libpython2.7
在单板上运行gdbserver如果报这个错误:
gdbserver: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
解决方法是:
把主机的<交叉编译器安装目录>/libstdc++.so.6拷贝到单板的/lib目录。
“test”是待调试的可执行程序。
单板:
gdbserver 192.168.43.247:6666 test
主机:
arm-linux-gnueabihf-gdb test
(gdb) target remote 192.168.43.141:6666
OK,可以开始调试了。
这篇文章讲得很详细了:
https://www.jianshu.com/p/4f1140300516