使用gdb、gdbserver在ARM-Linux下进行远程调试

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

http://ftp.gnu.org/gnu/gdb/

二、编译 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]

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值