Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: brobecker@adacore.com (Joel Brobecker)
Cc: gdb-patches@sourceware.org
Subject: Re: [rfc] Fix removing breakpoint from shared library race
Date: Mon, 18 Aug 2008 14:15:00 -0000	[thread overview]
Message-ID: <200808181414.m7IEEZtO010275@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <20080818114617.GH16894@adacore.com> from "Joel Brobecker" at Aug 18, 2008 03:46:17 PM

Joel Brobecker wrote:

> > When *removing* breakpoints, however, there is no such check.  I have a
> > multi-threaded test case that reproducibly runs into an error when trying
> > to remove a breakpoint from a shared library that was *just* unloaded.
> [...]
> > Am I missing some reason why we shouldn't get to this point?  Otherwise,
> > this seems a reasonble solution to me ...
> 
> The fix looks reasonable to me, but I'm not sure, though. Perhaps
> part of the problem is that I don't see how you got there in your
> example (I'm having trouble figuring out a case where the debugger
> would end up removing a breakpoint while a shared library has just
> been unloaded). Could you post more details?

The actual test case was using the Cell multi-arch debugger.  However,
I think the problem can potentially also show up in current GDB with
multi-threaded code.

Assume you have a thread A that is just unloading a shared library

 1.) app calls dlclose
 2.) dlclose unmaps shared library
 3.) dlclose calls _dl_debug_event (which GDB has a breakpoint on)
 4.) GDB gets active
 5.) GDB processes the unload event

while at the same time, thread B is doing something that invokes GDB

 A.) app runs into a breakpoint
 B.) GDB gets active
 C.) GDB stops all threads
 D.) GDB removes all breakpoints
 E.) GDB goes to user prompt

(Note that this still assumes all-stop, breakpoints-not-always-inserted
mode.  If those new modes are active, the race would probably be more
difficult to trigger.)

Now imagine the race where thread A is just in-between steps 2.) and 3.)
while thread B runs into the breakpoint (which causes GDB to stop thread
A at this point).  When GDB now performs action D.), the breakpoints that
were inserted into the shared library are still on GDB's list as active,
because step 5.) which would have set them to solib_disabled state did
not yet run.  However, attempting to remove the breakpoint will fail 
because the library was already unmapped.

This is the situation that my patch attempts to address, by having the
remove_breakpoints not fail.  At some later point, either when GDB actually
gets to process the solib event, or when GDB tries to re-insert the
breakpoints, GDB will properly recognize that the library has been 
unloaded and sets the state to solib_disabled.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


  reply	other threads:[~2008-08-18 14:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 20:36 Ulrich Weigand
2008-08-18 11:47 ` Joel Brobecker
2008-08-18 14:15   ` Ulrich Weigand [this message]
2008-09-09 20:43     ` Joel Brobecker
2008-09-09 22:32       ` Ulrich Weigand
2008-08-26 17:43 ` 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=200808181414.m7IEEZtO010275@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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