1. 下载源码 http://www.gnu.org/software/gdb/download/
2. su root 切换到root用户
3. 打算安装到/usr/local/arm-gdb目录下,先手动创建该目录
mkdir -p /usr/local/arm-gdb
chown -R mars /usr/local/arm-gdb
4. cd到源码包所在目录/usr/src
解压
tar -jxvf gdb-7.2a.tar.bz2
注:gcc4.6对应用的是gdb-7.2,gcc4.9对应用的是gdb-8.0
4.1 编译安装gdb
[gdb7.2]:
./configure --target=arm-none-linux-gnueabi --prefix=/usr/local/arm-gdb
make
make install
[gdb8.0]:
(1)8.0依赖expat库,不装的话会提示类似如下错误:
(gdb) target remote 192.168.0.138:1234
Remote debugging using 192.168.0.138:1234
warning: Can not parse XML target description; XML support was disabled at compile time
Reading /lib/ld-linux-armhf.so.3 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/ld-linux-armhf.so.3...done.
Remote 'g' packet reply is too long (expected 168 bytes, got 328 bytes): 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020fdffbe00000000007afdb6100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
编译安装libexpat
a. 下载源码https://github.com/libexpat/libexpat
b. 解压
c. ./configure --without-docbook --prefix=/usr/local/arm-gdb/expat_out
d. make & make install
(2)编译安装gdb
a. 解压
b. cd 到 gdb-8.0/gdb下
c. ./configure --target=arm-linux --prefix=/usr/local/arm-gdb --with-expat --with-libexpat-prefix=/usr/local/arm-gdb/expat_out
d. make & make install
注:一定注意是在gdb-8.0根目录的gdb子目录下执行,如果在gdb-8.0目录下执行,make时会提示
checking whether to use expat... yes
checking for libexpat... (cached) no
configure: error: expat is missing or unusable
------------------
完成后可以到/usr/local/arm-gdb中看到安装之后的内容
注:这一步编译生成的arm-none-linux-gnueabi-gdb是运行在主机上的,所以编译过程会看到用的是主机gcc而不是交叉gcc
-----------------
4.2 编译gdbserver
配置
cd gdb-7.2/gdb/gdbserver
./configure --target=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi
编译
make CC=arm-none-linux-gnueabi-gcc
拷贝
把生成的gdbserver拷贝至目标板上(以/gdbserver为例)
5. 调试
在目标板上启动gdbserver监听
/gdbserver 192.168.0.102:1234 x_fifo
其中1234是gdbserver在目标板上的监听端口,x_fifo是目标调试程序,192.168.0.102是主机也就是gdb所在机器,而不是目标板的IP,这样写法很别扭,不过据说新的gdb中这个IP已经被忽略了。
补充:注意,如果x_fifo有启动参数,则需要在此处加上。
(1)在主机上目标程序所在目录启动gdb
/usr/local/arm-gdb/bin/arm-none-linux-gnueabi-gdb x_fifo
补充:arm-poky-linux-gnueabi-gdb x_fifo(安装目录/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi)
注意:最好用绝对路径启动,因为机器里可能有安装过同名的gdb
补充:/usr/local/lierd-arm-nosgx-gdb/bin/arm-linux-gdb test
(2)然后链接到目标板
target remote 192.168.0.139:1234
正常情况下就可以开始调试了,但有时候需要设置环境变量
比如,可能看到这样的提示
warning: Could not load shared library symbols for /lib/ld-linux.so.3.
Do you need "set solib-search-path" or "set sysroot"?
或者
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Cannot access memory at address 0x0
0x76fd7b00 in ?? ()
这个时候,执行show solib-search-path,注意这是在gdb里面执行。
结果显示The search path for loading non-absolute shared library symbol files is /lib
也就是说gdb会在主机的/lib目录下寻找ld-linux.so.3.文件。这是路径寻找中的一部分,如果找不到,则另一部分是靠solib-absolute-prefix环境变量。
执行show solib-absolute-prefix可以看当前的环境变量值
执行set solib-absolute-prefix /opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/arm-fsl-linux-gnueabi/multi-libs设置环境变量值
补充:set solib-absolute-prefix /opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi
执行set solib-absolute-path /opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/arm-fsl-linux-gnueabi/multi-libs:.设置被搜索文件的路径
补充:set solib-absolute-prefix /opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi(此项设置时提示No symbol "solib" in current context好像没成功,但未影响使用)
注意这个路径不涵盖到lib,也就是说/lib/ld-linux.so.3.在这个环境变量指定的目录中
solib-absolute-prefix设置的是被搜索文件路径的前缀,solib-search-path设置的是被搜索文件的路径。
solib-search-path可以有多个路径,中间按用:隔开, solib-absolute-prefix的值只能有一个。
补:poky的路径是/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi
注意编译目标程序的时候加-g选项