This is the mail archive of the gdb-patches@sourceware.cygnus.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]

Re: problems loading shared libraries - with attached test case


Jim Blandy wrote:
> 
> Yep, this is my bug.  Pretty embarrassing, since the whole point of
> the solib_add rewrite was to get it *right* --- but I forgot about
> loading symbols by hand.
> 
> So it was with a mixture of relief and childish glee that I found a
> shortcoming in your patch.  If you tell it to load symbols for a
> shared object that's been unloaded since the last time GDB checked,
> it'll load the symbols anyway, and then throw them away.  Transcript
> below; I added a call to dlclose to your test program.
> 

Good point, I missed that case.  Damn.  Thanks for spending the time on
this, Jim.

While we're talking about this I've noticed a behavior change with
respect to the way the "info sharedlibrary" command works.  It now
forces all the shared libraries to load which is bad(tm).  I've done
that a few times and had to kill gdb after it sucked up a couple hundred
meg of memory. :)

--Chris

> I've committed the patch at bottom, which fixes a few other minor
> problems in your change, and another major problem in my old code.
> 
> Some final comments:
> - Thank you so much for the clear and simple test programs.
> - You should post patches to gdb-patches@sourceware.
> - Please don't include the ChangeLog diff in the patch --- it
>   never applies cleanly.  Just insert the ChangeLog text as-is at
>   the top of the patch.
> 
> zenia:manual-solib$ $D6/gdb/gdb main
> GNU gdb 20000204
> Copyright 2000 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i686-pc-linux-gnu"...
> (gdb) break main
> Breakpoint 1 at 0x80487f6: file main.c, line 5.
> (gdb) run
> Starting program: /home/jimb/gdb/bugs/manual-solib/main
> set
> Breakpoint 1, main (argc=1, argv=0xbfffedb4) at main.c:5
> 5         void *handle0 = dlopen("./libdummy0.so", RTLD_LAZY);
> (gdb) set auto-solib-add 0
> (gdb) next
> 6         void *handle1 = dlopen("./libdummy1.so", RTLD_LAZY);
> (gdb)
> 7         void *handle2 = dlopen("./libdummy2.so", RTLD_LAZY);
> (gdb) shar dummy1
> Reading symbols from /home/jimb/gdb/bugs/manual-solib/./libdummy1.so...done.
> Loaded symbols for /home/jimb/gdb/bugs/manual-solib/./libdummy1.so
> (gdb) next
> 8         void *handle3 = dlopen("./libdummy3.so", RTLD_LAZY);
> (gdb)
> 9         dlclose (handle0);
> (gdb)
> 10        printf("Hi.\n");
> (gdb) shar dummy0
> Reading symbols from /home/jimb/gdb/bugs/manual-solib/./libdummy0.so...done.
> Loaded symbols for /home/jimb/gdb/bugs/manual-solib/./libdummy0.so
> (gdb) info shared
> Reading symbols from /home/jimb/gdb/bugs/manual-solib/./libdummy2.so...done.
> Reading symbols from /home/jimb/gdb/bugs/manual-solib/./libdummy3.so...done.
> >From        To          Syms Read   Shared Object Library
> 0x40017000  0x40019d0c  Yes         /lib/libdl.so.2
> 0x4001b000  0x4005cdb0  Yes         /usr/lib/libstdc++-libc6.1-1.so.2
> 0x4005d000  0x40078fd8  Yes         /lib/libm.so.6
> 0x40079000  0x4016b8dc  Yes         /lib/libc.so.6
> 0x40000000  0x400126b0  Yes         /lib/ld-linux.so.2
> 0x40015000  0x40016cbc  Yes         /home/jimb/gdb/bugs/manual-solib/./libdummy1.so
> 0x4016c000  0x4016dcbc  Yes         /home/jimb/gdb/bugs/manual-solib/./libdummy2.so
> 0x4016e000  0x4016fcbc  Yes         /home/jimb/gdb/bugs/manual-solib/./libdummy3.so
> (gdb)
> 
> The patch:
> 
> 2000-04-03  Jim Blandy  <jimb@redhat.com>
> 
>         * solib.c (solib_add): Move all the code for loading symbol tables
>         below the code to sort out additions and removals.  That way, we
>         always catch all loaded shared libraries whose symbols we haven't
>         grabbed yet.
> 
>         * solib.c (solib_add): Don't try to free a shared object's objfile
>         if it doesn't have one.  Duh.
> 
>         * solib.c (solib_add): If a pattern was given, but it doesn't
>         match any currently loaded shared libraries, print a message;
>         don't just be silent.
> 
> Index: gdb/solib.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/solib.c,v
> retrieving revision 1.7
> diff -c -r1.7 solib.c
> *** gdb/solib.c 2000/03/24 23:49:10     1.7
> --- gdb/solib.c 2000/04/03 17:15:05
> ***************
> *** 1315,1321 ****
>           *gdb_link = gdb->next;
> 
>           /* Unless the user loaded it explicitly, free SO's objfile.  */
> !         if (! (gdb->objfile->flags & OBJF_USERLOADED))
>             free_objfile (gdb->objfile);
> 
>           /* Some targets' section tables might be referring to
> --- 1315,1321 ----
>           *gdb_link = gdb->next;
> 
>           /* Unless the user loaded it explicitly, free SO's objfile.  */
> !         if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED))
>             free_objfile (gdb->objfile);
> 
>           /* Some targets' section tables might be referring to
> ***************
> *** 1329,1336 ****
> 
>     /* Now the inferior's list contains only shared objects that don't
>        appear in GDB's list --- those that are newly loaded.  Add them
> !      to GDB's shared object list, and read in their symbols, if
> !      appropriate.  */
>     if (inferior)
>       {
>         struct so_list *i;
> --- 1329,1335 ----
> 
>     /* Now the inferior's list contains only shared objects that don't
>        appear in GDB's list --- those that are newly loaded.  Add them
> !      to GDB's shared object list.  */
>     if (inferior)
>       {
>         struct so_list *i;
> ***************
> *** 1338,1345 ****
>         /* Add the new shared objects to GDB's list.  */
>         *gdb_link = inferior;
> 
> !       /* Fill in the rest of each of the `struct so_list' nodes, and
> !        read symbols for those files whose names match PATTERN.  */
>         for (i = inferior; i; i = i->next)
>         {
>           i->from_tty = from_tty;
> --- 1337,1343 ----
>         /* Add the new shared objects to GDB's list.  */
>         *gdb_link = inferior;
> 
> !       /* Fill in the rest of each of the `struct so_list' nodes.  */
>         for (i = inferior; i; i = i->next)
>         {
>           i->from_tty = from_tty;
> ***************
> *** 1348,1376 ****
>           catch_errors (solib_map_sections, i,
>                         "Error while mapping shared library sections:\n",
>                         RETURN_MASK_ALL);
> -
> -         if (! pattern || re_exec (i->so_name))
> -           {
> -             if (i->symbols_loaded)
> -               {
> -                 if (from_tty)
> -                   printf_unfiltered ("Symbols already loaded for %s\n",
> -                                      i->so_name);
> -               }
> -             else
> -               {
> -                 if (catch_errors
> -                     (symbol_add_stub, i,
> -                      "Error while reading shared library symbols:\n",
> -                      RETURN_MASK_ALL))
> -                   {
> -                     if (from_tty)
> -                       printf_unfiltered ("Loaded symbols for %s\n",
> -                                          i->so_name);
> -                     i->symbols_loaded = 1;
> -                   }
> -               }
> -           }
>         }
> 
>         /* If requested, add the shared objects' sections to the the
> --- 1346,1351 ----
> ***************
> *** 1398,1410 ****
>                 }
>             }
>         }
> 
> !       /* Getting new symbols may change our opinion about what is
> !          frameless.  */
> !       reinit_frame_cache ();
> 
> !       special_symbol_handling ();
> !     }
>   }
> 
> 
> --- 1373,1428 ----
>                 }
>             }
>         }
> +     }
> 
> !   /* Finally, read the symbols as requested.  Walk the list of
> !      currently loaded shared libraries, and read symbols for any that
> !      match the pattern --- or any whose symbols aren't already loaded,
> !      if no pattern was given.  */
> !   {
> !     int any_matches = 0;
> !     int loaded_any_symbols = 0;
> 
> !     for (gdb = so_list_head; gdb; gdb = gdb->next)
> !       if (! pattern || re_exec (gdb->so_name))
> !       {
> !         any_matches = 1;
> !
> !         if (gdb->symbols_loaded)
> !           {
> !             if (from_tty)
> !               printf_unfiltered ("Symbols already loaded for %s\n",
> !                                  gdb->so_name);
> !           }
> !         else
> !           {
> !             if (catch_errors
> !                 (symbol_add_stub, gdb,
> !                  "Error while reading shared library symbols:\n",
> !                  RETURN_MASK_ALL))
> !               {
> !                 if (from_tty)
> !                   printf_unfiltered ("Loaded symbols for %s\n",
> !                                      gdb->so_name);
> !                 gdb->symbols_loaded = 1;
> !                 loaded_any_symbols = 1;
> !               }
> !           }
> !       }
> !
> !     if (from_tty && pattern && ! any_matches)
> !       printf_unfiltered
> !       ("No loaded shared libraries match the pattern `%s'.\n", pattern);
> !
> !     if (loaded_any_symbols)
> !       {
> !       /* Getting new symbols may change our opinion about what is
> !          frameless.  */
> !       reinit_frame_cache ();
> !
> !       special_symbol_handling ();
> !       }
> !   }
>   }
> 
> 

-- 
------------
Christopher Blizzard
http://people.redhat.com/blizzard/
Consider the daffodil. And while you're doing that, I'll be over
here, looking through your stuff.
------------

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