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,
> 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.
> 
> 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.
> 
> Comments?  Michael, I'd like to fix this for 6.0...

Ping?

> 2003-07-30  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.125
> diff -u -p -r1.125 breakpoint.c
> --- breakpoint.c	2 Jul 2003 16:24:00 -0000	1.125
> +++ breakpoint.c	31 Jul 2003 01:22:29 -0000
> @@ -4122,10 +4122,12 @@ re_enable_breakpoints_in_shlibs (void)
>      if (b->enable_state == bp_shlib_disabled)
>      {
>        char buf[1];
> +      char *lib;
>  
>        /* Do not reenable the breakpoint if the shared library
>           is still not mapped in.  */
> -      if (target_read_memory (b->address, buf, 1) == 0)
> +      lib = PC_SOLIB (b->address);
> +      if (lib && target_read_memory (b->address, buf, 1) == 0)
>  	b->enable_state = bp_enabled;
>      }
>  }
> 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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