如何使用“手表"?广发银行? [英] How can I use "watch" GDB?

查看:15
本文介绍了如何使用“手表"?广发银行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过命令watch a"来观察int a"的变化.但是程序并没有停止,当它变为 12 时.为什么?

I tried to watch the change of the "int a" by the command "watch a". However, the program does not stop, when it changes to 12. Why?

 /* FILE: test.c */
 #include <stdio.h>
 #include <stdlib.h>

 int main(int argc, char** argv){
  printf("Hello world
");

  int a = 12;
  a = 10;                                                                                                                                                                      
  return 0; 
 }

推荐答案

指定您的平台、GDB 版本以及您使用的 GDB 命令的确切顺序可能会有所帮助.

It may help to specify your platform, version of GDB, and exact sequence of GDB commands you used.

这是我看到的(GDB 似乎工作得很好):

Here is what I see (GDB appears to work just fine):

$ gcc -g test.c

$ gdb a.out
GNU gdb (GDB) 6.8.50.20090430-cvs
Copyright (C) 2009 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 "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) list
1       #include <stdio.h>
2       #include <stdlib.h>
3
4       int main(int argc, char** argv){
5         printf("Hello world
");
6
7         int a = 12;
8         a = 10;                                                                                                                                                                      
9         return 0; 
10      }
11
(gdb) b 5
Breakpoint 1 at 0x4004a7: file test.c, line 5.
(gdb) r

Breakpoint 1, main (argc=1, argv=0x7fffffffdb28) at test.c:5
5         printf("Hello world
");
(gdb) watch a
Hardware watchpoint 2: a
(gdb) c
Hello world
Hardware watchpoint 2: a

Old value = 0
New value = 12
main (argc=1, argv=0x7fffffffdb28) at test.c:8
8         a = 10;                                                                                                                                                                      
(gdb) c
Hardware watchpoint 2: a

Old value = 12
New value = 10
main (argc=1, argv=0x7fffffffdb28) at test.c:9
9         return 0; 
(gdb) c

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x00007ffff7ab3033 in exit () from /lib/libc.so.6
(gdb) c

Program exited normally.
(gdb) q

这篇关于如何使用“手表"?广发银行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