GDBSERVER 用于omapl138调试---过程详细分析

注:发现有人引用本文,颇感荣幸!

请注明出处 http://blog.csdn.net/liufengl138/article/details/7634529


用了一番功夫研究GDBSERVER,这里先将GDBSERVER调试目标板程序的原理摘录部分资料如下:

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

---网上资料作者:李 权 李彦明 厉磊

实现步骤如下:

1.安装工具链(这里还是用的Sourcey_G++Lite,还没试dvsdk提供的东东)arm-2009q1-203-arm-none-linux-gnueabi.bin---注意这个有128M,那里得来他你知道的;

2.安装位置 /opt/CodeSourcery/Sourcery_G++_Lite;

3.copy GDBSERVER 及其关联库到目标板运行的目录中去

   sudo cp  //opt/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi//libc/usr/bin/gdbserver   /nfs/usr/bin  ;//这里/nfs 是我们安装启动的目录nfs,你的要求相应修改;

   sudo cp /opt/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libthread_db*   /nfs/lib

   sudo   cp /opt/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libgcc_s.so.1     /nfs/lib

   sudo   cp /opt/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/liblibc.so.6              /nfs/lib

   sudo  cp /opt/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3      /nfs/lib

4.target目标板运行完整结果

U-Boot 2009.01 (Sep 17 2009 - 17:41:56)                                                    

I2C:   ready
DRAM:  64 MB
*** Warning - bad CRC, using default environment
In:    serial
Out:   serial
Err:   serial
ARM Clock : 300000000 Hz
DDR Clock : 150000000 Hz
Net:   Ethernet PHY: GENERIC @ 0x00

