Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209550
  • 博文数量: 40
  • 博客积分: 1435
  • 博客等级: 上尉
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-24 21:57
文章分类

全部博文(40)

文章存档

2011年(4)

2010年(2)

2007年(34)

我的朋友

分类: LINUX

2007-08-25 11:27:51

转载1

(1) download gdb source
ftp://ftp.gnu.org/gnu/gdb/

(2) compile
(2.1) compile gdb
./configure --target=arm-linux -v
make
在gcc4.0中,强制转换的值不能做左值.
如果您和我一样用的是gcc 4.0, 那只好把这几个地方修改了,也不知道是不是因为这个原因,有了本文最后面的那个问题。
(2.2) compile gdbserver(这个是要运行在arm上的,所以要进行交叉编译)
cd gdb/gdbserver
./configure --target=arm-linux --host=arm-linux
把config.h中的以下这一行用//注释掉
// #define HAVE_SYS_REG_H 1
make CC=arm-linux-gcc
libthread_db.so.1找不到的问题也比较麻烦,可以再把下面这一行注释掉
/* Define if you have the header file.  */
//#define HAVE_THREAD_DB_H 1

(3)
run gdbsever on the ARM board
# gdbserver 192.168.0.2:1254 hello

run gdb on the pc
[root@localhost helloWorld]# ./gdb
GNU gdb 6.3
Copyright 2004 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.&<60; Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
(gdb) target remote 192.168.0.2:1254
Remote debugging using 192.168.0.2:1254
0x40001b80 in ?? ()
(gdb) symbol-file /share/hello
Reading symbols from /share/hello...done.
(gdb) break 5
Breakpoint 1 at 0x83b8: file hello.c, line 5.
(gdb) break 7
Breakpoint 2 at 0x83c4: file hello.c, line 7.
(gdb) break hello.c:17
Breakpoint 3 at 0x8408: file hello.c, line 17.
(gdb) c
如果不停地step, 遇到printf这样的库函数,由于找不到symbol,会使gdb段错误退出
关于这些symbol要如何搞定,现在没有时间管了,再说.

转载2

S3C2410 ARM板上构造gdb +gdbserver调试环境
 
远程调试环境由宿主机gdb和目标机调试stub共同构成,两者通过串口或TCP连接。使用GDB标准程串行协议协同工作,实现对目标机上的系统内核和上层应用的监控和调试功能。调试stub是嵌入式系统中的一段代码,作为宿主机GDB和目标机调试程序间的一个媒介而存在。
         
       就目前而言,嵌入式Linux系统中,主要有三种远程调试方法,分别适用于不同场合的调试工作:
       用ROMMonitor调试目标机程序、
       用KGDB调试系统内核
       用gdbserver调试用户空间程序。
      
       这三种调试方法的区别主要在于,目标机远程调试stub的存在形式的不同,而其设计思路和实现方法则是大致相同的。
而我们最常用的是调试应用程序。就是采用gdb+gdbserver的方式进行调试。在很多情况下,用户需要对一个应用程序进行反复调试,特别是复杂的程序。采用GDB方法调试,由于嵌入式系统资源有限性,一般不能直接在目标系统上进行调试,通常采用gdb+gdbserver的方式进行调试。Gdbserver在目标系统中运行,gdb则在宿主机上运行。

      目标系统必须包括gdbserver程序,宿主机也必须安装gdb程序。一般linux发行版中都有一个可以运行的gdb,但开发人员不能直接使用该发行版中的gdb来做远程调试,而要获取gdb的源代码包,针对arm平台作一个简单配置,重新编译得到相应gdb如armv4l-unknown-linux-gdb  。
1.source compile
download  from 
$ tar jxf gdb-5.2.1.tar.bz2
$ cd gdb-5.2.1
$ mkdir obj
$ cd obj
../configure --target=armv4l-unknown-linux \
        --enable-shared --prefix=/tmp/g \
        --without-x --disable-gdbtk --disable-tui \
        --without-included-regex --without-included-gettext
$ make
$ make install
$ mkdir gdb/gdbserver 
$ cd gdb/gdbserver
$ chmod +x ../../../gdb/gdbserver/configure
$ CC=/opt/host/armv4l/bin/armv4l-unknown-linux-gcc \
        ../../../gdb/gdbserver/configure armv4l-unknown-linux \
        --without-included-regex --without-included-gettext
$ make
$ cp -vf gdbreplay gdbserver /tmp/g/bin

2.remote debugging

o cp  gdbserver from  host  to  target machine

o target machine
        gdbserver 59.69.74.87:2345 hello
   
出现
Process hello created; pid = 68

o host
        /tmp/g/bin/armv4l-unknown-linux-gdb hello
       (gdb) b main
       (gdb) target remote 203.239.30.207:2345
      出现 Remote debugging using 59.69.75.186:2345
           0x40002a00 in ?? ()

       (gdb) c  //相当于主机gdb的run命令
      
此时目标机上出现
Remote debugging from host 59.69.74.87
hello,world

  连接成功后,这时候就可以输入各种gdb命令如list、run、next、step、break等进行程序调试了。
调试结束出现                                                                               
Child exited with retcode =0

                                                                       
Child exited with status 236
GDBserver exiting

说明: 
1)目标机上的被调试程序hello, 与主机上的程序hello, 是相同的程序, 但位置不一样,并非是用网络共享的同一个位置的同一个文件, 一个在目标机上 ,一个在主机上, 没有关系.
2) host ip  : 59.69.74.87
    target  2410  ip is  59.69.75.186               
都是局域网ip.

转3

嵌入式Linux的GDB调试环境由Host和Target两部分组成,Host端使用arm-linux-gdb,Target Board端使用gdbserver。调试时,应用程序在嵌入式目标系统上运行,而gdb调试在Host端。

 一、编译安装gdb+gdbserver

 首先下载gdb源码,我下载的是gdb-6.6.tar.gz。

$tar xvzf gdb-6.6.tar.gz

$mkdir mygdb

$cd mygdb

必须要在你想要安装的目录下执行下边的命令。

$../gdb-6.6/configure --target=arm-linux   \ --prefix=/home/a/mygdb

参数说明:target是你的目标板,我的是arm-linux,prefix是你要安装的目标文件夹。

$make

$make install

然后建立gdbserver。

$mkdir mygdbserver

$cd mygdbserver

$chmod +x ../gdb-6.6/gdb/gdbserver/configure

$CC=arm-linux-gcc ../gdb-6.6/gdb/gdbserver/configure \

--host=arm-linux  --prefix=/home/a/mygdbserver

$make

$make install

$arm-linux-strip gdbserver

去除调试信息。不去好像不行,我的就不行,去了就ok了。

复制到你的开发板上就可以了。

 二、调试步骤

1、交叉编译,带参数-g加入调试信息。

假设要调试的程序为test.c。

#arm-linux-gcc -g test.c -o test

2、在Target Board开启gdbserver

#gdbserver  :2345 test

gdbserver开始监听2345端口(你也可以设其他的值),然后启动test,你会看到“Process test created:pid=88”

3、回到Host端

#arm-linux-gdb test

最后一行显示:This GDB was configured as “--host=i686-pc-linux-gnu,--target=arm-linux”...

说明此gdb在X86的Host上运行,但是调试目标是ARM代码。

(gdb)target remote :2345

注意:你的端口号必须与gdbserver开启的端口号一致,这样才能进行通信。

建立链接后,就可以进行调试了。调试在Host端,跟gdb调试方法相同。注意的是要用“c”来执行命令,不能用“r”。因为程序已经在Target Board上面由gdbserver启动了。结果输出是在Target Board端,用超级终端查看。


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