Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2115502
  • 博文数量: 374
  • 博客积分: 7276
  • 博客等级: 少将
  • 技术积分: 5668
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-06 16:35
文章分类

全部博文(374)

文章存档

2013年(23)

2012年(153)

2011年(198)

分类:

2011-12-01 11:41:11

原文地址:mini2440 gdb远程调试 作者:sjj0412

-------------------------------------------------
本文系本站原创,欢迎转载!

转载请注明出处:http://sjj0412.cublog.cn/
--------------------------------------------------------
前几天搞qtopia,编译成功,下载到mini2440开发板运行,屏幕没反应,然后就是segment error,感觉无从下手,决定搞
gdb远程调试,记得大四的时候搞过一次,没成功,后来也就没搞了,这次没办法,下定决定搞好,在网上查了下资料,没
想到轻松搞定,当然期间肯定有些错误,但是这些都是小事,很快搞定了,下面说下过程。
1.下载源码,我下的是gdb-6.6
大家可以在下面的网址下载

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 CC=你的交叉编译链路径(x/bin/arm-linux-gcc),如果已经加入PATH环境变量,则使用arm-linux-gcc
     make install
   然后就在~/armgdb/gdbserver/bin看到arm-linux-gdbserver
    这个对于不等于不同版本的交叉编译链,可能会出错,如果在编译arm-linux-low.c这个文件时提示找不到“sys/reg.h”, 则修改arm-linux-low.c,注释掉#include "sys/reg.h"。
 如果是其他的问题,又找不到,那就换交叉编译链,我的3.4.2没问题,4.3.2只有上面这个问题。

然后下载到目标板即可,运行的时候会出问题,会说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客户端
arm-linux-gdb hello
GNU gdb 6.6
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
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
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)

 

阅读(830) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~