This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question about the watchpoint


Hello everyone,
I am new to use gdb. I have a question about the watchpoint. For the
following program:

#include <stdio.h>
void main(const char *name)
{
int a;
a=1;
a=2;
printf("%d.\n",a);
}

Reading symbols from /home/yorua007/tmp/static-library/test...done.
(gdb) b main
Breakpoint 1 at 0x80483ed: file test.c, line 5.
(gdb) r
Starting program: /home/yorua007/tmp/static-library/test

Breakpoint 1, main (name=0x1 <Address 0x1 out of bounds>) at test.c:5
5       a=1;
(gdb) p a
$1 = -1208205324
(gdb) watch a
Hardware watchpoint 2: a
(gdb) c
Continuing.
Hardware watchpoint 2: a

Old value = -1208205324
New value = 2
main (name=0x1 <Address 0x1 out of bounds>) at test.c:7
7       printf("%d.\n",a);
(gdb)

You see that the program did not break when "a" changed from
-1208205324 to 1. It seems to relate with the hardware watchpoint.
When I configured to use the software watchpoint:

(gdb) set can-use-hw-watchpoint 0
(gdb) r
Starting program: /home/yorua007/tmp/static-library/test

Breakpoint 1, main (name=0x1 <Address 0x1 out of bounds>) at test.c:5
5       a=1;
(gdb) watch a
Watchpoint 3: a
(gdb) c
Continuing.
Watchpoint 3: a

Old value = -1208205324
New value = 1
main (name=0x1 <Address 0x1 out of bounds>) at test.c:6
6       a=2;
(gdb)

The program broke when "a" changed to 1. Could someone explain the
differences between the hardware and software watchpints ?

Besides this, another question about the watchpoint is that:
I have a program linked with a static library. In the static library,
there is a global variable(for example gl_a). After reading symbols
from the program,
(gdb) p gl_a
$1 = 1
(gdb) watch gl_a
Hardware watchpoint 1: gl_a
(gdb) r

The program executed without any break. But the value of "gl_a" did
changed(to 0) during the execution. When I set a breakpoint somewhere
in the program
before "gl_a" had changed, the program stopped there, and I made it
continue to execute, the program stopped where the value of "gl_a"
changed. I could not figure it out why.


-- 
此致
        敬礼!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]