Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: gdb-patches@sourceware.org
Subject: [rfc] Fix removing breakpoint from shared library race
Date: Wed, 13 Aug 2008 20:36:00 -0000	[thread overview]
Message-ID: <200808132034.m7DKYEEK005260@d12av02.megacenter.de.ibm.com> (raw)

Hello,

after a shared library was unloaded, we can no longer insert breakpoints
into its (no longer present) code segment.  Therefore, code in breakpoint.c
(disable_breakpoints_in_unloaded_shlib etc.) takes care to disable such
breakpoints.

However, in a multi-threaded application we cannot really guarantee that
we have noticed the shlib unload event at the time breakpoints are to be
inserted or removed.  For the insertion case, insert_bp_location therefore
has its own check, and handles unloaded shared libraries appropriately.

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.

The patch below fixes this, by simply silently ignoring failures to remove
a breakpoint from a shared library code segment.  The breakpoint will be
cleanly disabled once disable_breakpoints_in_unloaded_shlib gets a chance
to run (or at the next attempt to insert it).

Am I missing some reason why we shouldn't get to this point?  Otherwise,
this seems a reasonble solution to me ...

Tested on powerpc-linux and powerpc64-linux.


Bye,
UIrich


ChangeLog:

	* breakpoint.c (remove_breakpoint): Do not fail if unable to remove
	breakpoint from shared library.


diff -urNp gdb-orig/gdb/breakpoint.c gdb-head/gdb/breakpoint.c
--- gdb-orig/gdb/breakpoint.c	2008-08-08 16:42:41.000000000 +0200
+++ gdb-head/gdb/breakpoint.c	2008-08-13 21:56:44.567419172 +0200
@@ -1642,6 +1642,13 @@ remove_breakpoint (struct bp_location *b
 	      val = 0;
 	    }
 	}
+
+      /* In some cases, we might not be able to remove a breakpoint
+	 in a shared library that has already been removed, but we
+	 have not yet processed the shlib unload event.  */
+      if (val && solib_address (b->address))
+	val = 0;
+
       if (val)
 	return val;
       b->inserted = (is == mark_inserted);
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


             reply	other threads:[~2008-08-13 20:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 20:36 Ulrich Weigand [this message]
2008-08-18 11:47 ` Joel Brobecker
2008-08-18 14:15   ` Ulrich Weigand
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=200808132034.m7DKYEEK005260@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.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