This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix a bp_shlib_disabled bug with dlopen'd libraries


On Wed, Jul 30, 2003 at 09:32:10PM -0400, Daniel Jacobowitz wrote:
> While investigating what is probably a different dlopen issue, I stumbled on
> this.  Build a trivial shared library, and load it.  Set a breakpoint in it,

... load it using dlopen, I mean.

> and re-run.  We get hopelessly confused.
> 
> The problem occurs in remove_breakpoints (), which returns on the first
> failure - so breakpoints_inserted gets out of sync with reality.  Rather
> than fix it there, I went back to find the root cause of the problem in
> remove_breakpoint.  Turns out we were "inserting" a breakpoint before the
> shared library it belonged to was loaded.  Somehow, this led to us failing
> to remove it, and then when we tried to single-step past it thinking it had
> been removed, the inferior segfaulted.
> 
> Easiest fix was this.  Don't just try to access target memory - the page
> might have been mapped for some other reason, which it appears to be on my
> system.  In fact, this library gets loaded where /etc/ld.so.cache is mmaped
> during the initial library search!  No wonder bad things happened.

... because we inserted a breakpoint over program data.

> A possibly better fix is to check by name that the right shared library is
> loaded; should I do that?  A definitely better fix would be to make
> breakpoint_re_set_one communicate with this mechanism, instead of just
> spewing errors to the terminal about undefined functions; that way we'd
> actually know when to reset the breakpoint.  But that's quite tricky to do.

No one had any comments on this old patch.  While not ideal, it is
still an improvement, so I've checked it in after retesting.  Updated
version attached.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-11-16  Daniel Jacobowitz  <drow@mvista.com>

	* breakpoint.c (re_enable_breakpoints_in_shlibs): Only re-enable a
	bp_shlib_disabled breakpoint if there is a shared library mapped
	at its expected address.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.144
diff -u -p -r1.144 breakpoint.c
--- breakpoint.c	12 Nov 2003 17:00:42 -0000	1.144
+++ breakpoint.c	16 Nov 2003 22:44:41 -0000
@@ -4297,11 +4297,12 @@ re_enable_breakpoints_in_shlibs (void)
   ALL_BREAKPOINTS (b)
     if (b->enable_state == bp_shlib_disabled)
     {
-      char buf[1];
+      char buf[1], *lib;
 
       /* Do not reenable the breakpoint if the shared library
          is still not mapped in.  */
-      if (target_read_memory (b->loc->address, buf, 1) == 0)
+      lib = PC_SOLIB (b->loc->address);
+      if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
 	b->enable_state = bp_enabled;
     }
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]