public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Question about the watchpoint
@ 2011-05-26  8:00 Qian Hao
  0 siblings, 0 replies; only message in thread
From: Qian Hao @ 2011-05-26  8:00 UTC (permalink / raw)
  To: gdb

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.


-- 
此致
        敬礼!

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-26  8:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26  8:00 Question about the watchpoint Qian Hao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).