On Fri, Dec 11, 2009 at 04:59:44PM +0100, Oleg Nesterov wrote:
> On 12/11, K.Prasad wrote:
> > Watchpoints (using DABR) through GDB can fail for many reasons....they
> > must ideally be set after the program has started execution - to enable
> > GDB know the size of the variable...else they would resort to
> > single-stepping to trap access to the target variable.
> 
> Yes. I straced gdb to be sure it really does PTRACE_SET_DEBUGREF to
> use the hardware watchpoint.
> 
> There is something strange though. gdb does PTRACE_SINGLESTEP and only
> then PTRACE_CONT after "watch xxx".
>

I haven't taken a good look at the testcase...although I suspect that
the use of PTRACE_SINGLESTEP vs PTRACE_SET_DEBUGREG during your trials
is due to the way "watch <var>" is being set.

For instance, here are two screenlogs taken from a PPC64 (Power5 box
running RHEL 5.3 2.6.18-128.el5). It can be seen that hw-breakpoints are
used only during the second-run of GDB vs single-stepping done in the
first...wondering if you used it in similar ways.

First run
-----------
[r...@p510 ~]# gdb prasad
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 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 "ppc64-redhat-linux-gnu"...
(gdb) watch b
Watchpoint 1: b <--------(Watchpoint vs Hardware watchpoint)
(gdb) r
Starting program: /root/prasad 

Prasad: sizeof(long): sizeof(b)=4
Watchpoint 1: b

Old value = 0
New value = 200
main () at a.c:17
17              i = 300;
(gdb) c


Second run
-----------
[r...@p510 ~]# gdb prasad
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 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 "ppc64-redhat-linux-gnu"...
(gdb) start
Breakpoint 1 at 0x100004bc: file a.c, line 14.
Starting program: /root/prasad 
main () at a.c:14
14              printf("\nPrasad: sizeof(long): sizeof(b)=%d\n",
sizeof(b));
(gdb) watch b
Hardware watchpoint 2: b <----------(uses DABR unlike the firstrun)
(gdb) q
The program is running.  Exit anyway? (y or n) y

Reply via email to