1. gdb + gdbserver交叉编译 下载GDB源码: http://ftp.gnu.org/gnu/gdb/这里选择gdb-7.9.1.tar.gztar -zxvf gdb-7.9.1.tar.gz gdb 安装:cd gdb-7.9.1./configure --target=arm-ambarella-linux-uclibcgnueabihf --prefix=/usr/local/arm-amba-gdb -v--target配置gdb的目标平台,--prefix配置安装路径makemake install将bin目录下生成的可执行文件拷贝至交叉编译器的bin目录下gdbserver安装:cd gdb-7.9.1/gdb/gdbserver./configure --host=arm-ambarella-linux-uclibcgnueabihf --prefix=/usr/local/gdbservermake make installbin目录下生成可执行文件gdbserver ,用于板端运行2.板端建立远程调试环境./gdbserver 192.168.1.86:1234 ipcam192.168.1.86为PC端IP地址3.HOST端GDB加载要调试的应用程序arm-ambarella-linux-uclibcgnueabihf-gdb ipcam4.连接到目标板调试服务(gdb) target remote 192.168.1.87:1234192.168.1.87为板端IP地址成功连接arm板后,板端打印信息为: ./gdbserver 192.168.1.86:1234 ipcam Process ipcam created; pid = 274 Listening on port 1234 Remote debugging from host 192.168.1.86上面这行表示宿主机和开发板连接成功。现在我们就可以在Host端像调试本地程序一样调试ARM板上程序。不过,需要注意的是这里执行程序要用“c”,不能用“r”。因为程序已经在Target Board上面由gdbserver启动了。Remote 'g' packet reply is too long问题解决:Remote 'g' packet reply is too long: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060fdff7e00000000542eff76100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0x76ff2e54 in ?? ()修改gdb/remote.c文件,定位到:static void process_g_packet (struct regcache *regcache)函数,6113行,屏蔽对buf_len的判断。(gdb) cContinuing. warning: Could not load shared library symbols for 15 libraries, e.g. /usr/lib/libfreetype.so.6. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? Program received signal SIGSEGV, Segmentation fault. 0x76ff5d62 in ?? ()若产生这个错误主要是由于该调试的应用程序使用到了额外的库,而这个库在gdb默认的搜索路径内没有 (相对与远程调试,gdb默认搜索的路径即为交叉编译器的库路径) 因此,这里我们需要修改一下gdb默认的共享库搜索路径。修改的办法是设置GDB的环境变量:solib-absolute-prefix设置的是被搜索文件路径的前缀,一般设置为交叉编译工具链的库路径前缀,即不包括lib目录,lib目录的父目录,solib-search-path设置的是被搜索库文件的路径。solib-search-path可以有多个路径,中间按用:隔开, solib-absolute-prefix的值只能有一个。若在solib-absolute-prefix指定的路径内没有搜索到库,则再继续尝试从solib-search-path指定的路径进行搜索。设置库搜索路径:根据提示依次找到相应库的路径,并设置,以下是我的最终结果:e.g: (gdb)setsolib-search-path /usr/local/arm-amba-linux-uclibcgnueabihf-2014.11-gcc4.9/arm-ambarella-linux-uclibcgnueabihf/sysroot/usr/lib:/home/yym/work/S2L_2_0:/usr/local/arm-amba-linux-uclibcgnueabihf-2014.11-gcc4.9/arm-ambarella-linux-uclibcgnueabihf/sysroot/lib设置好 solib-search-path后再运行程序(gdb) c Continuing. Program terminated with signal SIGSEGV, Segmentation fault. The program no longer exists.如果出现上述情况,需再次重复步骤2,4 再运行