mini2440 gdb远程调试
时间:2009-05-18 来源:sjj0412
-------------------------------------------------
本文系本站原创,欢迎转载!
gdb远程调试,记得大四的时候搞过一次,没成功,后来也就没搞了,这次没办法,下定决定搞好,在网上查了下资料,没
想到轻松搞定,当然期间肯定有些错误,但是这些都是小事,很快搞定了,下面说下过程。
1.下载源码,我下的是gdb-6.6
大家可以在下面的网址下载
http://www.gnu.org/software/gdb/download/
2. 解压到~/source目录下,这个目录随便你选择
#tar xzvf gdb-6.6.tar.gz -C ~/source
cd ~/source
可以看到gdb-6.6
然后cd gdb-6.6
然后编译宿主gdb,及目标板gdbserver
一般如果你安装了arm cross交叉编译链,就会有arm-linux-gdb,也就不用编译宿主gdb,但是为了保证兼容,还是编译吧。
3,编译宿主gdb
首先建一个编译目录
mkdir -p ~/armgdb/build
cd ~/armgdb/build
~/source/gdb-6.6/configure --target=arm-linux --prefix=/home/jimmy/armgdb(注意这个要用绝对路径,不能用~)
然后make,make install
这样就可以在~/armgdb的bin下看到arm-linux-gdb及其他文件。
4.编译arm-linux-gdbserver
编译server的源码文件要变,在gdb/gdbserver里
进入这个文件夹
cd ~/source/gdb-6.6/gdb/gdbserver
./configure --host=arm-linux --target=arm-linux --prefix=/home/jimmy/armgdb/gdbserver
make
make install
然后就在~/armgdb/gdbserver/bin看到arm-linux-gdbserver
然后下载到目标板即可,运行的时候会出问题,会说libthread_db.so.1找不到,这时可以在/usr/local/arm/3.4.1/arm-linux/lib将这个文件下载到
目标板上去即可,一般放到/lib目录,如果你放到其他目录,要将其加到LD_LIBRARY_PATH环境变量里。
5.调试
1.使用gdbserver
在目标板上运行gdbserver
在目标板上执行
#./gdbserver 192.168.1.230:7777 hello
其中192.168.1.230为目标板的IP。7777为gdbserver打开的端口,可以自己设置。
2. 运行gdb客户端
jimmy@jimmy-linux:/mnt/nfs/bin$ arm-linux-gdb hello
GNU gdb 6.6
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
(gdb) target remote 192.168.1.230:7777
Remote debugging using 192.168.1.230:7777
0x40000dd0 in ?? () from /lib/ld-linux.so.2
(gdb) b main
Breakpoint 1 at 0x84a0: file hello.c, line 3.
(gdb) l
1 #include<stdio.h>
2 int main(){
3 int i=0;
4 i++;
5 printf("%d\n",i);
6 }
(gdb) b main
Breakpoint 1 at 0x84a0: file hello.c, line 3.
(gdb) c
Continuing.
Breakpoint 1, main () at hello.c:3
3 int i=0;
(gdb) n
4 i++;
(gdb) n
5 printf("%d\n",i);
(gdb)