跳至主要内容

【转】用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  http://cygwin.mirrors.pair.com/gdb/old-releases/
$ 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.

参考连接:
嵌入式软件设计常用的测试工具
http://lionwq.spaces.eepw.com.cn/articles/article/item/16545

评论

此博客中的热门博文

【转】AMBA、AHB、APB总线简介

AMBA 简介 随着深亚微米工艺技术日益成熟,集成电路芯片的规模越来越大。数字IC从基于时序驱动的设计方法,发展到基于IP复用的设计方法,并在SOC设计中得到了广泛应用。在基于IP复用的SoC设计中,片上总线设计是最关键的问题。为此,业界出现了很多片上总线标准。其中,由ARM公司推出的AMBA片上总线受到了广大IP开发商和SoC系统集成者的青睐,已成为一种流行的工业标准片上结构。AMBA规范主要包括了AHB(Advanced High performance Bus)系统总线和APB(Advanced Peripheral Bus)外围总线。   AMBA 片上总线        AMBA 2.0 规范包括四个部分:AHB、ASB、APB和Test Methodology。AHB的相互连接采用了传统的带有主模块和从模块的共享总线,接口与互连功能分离,这对芯片上模块之间的互连具有重要意义。AMBA已不仅是一种总线,更是一种带有接口模块的互连体系。下面将简要介绍比较重要的AHB和APB总线。 基于 AMBA 的片上系统        一个典型的基于AMBA总线的系统框图如图3所示。        大多数挂在总线上的模块(包括处理器)只是单一属性的功能模块:主模块或者从模块。主模块是向从模块发出读写操作的模块,如CPU,DSP等;从模块是接受命令并做出反应的模块,如片上的RAM,AHB/APB 桥等。另外,还有一些模块同时具有两种属性,例如直接存储器存取(DMA)在被编程时是从模块,但在系统读传输数据时必须是主模块。如果总线上存在多个主模块,就需要仲裁器来决定如何控制各种主模块对总线的访问。虽然仲裁规范是AMBA总线规范中的一部分,但具体使用的算法由RTL设计工程师决定,其中两个最常用的算法是固定优先级算法和循环制算法。AHB总线上最多可以有16个主模块和任意多个从模块,如果主模块数目大于16,则需再加一层结构(具体参阅ARM公司推出的Multi-layer AHB规范)。APB 桥既是APB总线上唯一的主模块,也是AHB系统总线上的从模块。其主要功能是锁存来自AHB系统总...

【转】smb协议栈使用示例

/*  * * uncdownload.c  * *  * * Utility for downloading files from SMB shares using libsmbclient  * *  * * Copyright(C) 2006 Sophos Plc, Oxford, England.  * *  * * This program is free software; you can redistribute it and/or modify it under the terms of the  * * GNU General Public License Version 2 as published by the Free Software Foundation.  * *  * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  * * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  * * See the GNU General Public License for more details.  * *  * * You should have received a copy of the GNU General Public License along with this program; if not,  * * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  * *  * */ # include < sys / types . h > # include < sys / time . h > # include ...

【转】udp编程实例

UDP通讯实例 2008-04-29 15:30:05 / 个人分类: linux C编程 UDP协议的几点好处: 1.UDP不要求保持一个连接; 2.UDP没有因接收方认可收到数据包(或者当数据包没有正确抵达而自动重传)而带来的开销; 3.设计UDP的目的是用于短应用和控制信息; 4.在一个数据包接一个数据包的基础上,UDP要求的 网络 带宽比TCP更小。 UDP的几个缺点: 1.程序员必须创建代码检测传输错误并进行重传(如果应用程序要求这样做); 2.程序员必须把大数据包分片。 code: <1> /* * sender.c--UDP protocol example */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> int port = 6789; int main() {     int socket_descrīptor;     int iter = 0;     char buf[80];     struct sockaddr_in address;     /* Initialize socket address structure for Interner Protocols */     bzero(&address, sizeof(address)); // empty data structure     address.sin_family = AF_INET;     address.sin_addr.s_addr = inet_addr("127.0.0.1");     address...