Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: pedromfc@linux.ibm.com (Pedro Franco de Carvalho)
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3] [PowerPC] Fix debug register issues in ppc-linux-nat
Date: Fri, 09 Aug 2019 15:28:00 -0000	[thread overview]
Message-ID: <20190809152845.C680AD802D2@oc3748833570.ibm.com> (raw)
In-Reply-To: <87y302753y.fsf@linux.ibm.com> from "Pedro Franco de Carvalho" at Aug 09, 2019 12:04:01 PM

Pedro Franco de Carvalho wrote:
> "Ulrich Weigand" <uweigand@de.ibm.com> writes:
> > I may still be missing something, but why exactly *do* we need to know
> > which slots might already be installed?  I'd have assumed that when we
> > get to low_prepare_to_resume, and the lwp is marked stale, we just throw
> > away everything and install the complete desired state.
> 
> To throw away everything in low_prepare_to_resume, we need to know which
> slots the kernel had assigned to the debug registers we requested,
> because PPC_PTRACE_DELHWDEBUG takes the slot as an argument.  Ideally
> we'd have a ptrace call to clear all the debug register state.

Huh.  I wasn't aware we didn't have such a method, but it does appear
you're correct here.  Weird.

> I considered assuming that the kernel will always use a contiguous range
> of slots from 1 to num_instruction_bps + num_data_bps, and always
> deleting all these slots while ignoring ENODATA errors, but I'm not sure
> if this is a very robust solution.  For instance, I inspected the kernel
> code, and in embedded processors, if you set a ranged breakpoint, this
> will occupy slots 1 and 2, and PPC_PTRACE_SETHWDEBUG will return slot 1.
> You then have to use slot 1 as an argument to PPC_PTRACE_DELHWDEBUG to
> delete the ranged breakpoint.  If you try to delete slot 2 before 1,
> you'll get an EINVAL, and not an ENOENT.  If you delete 1 then 2, you'll
> get ENOENT for 2.  I fact, this case means that the solution I proposed
> in my previous reply of gathering all the slots from all threads in the
> same thread group would not work well (we could get EINVALs).

But it seems what would work reliably is to delete slots from 1 to max,
while ignoring ENOENT, right?  In fact, you don't even need to know the
max slot number, because you'll get EINVAL if and only if you're attempting
to delete the first slot after max (assuming you do it in sequence).

> >> Another reason is that add_lwp (and therefore low_new_thread) is also
> >> called in cases other than a ptrace clone event.
> >
> > Well, yes, but those cases *also* need to be handled, right?  This is
> > e.g. when you attach to an already multi-threaded process while there
> > are already watchpoints set up.  In that case, you'll need to install
> > those watchpoints into all those threads.
> 
> This should already work, since we do set the stale flag in
> low_new_thread, like in other targets.  We just don't copy any debug
> register state from other threads.  So when we next resume the newly
> attached threads, we'll install the watchpoints GDB requested.
> 
> However, I don't think that it's possible to handle cases where a
> previous tracer installed hardware breakpoints and watchpoints and then
> detached without removing them.

The above method ought to handle that as well, I think.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


  reply	other threads:[~2019-08-09 15:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26 12:50 [PATCH 0/3] low_new_clone in linux-nat.c and powerpc watchpoint fixes Pedro Franco de Carvalho
2019-07-26 12:50 ` [PATCH 2/3] [PowerPC] Move up some register access routines Pedro Franco de Carvalho
2019-08-08 16:25   ` Ulrich Weigand
2019-07-26 12:50 ` [PATCH 3/3] [PowerPC] Fix debug register issues in ppc-linux-nat Pedro Franco de Carvalho
2019-08-08 16:24   ` Ulrich Weigand
2019-08-08 20:27     ` Pedro Franco de Carvalho
2019-08-09 11:04       ` Ulrich Weigand
2019-08-09 15:04         ` Pedro Franco de Carvalho
2019-08-09 15:28           ` Ulrich Weigand [this message]
2019-08-09 15:53             ` Pedro Franco de Carvalho
2019-07-26 12:50 ` [PATCH 1/3] Add low_new_clone method to linux_nat_target Pedro Franco de Carvalho
2019-08-08 14:05   ` Ulrich Weigand
     [not found] <87ftm56uqg.fsf@linux.ibm.com>
2019-08-21 15:31 ` [PATCH 3/3] [PowerPC] Fix debug register issues in ppc-linux-nat Ulrich Weigand
2019-08-21 17:45   ` Pedro Franco de Carvalho
2019-08-22 10:27     ` Ulrich Weigand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190809152845.C680AD802D2@oc3748833570.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedromfc@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox