Chinaunix

标题: 大家帮忙看看我的gdb测试. [打印本页]

作者: kornrock    时间: 2007-05-14 19:50
标题: 大家帮忙看看我的gdb测试.
[root@test kornrock]# gdb abc
GNU gdb Red Hat Linux (6.5-16.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/i686/nosegneg/libthread_db.so.1".

(gdb) list
1       #include <stdio.h>
2       #include <string.h>
3       #include <stdlib.h>
4
5       int main()
6       {
7               int i=1;
8               int a=10;
9
10                      a=a+10;
(gdb)
11      }
(gdb) watch a
No symbol "a" in current context.
请问这是什么问题?
作者: yangprc    时间: 2007-05-14 20:36
今天的第六个沙发
作者: MMMIX    时间: 2007-05-14 20:40
原帖由 kornrock 于 2007-5-14 19:50 发表
[root@test kornrock]# gdb abc
GNU gdb Red Hat Linux (6.5-16.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
...

你首先要进入 main 函数,才可能看到这个 a,就是这么回事。
作者: cjaizss    时间: 2007-05-14 20:54
a不是全局变量,不运行,则a是看不到的。
作者: baohuaihuai    时间: 2007-05-14 21:51
顶楼上几位.
作者: kornrock    时间: 2007-05-15 09:56
这个明白了,谢谢各位。还有个问题。
[root@test kornrock]# gdb abc


(gdb) list
1       #include <stdio.h>
2       #include <string.h>
3       #include <stdlib.h>
4
5       int main()
6       {
7               int i=1;
8               int a=10;
9               a=a+10;
10      }
(gdb)
Line number 11 out of range; abc.c has 10 lines.
(gdb) break 9
Breakpoint 1 at 0x8048343: file abc.c, line 9.
(gdb) run
Starting program: /home/kornrock/abc

Breakpoint 1, main () at abc.c:9
9               a=a+10;
(gdb) watch a
Hardware watchpoint 2: a
(gdb) next
10      }
(gdb)
为什么next以后没有显示a变量的值呢?
作者: emacsnw    时间: 2007-05-15 14:16
原帖由 kornrock 于 2007-5-14 17:56 发表
这个明白了,谢谢各位。还有个问题。
[root@test kornrock]# gdb abc


(gdb) list
1       #include <stdio.h>
2       #include <string.h>
3       #include <stdlib.h>
4
5       ...


应该可以打印类似下面的信息:
Hardware watchpoint 2: a

Old value = 10
New value = 20
作者: cjaizss    时间: 2007-05-15 14:20
原帖由 emacsnw 于 2007-5-15 14:16 发表


应该可以打印类似下面的信息:
Hardware watchpoint 2: a

Old value = 10
New value = 20

呵呵,这个问题我昨天也问过了,我也没搞明白
作者: kornrock    时间: 2007-05-15 14:58
但是break 7
      run
      watch a
      next   
      next    //显示line 8中 a 的变化
      next   //显示line 9中  a的变化
或者break 8
      run
      watch a
      next
      next//显示line 9中a的变化.
好像是要显示将断点设在变量所在行的上一行才行.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2