Re: [PATCH] PR threads/10729: x86 hw watchpoints and non-stop mode

Pedro Alves
2011-12-14T17:35:08Z

On Wednesday 14 December 2011 17:22:27, Pedro Alves wrote:
> > On Tue, 13 Dec 2011 17:26:03 +0100, Pedro Alves wrote:
> > > +amd64_linux_prepare_to_resume (struct lwp_info *lwp)
> > > {
> > > - struct lwp_info *lp;
> > > + int clear_status = 0;
> > >
> > > - ALL_LWPS (lp)
> > > + if (lwp->arch_private->debug_registers_changed)
> > > {
> > > - unsigned long value;
> > > -
> > > - value = amd64_linux_dr_get (lp->ptid, DR_STATUS);
> > > - value &= ~mask;
> > > - amd64_linux_dr_set (lp->ptid, DR_STATUS, value);
> > > + struct i386_debug_reg_state *state = i386_debug_reg_state ();
> > > + int i;
> > > +
> > > + for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++)
> > > + if (state->dr_ref_count[i] > 0)
> > > + {
> > > + amd64_linux_dr_set (lwp->ptid, i, state->dr_mirror[i]);
> >
> > FYI this way it will leave non-zero DR_FIRSTADDR...DR_LASTADDR after detaching
> > from the inferior. This is not a bug, just that it may look as a sort of
> > regression. I do not think a fix - clearing them - is required.
>
> Agreed. But there's actually a related bug here, that I had thought
> of fixing, then forgot. GDBserver has this bug too; I'll fix it in a bit.

Like below. Now applied.

> We need to call prepare_to_resume just before detaching, to clear
> the previously active debug registers in DR_CONTROL, otherwise, the
> inferior dies with SIGTRAP just after detaching.
>
> That is:
>
> (gdb) watch j
> or
> (gdb) hbreak foo
> (gdb) si
> watchpoints inserted
> (gdb) delete
> *deletes the watchpoints from global mirror, but doesn't update the threads' copies.*
> (gdb) detach
> *inferior trips on old watchpoints -> SIGTRAP death *
>

gdb/gdbserver/
2011-12-14 Pedro Alves <pedro@codesourcery.com>

* linux-low.c (linux_detach_one_lwp): Call
the_low_target.prepare_to_resume before detaching.

---
gdb/gdbserver/linux-low.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 8afbc8b..43d88fa 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -918,6 +918,8 @@ linux_detach_one_lwp (struct inferior_list_entry *entry, void *args)
get_lwp_thread (lwp));

/* Finally, let it resume. */
+ if (the_low_target.prepare_to_resume != NULL)
+ the_low_target.prepare_to_resume (lwp);
ptrace (PTRACE_DETACH, lwpid_of (lwp), 0, 0);

delete_lwp (lwp);