Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2098101
  • 博文数量: 333
  • 博客积分: 10161
  • 博客等级: 上将
  • 技术积分: 5238
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-19 08:59
文章分类

全部博文(333)

文章存档

2017年(10)

2014年(2)

2013年(57)

2012年(64)

2011年(76)

2010年(84)

2009年(3)

2008年(37)

分类: LINUX

2011-08-24 00:55:26

我没有使用arm-elf-gdb 使用gdb替代,也可以用,目前skyeye-1.2.9暂时不支持gdb调试,但是1.2.8及以前版本是支持的,因此本文以1.2.8为例说明

要使用SkeyEye调试功能,可以在执行的时候加入-d参数,例如: 
$skyeye -e hello -d 
skyeye会提示
debugmode= 1, filename = skyeye.conf, server TCP port is 12345
这时就在本机的12345端口开启了gdb服务 
这时在当前目录重新开一个终端程序
$arm-elf-gdb hello
(gdb) target remote 127.0.0.1:12345
Remote debugging using 127.0.0.1:12345  
hello () at hello.c:23
23        }
(gdb) 
同时原skeyeye段给出提示
Remote debugging using host:12345
这就说明已经连接上服务,可以开始调试了




(gdb) help                   #--获取帮助信息,呵呵,这个最重要了
List of classes of commands:

aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands

Type "help" followed by a class name for a list of commands in that class.
Type "help all" for the list of all commands.
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.

下面列出常用的调试指令:

list ---列出源代码

如果连续输入,则会依次列出源代码
如果想看23行的上下文,可以使用list 23



单步执行
step 进入子函数的单步--如果在子函数中想要退出该子函数,可以使用finish命令
next 不进入子函数的单步


查看变量
print
(gdb) print hellostr   -- 查看字符串
$2 = 0x1000078 "helloworld"
(gdb) print timeout    --查看int变量
$3 = 1
(gdb) print hello       --查看函数信息
$4 = {void (void)} 0x1000020


修改变量的值
1。显示变量类型
(gdb) ptype timeout 
type = int
(gdb) whatis timeout 
type = int
2。修改变量的值
(gdb) print timeout 
$5 = 2
(gdb) set timeout=5
(gdb) print timeout 
$6 = 5




设置断点
break
1。break 行数
(gdb) b 18
Breakpoint 4 at 0x1000048: file hello.c, line 18.
2。函数断点
(gdb) break hello
Breakpoint 2 at 0x100002c: file hello.c, line 13.
3。条件断点
(gdb) break if timeout=3
Breakpoint 1 at 0x1000044: file hello.c, line 17.
查看断点信息
(gdb) info b
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x01000044 in hello at hello.c:17
    stop only if timeout=3
2       breakpoint     keep y   0x0100002c in hello at hello.c:13
3       breakpoint     keep y   0x01000044 in hello at hello.c:17
4       breakpoint     keep y   0x01000048 in hello at hello.c:18


监视变量的值
watch 变量名   当变量的值发生变化时,程序会中断运行
(gdb) watch timeout 
Watchpoint 5: timeout
例如,设置检测timeout后,继续执行到while(++timeout != BOGO_MIPS);单步执行
(gdb) s
Watchpoint 5: timeout

Old value = 1
New value = 2
0x0100004c in hello () at hello.c:18
18            while(++timeout != BOGO_MIPS);
GDB会中断程序,并将变量的变化显示出来
查看监测信息:
使用info watch 查看
(gdb) info watch
Num     Type           Disp Enb Address    What
5       watchpoint     keep y              timeout
    breakpoint already hit 1 time
可见监测点也是断点的一种


断点的管理
1。查看断点信息
Num     Type           Disp Enb Address    What
5       watchpoint     keep y              timeout
    breakpoint already hit 1 time
6       breakpoint     keep y   0x0100002c in hello at hello.c:13
7       breakpoint     keep y   0x01000048 in hello at hello.c:18
8       breakpoint     keep y   0x0100004c in hello at hello.c:18
    stop only if timeout=4

2。删除断点
如果要删除所有断点,可使用
(gdb) delete breakpoints 
删除所有断点吗? (y or n) y
(gdb) info breakpoints 
No breakpoints or watchpoints.
如果要删除某一个断点,可使用
(gdb) delete breakpoints 6
(gdb) info b
Num     Type           Disp Enb Address    What
5       watchpoint     keep y              timeout
    breakpoint already hit 1 time
7       breakpoint     keep y   0x01000048 in hello at hello.c:18
8       breakpoint     keep y   0x0100004c in hello at hello.c:18
    stop only if timeout=4

3。禁止某个断点
(gdb) info b
Num     Type           Disp Enb Address    What
5       watchpoint     keep y              timeout
    breakpoint already hit 1 time
7       breakpoint     keep y   0x01000048 in hello at hello.c:18
8       breakpoint     keep y   0x0100004c in hello at hello.c:18
    stop only if timeout=4
(gdb) disable b 5
(gdb) info b
Num     Type           Disp Enb Address    What
5       watchpoint     keep n              timeout
    breakpoint already hit 1 time
7       breakpoint     keep y   0x01000048 in hello at hello.c:18
8       breakpoint     keep y   0x0100004c in hello at hello.c:18
    stop only if timeout=4
(gdb) 
4。允许断点
(gdb) enable b 5
(gdb) info b
Num     Type           Disp Enb Address    What
5       watchpoint     keep y              timeout
    breakpoint already hit 1 time
7       breakpoint     keep y   0x01000048 in hello at hello.c:18
8       breakpoint     keep y   0x0100004c in hello at hello.c:18
    stop only if timeout=4
(gdb)

阅读(2089) | 评论(0) | 转发(0) |
0

上一篇:Skyeye安装测试

下一篇:arm-elf-gdb的安装

给主人留下些什么吧!~~