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源代码:
- 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中)
- 拷贝libthr
ead库(这一步不做的话,运行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
- 测试
- 以上的环境变量都写到~/.profile中吧
- 写一个程序, 用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:6666 ##(连接目标)
Remote debugging using 192.168.0.34:6666
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
- 效果如下图: