gdb+gdbserver调试

65 篇文章 1 订阅

gdb+gdbserver 是调试目标板的常用方法.
看了网上的一些资料,加上我自己的一些体会, 写个完整的记录吧:
我的环境如下:HOST 192.168.0.33 Target: 192.168.0.34
NFS共享目录: mount -t nfs -o nolock /home/itlanger/work /mnt


编译arm-gdb:
下载gdb源代码:

$ cd downloads

$ wget -t 0 -w 30 -c http://ftp.gnu.org/gnu/gdb/gdb-6.6.tar.gz
tar zxvf gdb-6.6.tar.gz
cd gdb-6.6
./configure --target=arm-linux --prefix=/usr/local/arm-gdb -v

make
sudo make install
export PATH=$PATH:/usr/local/arm-gdb
编译arm-gdb-server
cd ~/downloads/gdb-6.6/gdb/gdbserver
./configure --target=arm-linux --host=arm-linux
make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc ##这里是交叉编译器的路径
cp gdbserver ~/work ##gdbserver是编译生成的
export PATH=$PATH:/usr/local/arm-gdb/bin (最好加到.bashrc中)

拷贝libthread库(这一步不做的话,运行gdbserver会出错!)
$ cd /usr/local/arm/3.4.1/arm-linux/lib
$ ls -l libthread_db*
-rwxr-xr-x 1 2619 man 29151 2004-07-28 23:08 libthread_db-1.0.so
lrwxrwxrwx 1 2619 man    17 2008-05-25 12:00 libthread_db.so -> libthread_db.so.1
lrwxrwxrwx 1 2619 man    19 2008-05-25 12:00 libthread_db.so.1 -> libthread_db-1.0.so

$ cp libthread_db-1.0.so ~/work

minicom下:
# cd /lib/
# cp /mnt/libthread_db-1.0.so /lib/
# ln -s libthread_db-1.0.so libthread_db.so.1
# ln -s libthread_db-1.0.so libthread_db.so
测试
写一个程序, 用arm-linux-gcc -g 编译, 放到work目录下, (我的为third)

minicom下: 

cd /mnt

./gdbserver 192.168.0.33:6666 third
Process third created; pid = 356
Listening on port 6666
终端下:
export PATH=$PATH:/usr/local/arm-gdb/bin
cd ~/work
arm-linux-gdb third
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
(gdb)

(gdb) target remote 192.168.0.34:2345       ##(连接目标)
Remote debugging using 192.168.0.34:2345
0x40000dd0 in ?? () from /lib/ld-linux.so.2
现在可以通过l, b 设置断点了
运行: 用命令c    ##记住这里不是用run, 因为程序已在Target Board上面由gdbserver启动了。结果输出是在Target Board端

这样就可以用emacs方便地远程调试了。
M-x gdba ##(我已经绑定到F10了)

Run gdba (like this): arm-linux-gdb -annotate=3 third

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值