Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217492
  • 博文数量: 88
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 555
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-03 13:08
个人简介

失意高调,得意低调

文章分类

全部博文(88)

文章存档

2021年(3)

2020年(2)

2018年(2)

2017年(3)

2016年(6)

2015年(19)

2014年(32)

2013年(21)

我的朋友

分类: LINUX

2015-05-15 13:58:18

一,gdb直接在嵌入式上运行
gdb hello
1. 默认设置下,在调试多进程程序时GDB只会调试主进程。但是GDB(>V7.0)支持多进程的分别以及同时调试,换句话说,GDB可以同时调试多个程序。只需要设置follow-fork-mode(默认值:parent)和detach-on-fork(默认值:on)即可。
      follow-fork-mode  detach-on-fork   说明
parent                   on               只调试主进程(GDB默认)
child                     on               只调试子进程
parent                   off              同时调试两个进程,gdb跟主进程,子进程block在fork位置
child                     off              同时调试两个进程,gdb跟子进程,主进程block在fork位置
   设置方法:set follow-fork-mode [parent|child]   set detach-on-fork [on|off]

   查询正在调试的进程:info inferiors
   切换调试的进程: inferior
   添加新的调试进程: add-inferior [-copies n] [-exec executable] ,可以用file executable来分配给inferior可执行文件。
   其他:remove-inferiors infno, detach inferior

2. GDB默认支持调试多线程,跟主线程,子线程block在create thread。
   查询线程:info threads
二,gdbserver在嵌入式运行,gdb客服端运行在pc
1、交叉编译,带参数-gstabs 或 -g 加入调试信息。
   假设要调试的程序为hello.c。
   #arm-linux-gcc -g hello.c -o hello


2、在Target Board开启gdbserver
   #gdbserver  :2345 hello   (我的host-ip是192.168.0.178)
   gdbserver开始监听2345端口(你也可以设其他的值),然后启动hello,你会看到“Process test created:pid=88   ”


3、回到Host端
   #export PATH=$PATH:/home/cby/arm-gdb/bin(arm-linux-gdb的路径)
   #arm-linux-gdb hello
   最后一行显示:This GDB was configured as “--host=i686-pc-linux-gnu,--target=arm-linux”...
   说明此gdb在X86的Host上运行,但是调试目标是ARM代码。
   (gdb)target remote :2345    (我的target-board-ip is 192.168.0.177)


注意:你的端口号必须与gdbserver开启的端口号一致,这样才能进行通信。
   建立链接后,就可以进行调试了。调试在Host端,跟gdb调试方法相同。注意的是要用“c”来执行命令,不能用“r”   。因为程序已经在Target Board上面由gdbserver启动了。


   结果输出是在Target Board端,用超级终端查看



今天客户使用gdb调试程序的时候出现问题。先是“no debugging symbols found",google下发现是因为程序使用strip去掉了debug信息。

然后gdb显示"Program received signal SIG32, Real-time event 32."

继续google后,发现是因为用到的lib库被strip掉了。但是可以使用下面折中的方法:

在dbg prompt后键入"handle SIG32 pass noprint nostop"即可。


pc端使用gdb,嵌入式板子使用gdbserver,因为板子程序用到SIGALARM,每秒gdbserver都会被中断,请问gdbserver如何屏蔽这个中断以至于不影响正常调试?
handle SIGALARM nostop noprint

handle SIG32 nostop
handle SIG33 nostop
handle SIG32 pass noprint nostop
handle SIG33 pass noprint nostop

*********************************
编译:
CONFIG_DEBUG=y
+= -g -O0
gdb /axel core_dump
ulimit -c

编译:no strip
 -O0 :Advanced configuration options (for developers) --> Target Options 

[Inferior 1 (process 124406) exited normally]
set follow-fork-mode child

Reading symbols from ./xbt_tracker...(no debugging symbols found)...done.
a.out


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