[PATCH]: Make Linux use the new unified x86 watchpoint support

Mark Salter msalter@redhat.com
Thu Mar 29 12:03:00 GMT 2001


>>>>> Eli Zaretskii writes:

> On Wed, 28 Mar 2001, Mark Salter wrote:

>> > Is there any reason that you can't define HAVE_NONSTEPPABLE_WATCHPOINT 
>> > (or some of its other brethren; see infrun.c) and get GDB to DTRT for 
>> > your target?
>> 
>> Hmm. So, what are the meanings of HAVE_NONSTEPPABLE_WATCHPOINT and
>> HAVE_STEPPABLE_WATCHPOINT? It seems if you have one, you don't have
>> the other, but infrun.c doesn't see it that way.

> IMVHO, infrun.c is somewhat messy in this area; see the comments around 
> that code.  A target should have either of these two or none, but not 
> both.  However, in practice, if you don't define any of these constants, 
> it automatically gets defined to zero by infrun.c (see the beginning of 
> the file), so the compiler will simply optimize the wrong if clauses out 
> of existence when you build GDB.

I looked at that a little further and it seems that if one of those is
defined, then GDB will step the target. It looks like one of those
should be defined iff GDB needs to step past the insn causing the
watchpoint. That is the case for architectures where the watchpoint
is triggered before the insn executes. On the architecture I'm working
with, the insn executes before the watchpoint triggers, so GDB doesn't
need to step.

>> int foo = 3;
>> 
>> main()
>> {
>> printf("%d\n", foo);
>> }
> [...]
>> If I define HAVE_NONSTEPPABLE_WATCHPOINT, I get:
>> 
>> (gdb) c
>> Continuing.
>> Hardware read watchpoint 1: foo
>> 
>> Value = 3
>> 0xa0020c4c in printf () at ....
>> (gdb)

> This looks like what you should get.

>> Note that gdb stopped inside printf. This seems suboptimal but at least
>> there's not error.

> Why suboptimal?  Does disassembly show that the debuggee stopped on a 
> wrong insn?  That is, do you indeed see an instruction before 0x0020c4c 
> which accesses the value of `foo'?  Can you show the instructions near 
> this point?

0xa0020024 <main+24>:	ldr	r1, [r3]
0xa0020028 <main+28>:	bl	0xa0020c4c <printf>

So here, the 'ldr' insn reads the foo variable, then the bl insn calls printf.
The PC is at 0xa0020028 when the wathcpoint is reported to GDB. If I don't
define HAVE_NONSTEPPABLE_WATCHPOINT, then gdb reports the read error and the
target PC is left at 0xa0020028. If I define HAVE_NONSTEPPABLE_WATCHPOINT,
then GDB steps the target which causes it to branch into printf. No read
error is reported, but the PC is in printf.

--Mark



More information about the Gdb-patches mailing list