Hit any key to stop autoboot:  0 
U-Boot > setenv serverip 172.**.**.2
U-Boot > setenv ipaddr 172.**.**.248
U-Boot > setenv bootfile uImage
U-Boot > setenv netmask 255.255.255.0
U-Boot > setenv bootcmd 'tftp 0xc0700000 uImage;bootm'
U-Boot > setenv bootargs console=ttyS2,115200n8 noinitrd rw ip=172.**.**.248:172.**.**.1:255.255.255.0 root=/dev/nfs nfsroot=172.**.**.2:/nfs nolock mem=32M
U-Boot > boot
Using  device
TFTP from server 172.**.**.2; our IP address is 172.**.**.248
Filename 'uImage'.
Load address: 0xc0700000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ###############################################################
done
Bytes transferred = 2315152 (235390 hex)
## Booting kernel from Legacy Image at c0700000 ...
   Image Name:   Arago/2.6.37-psp03.21.00.04.sdk/
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2315088 Bytes =  2.2 MB
   Load Address: c0008000
   Entry Point:  c0008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.37 (a0876316@bangdvsdkdev01) (gcc version 4.3.3 (GCC) ) #1 PREEMPT Fri Dec 23 11:12:57 IST 2011
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: DaVinci DA850/OMAP-L138/AM18x EVM
Memory policy: ECC disabled, Data cache writeback
DaVinci da850/omap-l138 variant 0x0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 8128
Kernel command line: console=ttyS2,115200n8 noinitrd rw ip=172.**.**.248:172.**.**.1:255.255.255.0 root=/dev/nfs nfsroot=172.**.**.2:/nfs nolock mem=32M
PID hash table entries: 128 (order: -3, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory: 32MB = 32MB total
Memory: 27540k/27540k available, 5228k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xff000000 - 0xffe00000   (  14 MB)
    vmalloc : 0xc2800000 - 0xfea00000   ( 962 MB)
    lowmem  : 0xc0000000 - 0xc2000000   (  32 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .init : 0xc0008000 - 0xc0032000   ( 168 kB)
      .text : 0xc0032000 - 0xc047e000   (4400 kB)
      .data : 0xc047e000 - 0xc04a8980   ( 171 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Preemptable hierarchical RCU implementation.
        RCU-based detection of stalled CPUs is disabled.
        Verbose stalled-CPUs detection is disabled.
NR_IRQS:245
Console: colour dummy device 80x30
Calibrating delay loop... 149.50 BogoMIPS (lpj=747520)
pid_max: default: 32768 minimum: 301
Security Framework initialized
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
DaVinci: 144 gpio irqs
regulator: core version 0.5
regulator: dummy: 
NET: Registered protocol family 16
WARNING: both McASP and McBSP are enabled, but they share pins.
        Only McASP will work. If you want McBSP support, disable McASP.
WARNING: both McASP and UART1_AFE are enabled, but they share pins.
        Disable one of them.
da850_evm_init: eHRPWM module 0 cannot be used since it is being used by MII interface
da850_evm_init: eHRPWM module1 outputA cannot be used since it is being used by LCD
da850_evm_init: eHRPWM module1 outputB cannot be used since it is being used by spi1
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
pca953x 1-0020: failed reading register
pca953x 1-0021: interrupt support not compiled in
regulator: VDCDC1: 3200 <--> 3300 mV at 3300 mV 
regulator: VDCDC2: 1750 <--> 3300 mV at 3300 mV 
regulator: VDCDC3: 950 <--> 1350 mV at 1200 mV 
regulator: LDO1: 1800 mV 
regulator: LDO2: 1150 <--> 1300 mV at 1200 mV 
i2c-gpio i2c-gpio.1: using pins 20 (SDA) and 21 (SCL)
Advanced Linux Sound Architecture Driver Version 1.0.23.
Bluetooth: Core ver 2.15
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Switching to clocksource timer0_1
musb-hdrc: version 6.0, host, debug=0
musb-hdrc musb-hdrc: dma type: dma-cppi41
Waiting for USB PHY clock good...
musb-hdrc musb-hdrc: MUSB HDRC host driver
musb-hdrc musb-hdrc: new USB bus registered, assigned bus number 1
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
musb-hdrc musb-hdrc: USB Host mode controller at fee00000 using DMA, IRQ 58
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
EMAC: MII PHY configured, RMII PHY will not be functional
McBSP:Probed McBSP1
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
msgmni has been set to 53
io scheduler noop registered (default)
da8xx_lcdc da8xx_lcdc.0: GLCD: Found Sharp_LK043T1DG01 panel
Console: switching to colour frame buffer device 60x34
Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x1c42000 (irq = 25) is a AR7
serial8250.0: ttyS1 at MMIO 0x1d0c000 (irq = 53) is a AR7
serial8250.0: ttyS2 at MMIO 0x1d0d000 (irq = 61) is a AR7
console [ttyS2] enabled
brd: module loaded
at24 1-0050: 32768 byte 24c256 EEPROM (writable)
ahci ahci: forcing PORTS_IMPL to 0x1
ahci ahci: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl platform mode
ahci ahci: flags: ncq sntf pm led clo only pmp pio slum part ccc 
scsi0 : ahci_platform
ata1: SATA max UDMA/133 mmio [mem 0x01e18000-0x01e19fff] port 0x100 irq 67
spi_davinci spi_davinci.1: DMA: supported
spi_davinci spi_davinci.1: DMA: RX channel: 18, TX channel: 19, event queue: 0
m25p80 spi1.0: m25p64 (8192 Kbytes)
Creating 6 MTD partitions on "m25p80":
0x000000000000-0x000000010000 : "UBL"
0x000000010000-0x000000090000 : "U-Boot"
0x000000090000-0x0000000a0000 : "U-Boot-Env"
0x0000000a0000-0x000000320000 : "Kernel"
0x000000320000-0x000000720000 : "Filesystem"
0x0000007f0000-0x000000800000 : "MAC-Address"
Read MAC addr from SPI Flash: 00:08:ee:03:d0:8f
spi_davinci spi_davinci.1: Controller at 0xfef0e000
davinci_mdio davinci_mdio.0: davinci mdio revision 1.5
davinci_mdio davinci_mdio.0: detected phy mask fffffffe
davinci_mdio.0: probed
davinci_mdio davinci_mdio.0: phy[0]: device 0:00, driver SMSC LAN8710/LAN8720
console [netcon0] enabled
netconsole: network logging started
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci ohci.0: DA8xx OHCI
ohci ohci.0: new USB bus registered, assigned bus number 2
Waiting for USB PHY clock good...
ohci ohci.0: irq 59, io mem 0x01e25000
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
input: gpio-keys-polled as /devices/platform/gpio-keys-polled.1/input/input0
input: TPS6507x Touchscreen as /devices/platform/i2c-gpio.1/i2c-1/1-0048/input/input1
ata1: SATA link down (SStatus 0 SControl 300)
omap_rtc omap_rtc: rtc core: registered omap_rtc as rtc0
omap_rtc: RTC power up reset detected
i2c /dev entries driver
watchdog watchdog: heartbeat 60 sec
Bluetooth: HCI UART driver ver 2.2
Bluetooth: HCI H4 protocol initialized
Bluetooth: HCILL protocol initialized
cpuidle: using governor ladder
cpuidle: using governor menu
davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
davinci_mmc davinci_mmc.1: Using DMA, 4-bit mode
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
1-0018 supply IOVDD not found, using dummy regulator
1-0018 supply DVDD not found, using dummy regulator
1-0018 supply AVDD not found, using dummy regulator
1-0018 supply DRVDD not found, using dummy regulator
asoc: tlv320aic3x-hifi <-> davinci-mcasp.0 mapping ok
ALSA device list:
  #0: DA850/OMAP-L138 EVM
nf_conntrack version 0.5.0 (430 buckets, 1720 max)
ip_tables: (C) 2000-2006 Netfilter Core Team
TCP cubic registered
NET: Registered protocol family 17
Bluetooth: L2CAP ver 2.15
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO (Voice Link) ver 0.6
Bluetooth: SCO socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bluetooth: BNEP filters: protocol multicast
Bluetooth: HIDP (Human Interface Emulation) ver 1.2
regulator_init_complete: incomplete constraints, leaving LDO2 on
regulator_init_complete: incomplete constraints, leaving LDO1 on
regulator_init_complete: incomplete constraints, leaving VDCDC3 on
regulator_init_complete: incomplete constraints, leaving VDCDC2 on
regulator_init_complete: incomplete constraints, leaving VDCDC1 on
omap_rtc omap_rtc: setting system clock to 2000-01-01 00:00:00 UTC (946684800)
davinci_mdio davinci_mdio.0: resetting idled controller
net eth0: attached PHY driver [SMSC LAN8710/LAN8720] (mii_bus:phy_addr=0:00, id=7c0f1)
IP-Config: Guessing netmask 255.255.0.0
IP-Config: Gateway not on directly connected network.
PHY: 0:00 - Link is Up - 100/Full
VFS: Mounted root (nfs filesystem) on device 0:13.
Freeing init memory: 168K
INIT: version 2.86 booting
Please wait: booting...
Starting udev
udevd (601): /proc/601/oom_adj is deprecated, please use /proc/601/oom_score_adj instead.
udev: starting version 141
Root filesystem already rw, not remounting
Caching udev devnodes
Populating dev cachemv: cannot rename '/tmp/devices': No such file or directory
NET: Registered protocol family 10
logger: mount: mount point /proc/bus/usb does not exist
ALSA: Restoring mixer settings...
NOT configuring network interfaces: / is an NFS mount
Fri Dec 23 16:04:00 UTC 2011
INIT: Entering runlevel: 5
Starting system message bus: dbus.
Starting Dropbear SSH server: dropbear.
Starting telnet daemon.
Starting network benchmark server: netserver.
Starting syslogd/klogd: done
Starting thttpd.
CMEMK module: built on Dec 23 2011 at 12:04:44
  Reference Linux version 2.6.37
  File /datalocal/DVSDK43_HPDL380G7/arago-tmp/work/da850-omapl138-evm-arago-linux-gnueabi/ti-linuxutils-1_2_26_02_05-r57d/linuxutils_2_26_02_05/packages/ti/c
allocated heap buffer 0xc3000000 of size 0x1200000
heap fallback enabled - will try heap if pool buffer is not available
cmemk initialized
DSPLINK Module (1.65.01.05_eng) created on Date: Dec 23 2011 Time: 12:07:46

 _____                    _____           _         _   
|  _  |___ ___ ___ ___   |  _  |___ ___  |_|___ ___| |_ 
|     |  _| .'| . | . |  |   __|  _| . | | | -_|  _|  _|
|__|__|_| |__,|_  |___|  |__|  |_| |___|_| |___|___|_|  
              |___|                    |___|            

Arago Project http://arago-project.org arago ttyS2

Arago 2011.06 arago ttyS2

arago login: root
root@arago:~# ls
root@arago:~# cd ..
root@arago:/home# ls
fpxshyy  root
root@arago:/home# cd fpxshyy
root@arago:/home/fpxshyy# ls
buf_set     buf_set.c   hello       helloworld  simple
root@arago:/home/fpxshyy# gdbserver 172.**.**.2:1000 ./buf_set
Process ./buf_set created; pid = 1038
Listening on port 1000
Remote debugging from host 172.**.**.2
OK, set successful!
stdin is unbuffered
buffer size is 1
file discriptor is 0
OK, change successful!
stdin is fully-buffered
buffer size is 1024
file discriptor is 0
Child exited with retcode = 15 
Child exited with status 21
GDBserver exiting

5.主机运行结果

root@ubuntu:/nfs# /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gdb ./buf_set
GNU gdb (Sourcery G++ Lite 2009q1-203) 6.8.50.20081022-cvs
Copyright (C) 2008 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-none-linux-gnueabi".
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>...
(gdb) b main
Breakpoint 1 at 0x8464: file simple_gdb.c, line 4.
(gdb) target remote 172.**.**.248:1000
Remote debugging using 172.**.**.248:1000

0x400cd7e0 in ?? () from /nfs/lib/ld-linux.so.3

(gdb) b main
Note: breakpoint 1 also set at pc 0x8464.

6.  c 程序

#include <stdio.h>
#define SIZE 1024                    
int main(void)
{
   char buf[SIZE];                  
   if(setvbuf(stdin, buf, _IONBF, SIZE)!=0)    
     {
       printf("error!\n");
       exit(1);                    
     }
   printf("OK, set successful!\n");
   printf("stdin is ");                  
   if(stdin->_flags & _IO_UNBUFFERED)  
      printf("unbuffered\n");
   else if(stdin->_flags & _IO_LINE_BUF)
      printf("line-buffered\n");
   else
      printf("fully-buffered\n");
   printf("buffer size is %d\n", stdin->_IO_buf_end - stdin->_IO_buf_base); 
    
   printf("file discriptor is %d\n", fileno(stdin));  
   if(setvbuf(stdin, buf, _IOFBF, SIZE)!=0)     
    
       printf("error!\n");
       exit(1);     

     }
   printf("OK, change successful!\n");
   printf("stdin is ");                     
   if(stdin->_flags & _IO_UNBUFFERED)  / 
      printf("unbuffered\n");
   else if(stdin->_flags & _IO_LINE_BUF)
      printf("line-buffered\n");
   else
      printf("fully-buffered\n");
   printf("buffer size is %d\n", stdin->_IO_buf_end - stdin->_IO_buf_base); 
    
   printf("file discriptor is %d\n", fileno(stdin));   
}

7 . c 程序编译   /opt/Code../arm-non..gcc  -g -o buf_set  buf_set.c

附件:

嵌入式GDB调试命令

下面在gdb下输入命令开始调试

a.输入list打印出要调试的程序
b.输入b 5,在第5行设置一个断点
c.输入c命令,程序开始执行(不能用r命令)
d.输入next,程序开始单步运行
e.再输入next,可以运行下一句代码

注:新浪一网友,谢谢啊

卦囱**



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值