public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [RFA/commit] arm-tdep.c: Do not single-step after hitting a watchpoint
@ 2014-09-29 18:23 Peter Maydell
  2014-09-29 22:15 ` Pedro Alves
  2014-09-30  8:57 ` Will Deacon
  0 siblings, 2 replies; 32+ messages in thread
From: Peter Maydell @ 2014-09-29 18:23 UTC (permalink / raw)
  To: Joel Brobecker
  Cc: Marcus Shawcroft, Terry.Guo, Marcus Shawcroft, lgustavo, yao,
	gdb-patches, Will Deacon,
	gareth@blacksphere.co.nz >> Gareth, McMullin

Joel Brobecker wrote:
> I have been trying to understand the various contributions, and
> I admit I am still not quite sure...
>
> Does it look like the patch I proposed is correct? It seems to be
> supported by Terry Guo's experiments as well...

Note that the ARMv7 architecture allows watchpoints to
be implemented as *asynchronous*, in which case what
you will see is that you take a watchpoint exception
but it may not fire until after the instruction that
triggers the watchpoint and possibly several following
instructions have all finished execution. This may be
what you are seeing in your hardware tests.

For *synchronous* watchpoints, the behaviour is that the
CPU stops *before* execution of the instruction which
triggers the fault, and the memory access does not take
place. This is pretty clearly described in the ARM ARM
(see DDI0406C.c section C3.4.4 "Synchronous and asynchronous
Watchpoint debug events" and the referenced "Effects of
data-aborted instructions" section).

For ARMv8 (so including all AArch64 CPUs) watchpoints must
be synchronous.

QEMU's built in gdbstub was incorrectly not implementing
synchronous watchpoints (ie it was halting after the
execution of the offending insn, not before). This is fixed
by the QEMU patch referenced earlier, and with that patch
QEMU and GDB interoperate correctly (on ARM and also on
other architectures which have the "stop before insn"
watchpoint semantics).

GDB should continue to set have_nonsteppable_watchpoint
for ARM architectures, indicating:
 * watchpoints fire before the insn executes
 * you need to disable the watchpoint to successfully
   singlestep the insn
as this is correct for synchronous watchpoints.

If you have h/w with asynchronous watchpoints then there
really isn't much you can do about stopping in the
right place. Ideally I guess gdb would not do a step
in that case, but I don't think it has access to
enough info about the target CPU to know this (the
kernel does get this info in the DBGDSCR.MOE register
field, which is different for synchronous and
asynchronous watchpoint events).

thanks
-- PMM

^ permalink raw reply	[flat|nested] 32+ messages in thread
* [RFA/commit] arm-tdep.c: Do not single-step after hitting a watchpoint.
@ 2014-09-15 13:01 Joel Brobecker
  2014-09-16 11:12 ` Yao Qi
  0 siblings, 1 reply; 32+ messages in thread
From: Joel Brobecker @ 2014-09-15 13:01 UTC (permalink / raw)
  To: gdb-patches

Hello!

Re: question about ARM watchpoints
    https://www.sourceware.org/ml/gdb/2014-09/msg00000.html

This patch fixes an issue with watchpoints on ARM targets, where
the debugger stops 2 instructions after the instruction causing
the watchpoint. GDB is expected to stop at the next instruction.

The problem is caused by the fact that GDB does an extra single-step
after receiving the watchpoint notification, because the
have_nonsteppable_watchpoint gdbarch attribute is set for ARM
targets. Our experiments indicate that this is incorrect, at
least for the versions of ARM that we tested on (ARMv7). We tried
to get confirmation of this through the ARM documentation, but
did not manage to get a clear answer. So, in light of evidence
that the current code is wrong for some versions of ARM, and
with the lack of evidence regarding the versions of ARM we could
not test on, this patch simply unsets this gdbarch attribute
for all versions of ARM.  The plan is to refine this later on
if/when we find that some systems behave differently.

gdb/ChangeLog:

        * arm-tdep.c (arm_gdbarch_init): Remove call to
        set_gdbarch_have_nonsteppable_watchpoint.

Unless there are comments, I will commit the patch in a week.

Thank you!

---
 gdb/arm-tdep.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index f9feb52..990c4ad 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -10446,9 +10446,6 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (tdep->arm_abi == ARM_ABI_AUTO)
     tdep->arm_abi = ARM_ABI_APCS;
 
-  /* Watchpoints are not steppable.  */
-  set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
-
   /* We used to default to FPA for generic ARM, but almost nobody
      uses that now, and we now provide a way for the user to force
      the model.  So default to the most useful variant.  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2014-09-30 14:50 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-29 18:23 [RFA/commit] arm-tdep.c: Do not single-step after hitting a watchpoint Peter Maydell
2014-09-29 22:15 ` Pedro Alves
2014-09-29 22:54   ` Peter Maydell
2014-09-30  9:08     ` Pedro Alves
2014-09-30  9:18       ` Will Deacon
2014-09-30 10:07         ` Pedro Alves
2014-09-30 10:18           ` Peter Maydell
2014-09-30 10:38             ` Pedro Alves
2014-09-30 10:01       ` Peter Maydell
2014-09-30 10:34         ` Pedro Alves
2014-09-30 12:54           ` Pedro Alves
2014-09-30 13:50             ` Joel Brobecker
2014-09-30 14:11               ` Pedro Alves
2014-09-30 14:26                 ` Joel Brobecker
2014-09-30 14:50                   ` Peter Maydell
2014-09-30  8:57 ` Will Deacon
2014-09-30  9:04   ` Will Deacon
2014-09-30  9:14   ` Pedro Alves
2014-09-30  9:24     ` Will Deacon
  -- strict thread matches above, loose matches on Subject: below --
2014-09-15 13:01 Joel Brobecker
2014-09-16 11:12 ` Yao Qi
2014-09-16 11:59   ` Joel Brobecker
2014-09-16 12:05     ` Luis Machado
2014-09-16 12:48       ` Joel Brobecker
2014-09-16 13:09         ` Luis Machado
2014-09-16 15:21           ` Pedro Alves
2014-09-18 11:40             ` Marcus Shawcroft
2014-09-19 17:31               ` Pedro Alves
2014-09-29 17:51                 ` Joel Brobecker
2014-09-29 17:57                   ` Luis Machado
2014-09-29 21:04                   ` Pedro Alves
2014-09-30  8:54                     ` Will Deacon

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).