Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1868462
  • 博文数量: 152
  • 博客积分: 3730
  • 博客等级: 上尉
  • 技术积分: 3710
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-02 14:36
个人简介

减肥,运动,学习,进步...

文章分类

全部博文(152)

文章存档

2016年(14)

2015年(17)

2014年(16)

2013年(4)

2012年(66)

2011年(35)

分类: LINUX

2011-12-16 12:33:50

用:

我的环境:
Fedora 14 虚拟机
编译器:arm-linux-gcc-4.3.2
开发板:TQ2440

嵌入式Linux的GDB调试环境由Host和Target两部分组成,Host端使用arm-linux-gdb,Target Board端使用gdbserver。调试时,应用程序在嵌入式目标系统上运行,而gdb调试在Host端。
 一、编译安装gdb+gdbserver
 首先下载gdb源码,我下载的是gdb-7.0.1.tar.gz,然后解压缩到相应的文件夹。
[gong@Gong-Computer testprogram]$ tar -jxvf /mnt/hgfs/Linux/Source/gdb-7.0.1a.tar.bz2 -C /opt/EmbedSky/
跳转到解压缩好的文件夹
[gong@Gong-Computer testprogram]$ cd /opt/EmbedSky/
创建安装目录mygdb
[gong@Gong-Computer EmbedSky]$ make mygdb
[gong@Gong-Computer EmbedSky]$ cd mygdb/

必须要在你想要安装的目录下执行下边的命令,主要是完成一定的配置。
[gong@Gong-Computer mygdb]$ ../gdb-7.0.1/configure -target=arm-linux --prefix=/opt/EmbedSky/mygdb
参数说明:target是目标板,我的是arm-linux,prefix是要安装的目标文件夹。
安装,一般会需要一段时间:
[gong@Gong-Computer mygdb]$ make;make install
创建gdbserver:
然后建立gdbserver。
[gong@Gong-Computer mygdb]$ mkdir gdbserver
[gong@Gong-Computer mygdb]$ cd mygdbserver/
修改权限,添加可执行选项,并设置好相应的配置项:
[gong@Gong-Computer mygdbserver]$ ../../gdb-7.0.1/gdb/gdbserver/configure --host=arm-linux --prefix=/opt/EmbedSky/mygdb/mygdbserver
安装:
[gong@Gong-Computer mygdbserver]$ make;make install
[gong@Gong-Computer mygdbserver]$ arm-linux-strip gdbserver 
去除调试信息,具体为什么不知道,按照别人的做的。
复制gdbserver到开发板的文件系统中就可以了。
[gong@Gong-Computer mygdbserver]$ cp gdbserver /opt/filesystem/nfsroot/bin/gdbserver

二、调试步骤
1、交叉编译,带参数-g加入调试信息。
假设要调试的程序为HelloWorld.c。
[root@Gong-Computer opt]# arm-linux-gcc -g HelloWorld.c -o HelloWorld
2、在TQ2440上开启gdbserver
#gdbserver  :port HelloWorld,host-ip是主机的ip地址,port是端口号。
[root@EmbedSky /opt]# gdbserver 192.168.10.154:5412 HelloWorld 
gdbserver开始监听5412端口(你也可以设其他的值),然后启动HelloWorld,看到
Process HelloWorld created; pid = 668
Listening on port 5412
3、回到Host端
[root@Gong-Computer opt]# arm-linux-gdb HelloWorld 
GNU gdb (Sourcery G++ Lite 2008q3-72) 6.8.50.20080821-cvs
Copyright (C) 2008 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-none-linux-gnueabi".
For bug reporting instructions, please see:
<
红色的说明此gdb在X86的Host上运行,但是调试目标是ARM代码。
然后启动远程调试:
(gdb) target remote 192.168.10.122:5412
Remote debugging using 192.168.10.122:5412
0x00008130 in _start ()
注意其中的IP地址是开发板的IP,其中后面的端口号一定要和之前在开发板中设置的端口后一致,这样才能进行通信。上面的形式说明远程调式开始。

建立链接后,就可以进行调试了。调试在Host端,跟gdb调试方法相同。注意的是要用“c”来执行命令,不能用“r”。因为程序已经在Target Board上面由gdbserver启动了。在主机上调试如下:
(gdb) l
1 #include
2 #include
3
4 int main()
5 {
6 int i = 10;
7 i = i + 10;
8
9 printf("HelloWorld!!!\n");
10 printf("i = %d\n",i);
(gdb) l
11
12 exit(0);
13 }
(gdb) b 10
Breakpoint 1 at 0x8250: file HelloWorld.c, line 10.
(gdb) b 12
Breakpoint 2 at 0x825c: file HelloWorld.c, line 12.
(gdb) c
Continuing.

Breakpoint 1, main () at HelloWorld.c:10
10 printf("i = %d\n",i);
(gdb) r-----------------此处说明r不能在其中运行。
The "remote" target does not support "run".  Try "help target" or "continue".
(gdb) c
Continuing.

Breakpoint 2, main () at HelloWorld.c:12
12 exit(0);
(gdb) p i
$1 = 20
(gdb) c
Continuing.

Program exited normally.
(gdb) 

在开发板的终端上可以发现:
Remote debugging from host 192.168.10.154
HelloWorld!!!
i = 20

Child exited with status 0
GDBserver exiting

基本的调试过程与gdb调试相同,注意在启动远程调试之前,需要先传递好需要的参数才能远程协助。
阅读(7684) | 评论(0) | 转发(4) |
给主人留下些什么吧!~~