使用Gdb、gdbserver在ARM

一、下载gdb-6.4.tar.gz源代码

点击这里下载Gdb 的简单使用gdb+gdbserver 方式进行ARM 程序调试PDF版

二、编译 GDB

2.1、编译arm-linux-gdb

#tar zxvf gdb-6.4.tar.gz

#cd gdb-6.4
#./configure --target=arm-linux --prefix=/usr/local/arm-gdb
#make

#make install // 生成/usr/local/arm-gdb/bin

2.2、编译GDB Client

#cd ./gdb/gdbserver
    #export PATH=$PATH:/usr/local/arm-gdb/bin
    #./configure --target=arm-linux --host=arm-linux
    #vi config.h
         //#define HAVA_SYS_REG_H //注释此句

//#define HAVE_TD_VERSION //注释此句
    #make CC=arm-softfloat-linux-gnu-gcc //指定用于编译gdbserv的交叉编译器的路径

编译用于目标机的stub程序 生成gdbserver是GDB客户端程序,在板子上运行。

三、实战调试

1. 下载文件到目标板: gdbtest和gdbserver

假设 host pc ip:192.168.1.45
         board ip:192.168.1.180

将文件拷贝到目标板上:

先将gdbtest和gdbserver两个文件拷贝到主机的/tftpboot目录下

在目标板的Linux中运行:

#mount 192.168.1.108:/tftpboot /mnt/nfs
    #cd /mnt/nfs
    #ls

看是否有gdbtest和gdbserver两个文件。

3.运行调试

client board:
    #./gdbserver 192.168.1.45:1234 gdbtest // 目标板上运行gdbtest 监听端口1234
    host pc:
    #cd /usr/local/arm-gdb/bin/
    #copy gdbtest /usr/local/arm-gdb/bin/ // 将前面编译的文件gdbtest拷贝到此目录
    #./arm-linux-gdb gdbtest
    (gdb)target remote 192.168.1.180:1234 // 连接到开发板 成功后就可以进行调试
    (gdb)list or l
    (gdb)break func
    (gdb)break 22
    (gdb)info br
    (gdb)continue or c // 这里不能用 run
    (gdb)next or n
    (gdb)print or p result
    (gdb) finish // 跳出func函数
    (gdb) next
    (gdb) quit

建立连接后进行gdb远程调试和gdb本地调试方法相同

gdb/gdbserver 调试多线程

While debuging a remote multithread program by means of gdb/gdbserver, frequently I see gdb complaints like this:

Program received signal SIG32, Real-time event 32.
0x400d7e84 in ?? ()
(gdb)

Then gdb is suspended to wait for new commands, and on this occasion, typing 'c' can make the debuging continue. But instruction 'info threads' can not list correct information.

In fact, this results from stripped libpthread/libthread_db, which can be easily verified by means of '/usr/bin/file'. To remove the problem, simply refer the libs to unstripped versions via gdb instructions like:

set solib-absolute-prefix [dir]

set solib-search-path [dir1];[dir2]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/24633.html