如何使用步骤而不是继续在GDB中调用watchpoint

时间:2017-05-10 07:37:00

标签: c++ c gdb

我一直在使用以下步骤来监视GDB中的变量,它对我很好:

 1. set some breakpoints
 2. run
 3. watch a variable
 4. continue

但是,在此gdb youtube tutorial (start from 12:10)中,作者使用步骤而不是继续调用观察点消息,这种情况我无法重现。

示例代码是从教程中复制的:

int main(int argc, char *argv[])
{
  int sum, i;
  char string[120];

  sum=0;
  strcpy(string, "Hello!");

  for(i=0;i<10;i++) {
    sum+=i;
    sum=square(sum, i);
  }
  printf("sum=%d\n", sum);
  return 0;
}

int square(int big, int temp)
{
  int i;
  i=big;
  if(big>10) i=i%10;
  return(i*temp);
}

这是我尝试通过&#34;步骤&#34;来调用watchpoint的步骤。但是失败了(也就是说,即使我设置了观察点,但是&#34;旧值=&#34;以及&#34;新值=&#34;消息未显示):

 1. start
 2. step to main
 3. watch i
 4. step several times but none of watchpoint message was shown

我需要做些什么才能让它与#34;步骤&#34;?谢谢。

这是我的工作环境:

  

gdb版本:7.11.1
  操作系统:Win10中VMware Player 12上的Ubuntu 16.04   

已编辑:
1。这是我用过的代码&#34;继续&#34;并且工作得很好。

syuan@ubuntu:~/Downloads$ gdb test

(gdb) b main
Breakpoint 1 at 0x4005ae: file test.c, line 8.

(gdb) run
Starting program: /home/syuan/Downloads/test 

Breakpoint 1, main (argc=1, argv=0x7fffffffde48) at test.c:8
8   {
(gdb) watch i
Hardware watchpoint 2: i
(gdb) c
Continuing.

Hardware watchpoint 2: i

Old value = 0
New value = 1
0x0000000000400615 in main (argc=1, argv=0x7fffffffde48) at test.c:15
15    for(i=0;i<10;i++) {
(gdb) c
Continuing.

Hardware watchpoint 2: i

Old value = 1
New value = 2
0x0000000000400615 in main (argc=1, argv=0x7fffffffde48) at test.c:15
15    for(i=0;i<10;i++) {
(gdb) c
Continuing.

Hardware watchpoint 2: i

Old value = 2
New value = 3
0x0000000000400615 in main (argc=1, argv=0x7fffffffde48) at test.c:15


2。这是我使用的代码&#34; step&#34;或&#34; next&#34;但没有成功。

syuan@ubuntu:~/Downloads$ gdb test

(gdb) b main
Breakpoint 1 at 0x4005ae: file test.c, line 8.
(gdb) start
Temporary breakpoint 2 at 0x4005ae: file test.c, line 8.
Starting program: /home/syuan/Downloads/test 

Breakpoint 1, main (argc=1, argv=0x7fffffffde48) at test.c:8
8   {
(gdb) step
12    sum=0;
(gdb) watch i
Hardware watchpoint 3: i
(gdb) step
13    strcpy(string, "Hello!");
(gdb) step
15    for(i=0;i<10;i++) {
(gdb) step
16      sum+=i;
(gdb) step
17      sum=square(sum, i);
(gdb) step
square (big=0, temp=0) at test.c:26
26    i=big;
(gdb) step
27    if(big>10) i=i%10;
(gdb) step
28    return(i*temp);
(gdb) step
29  }
(gdb) step
main (argc=1, argv=0x7fffffffde48) at test.c:15
15    for(i=0;i<10;i++) {
(gdb) step
16      sum+=i;
(gdb) step
17      sum=square(sum, i);
(gdb) step
square (big=1, temp=1) at test.c:26
26    i=big;
(gdb) step
27    if(big>10) i=i%10;
(gdb) step
28    return(i*temp);
(gdb) step
29  }
(gdb) step
main (argc=1, argv=0x7fffffffde48) at test.c:15
15    for(i=0;i<10;i++) {
(gdb) step
16      sum+=i;
(gdb) step
17      sum=square(sum, i);
(gdb) step
square (big=3, temp=2) at test.c:26
26    i=big;
(gdb) step
27    if(big>10) i=i%10;
(gdb) step
28    return(i*temp);
(gdb) step
29  }
(gdb) step
main (argc=1, argv=0x7fffffffde48) at test.c:15
15    for(i=0;i<10;i++) {
(gdb) next
16      sum+=i;
(gdb) next
17      sum=square(sum, i);
(gdb) next
15    for(i=0;i<10;i++) {
(gdb) next
16      sum+=i;
(gdb) next
17      sum=square(sum, i);
(gdb) next
15    for(i=0;i<10;i++) {
(gdb) next
16      sum+=i;
(gdb) info watchpoint
Num     Type           Disp Enb Address            What
3       hw watchpoint  keep y                      i


再次编辑

我在gdb 7.7.1的在线gdb工具,gdb 7.11.1的linux服务器和运行Linux作为HOST OS的PC上进行了测试。所有这些都有效,这导致假设它可能是VM上的问题,但这需要更多验证。

0 个答案:

没有答案