手表不会停在指定地址

awatch does not stop on specified address

我了解到当表达式为 read/written 时,GDB 中的 awatch 命令会中断。但是,为什么当我将 awatch 命令设置为我的结构指针的地址时,它只停止了一次。下面是我的 GDB 的屏幕截图和代码片段。请指教。谢谢。

Testing.c

College_Record *college = NULL;
college = malloc(sizeof(College_Record));
printf("college %p\n", college);
free(college);
printf("college %p\n", college);
college = NULL;
printf("college %p\n", college);

printf("***************************\n");
printf("\tDONE OKAY\n");
printf("***************************\n");

return 0;

Testing.h

  typedef struct {
    int college_id;
    char school[20];
} College_Record;

这是一个示例程序:

struct college {
    int x;
    int y;
};

struct college college_glob;

struct college *college;

void
setwatch(void)
{

    college = &college_glob;
}

void
brkgdb(void)
{
}

int
main(void)
{

    setwatch();
    brkgdb();

    return college_glob.x;
}

这是 gdb 会话:

> gdb /tmp/watch
GNU gdb (GDB) Fedora 7.9.1-19.fc22
Copyright (C) 2015 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-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /tmp/watch...done.
(gdb) b brkgdb
Breakpoint 1 at 0x40050c: file /tmp/watch.c, line 20.
(gdb) run
Starting program: /tmp/watch 

Breakpoint 1, brkgdb () at /tmp/watch.c:20
20  }
(gdb) awatch *college
Hardware access (read/write) watchpoint 2: *college
(gdb) c
Continuing.
Hardware access (read/write) watchpoint 2: *college

Value = {x = 0, y = 0}
Hardware access (read/write) watchpoint 2: *college

Value = {x = 0, y = 0}
main () at /tmp/watch.c:30
30  }
(gdb) list
25  
26      setwatch();
27      brkgdb();
28  
29      return college_glob.x;
30  }
(gdb) q
A debugging session is active.

    Inferior 1 [process 15761] will be killed.

Quit anyway? (y or n) y