revert 1.9. Not approved.
[deliverable/binutils-gdb.git] / gdb / solib.c
index 621bd6cc4250ded01c1f939216130d94a1089082..fe3265e0930a6dfc7dad9f695dab6911d47b1dec 100644 (file)
@@ -49,7 +49,7 @@
 #include "command.h"
 #include "target.h"
 #include "frame.h"
-#include "gnu-regex.h"
+#include "gdb_regex.h"
 #include "inferior.h"
 #include "environ.h"
 #include "language.h"
@@ -921,7 +921,7 @@ first_link_map_member ()
 
   LOCAL FUNCTION
 
-  open_exec_file_object
+  open_symbol_file_object
 
   SYNOPSIS
 
@@ -936,11 +936,10 @@ first_link_map_member ()
 
  */
 
-int
-open_symbol_file_object (arg)
-     PTR arg;
+static int
+open_symbol_file_object (from_ttyp)
+     int *from_ttyp;   /* sneak past catch_errors */
 {
-  int from_tty = (int) arg;    /* sneak past catch_errors */
   CORE_ADDR lm;
   struct link_map lmcopy;
   char *filename;
@@ -975,7 +974,7 @@ open_symbol_file_object (arg)
 
   make_cleanup ((make_cleanup_func) free, (void *) filename);
   /* Have a pathname: read the symbol file.  */
-  symbol_file_command (filename, from_tty);
+  symbol_file_command (filename, *from_ttyp);
 
   return 1;
 }
@@ -1156,6 +1155,8 @@ symbol_add_stub (arg)
   register struct so_list *so = (struct so_list *) arg;  /* catch_errs bogon */
   CORE_ADDR text_addr = 0;
   struct section_addr_info *sap;
+  int i;
+  asection *text_section;
 
   /* Have we already loaded this shared object?  */
   ALL_OBJFILES (so->objfile)
@@ -1184,7 +1185,14 @@ symbol_add_stub (arg)
 
   sap = build_section_addr_info_from_section_table (so->sections,
                                                     so->sections_end);
-  sap->text_addr = text_addr;
+
+  /* Look for the index for the .text section in the sap structure. */
+  text_section = bfd_get_section_by_name (so->abfd, ".text");
+  for (i = 0; i < MAX_SECTIONS && sap->other[i].name; i++)
+    if (sap->other[i].sectindex == text_section->index)
+      break;
+  
+  sap->other[i].addr = text_addr;
   so->objfile = symbol_file_add (so->so_name, so->from_tty,
                                 sap, 0, OBJF_SHARED);
   free_section_addr_info (sap);
@@ -1195,22 +1203,22 @@ symbol_add_stub (arg)
 
 /* LOCAL FUNCTION
 
-   solib_add -- synchronize GDB's shared object list with the inferior's
+   update_solib_list --- synchronize GDB's shared object list with inferior's
 
    SYNOPSIS
 
-   void solib_add (char *pattern, int from_tty, struct target_ops *TARGET)
-
-   DESCRIPTION
+   void update_solib_list (int from_tty, struct target_ops *TARGET)
 
    Extract the list of currently loaded shared objects from the
-   inferior, and compare it with the list of shared objects for which
-   GDB has currently loaded symbolic information.  If new shared
-   objects have been loaded, or old shared objects have disappeared,
-   make the appropriate changes to GDB's tables.
+   inferior, and compare it with the list of shared objects currently
+   in GDB's so_list_head list.  Edit so_list_head to bring it in sync
+   with the inferior's new list.
 
-   If PATTERN is non-null, read symbols only for shared objects
-   whose names match PATTERN.
+   If we notice that the inferior has unloaded some shared objects,
+   free any symbolic info GDB had read about those shared objects.
+
+   Don't load symbolic info for any new shared objects; just add them
+   to the list, and leave their symbols_loaded flag clear.
 
    If FROM_TTY is non-null, feel free to print messages about what
    we're doing.
@@ -1223,7 +1231,7 @@ symbol_add_stub (arg)
    processes we've just attached to, so that's okay.  */
 
 void
-solib_add (char *pattern, int from_tty, struct target_ops *target)
+update_solib_list (int from_tty, struct target_ops *target)
 {
   struct so_list *inferior = current_sos ();
   struct so_list *gdb, **gdb_link;
@@ -1234,20 +1242,12 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
      symbols now!  */
   if (attach_flag &&
       symfile_objfile == NULL)
-    catch_errors (open_symbol_file_object, (PTR) from_tty, 
+    catch_errors (open_symbol_file_object, (PTR) &from_tty, 
                  "Error reading attached process's symbol file.\n",
                  RETURN_MASK_ALL);
 
 #endif SVR4_SHARED_LIBS
 
-  if (pattern)
-    {
-      char *re_err = re_comp (pattern);
-
-      if (re_err)
-       error ("Invalid regexp: %s", re_err);
-    }
-
   /* Since this function might actually add some elements to the
      so_list_head list, arrange for it to be cleaned up when
      appropriate.  */
@@ -1263,16 +1263,16 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
      shared objects appear where.  There are three cases:
 
      - A shared object appears on both lists.  This means that GDB
-       knows about it already, and it's still loaded in the inferior.
-       Nothing needs to happen.
+     knows about it already, and it's still loaded in the inferior.
+     Nothing needs to happen.
 
      - A shared object appears only on GDB's list.  This means that
-       the inferior has unloaded it.  We should remove the shared
-       object from GDB's tables.
+     the inferior has unloaded it.  We should remove the shared
+     object from GDB's tables.
 
      - A shared object appears only on the inferior's list.  This
-       means that it's just been loaded.  We should add it to GDB's
-       tables.
+     means that it's just been loaded.  We should add it to GDB's
+     tables.
 
      So we walk GDB's list, checking each entry to see if it appears
      in the inferior's list too.  If it does, no action is needed, and
@@ -1316,7 +1316,7 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
          *gdb_link = gdb->next;
 
          /* Unless the user loaded it explicitly, free SO's objfile.  */
-         if (! (gdb->objfile->flags & OBJF_USERLOADED))
+         if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED))
            free_objfile (gdb->objfile);
 
          /* Some targets' section tables might be referring to
@@ -1330,8 +1330,7 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
 
   /* 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.  */
+     to GDB's shared object list.  */
   if (inferior)
     {
       struct so_list *i;
@@ -1339,8 +1338,7 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
       /* 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.  */
+      /* Fill in the rest of each of the `struct so_list' nodes.  */
       for (i = inferior; i; i = i->next)
        {
          i->from_tty = from_tty;
@@ -1349,29 +1347,6 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
          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
@@ -1399,13 +1374,88 @@ solib_add (char *pattern, int from_tty, struct target_ops *target)
                }
            }
        }
+    }
+}
+
+
+/* GLOBAL FUNCTION
+
+   solib_add -- read in symbol info for newly added shared libraries
+
+   SYNOPSIS
 
-      /* Getting new symbols may change our opinion about what is
-         frameless.  */
-      reinit_frame_cache ();
+   void solib_add (char *pattern, int from_tty, struct target_ops *TARGET)
+
+   DESCRIPTION
+
+   Read in symbolic information for any shared objects whose names
+   match PATTERN.  (If we've already read a shared object's symbol
+   info, leave it alone.)  If PATTERN is zero, read them all.
+
+   FROM_TTY and TARGET are as described for update_solib_list, above.  */
+
+void
+solib_add (char *pattern, int from_tty, struct target_ops *target)
+{
+  struct so_list *gdb;
 
-      special_symbol_handling ();
+  if (pattern)
+    {
+      char *re_err = re_comp (pattern);
+
+      if (re_err)
+       error ("Invalid regexp: %s", re_err);
     }
+
+  update_solib_list (from_tty, target);
+
+  /* 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 ();
+      }
+  }
 }
 
 
@@ -1449,7 +1499,7 @@ info_sharedlibrary_command (ignore, from_tty)
   addr_fmt = "016l";
 #endif
 
-  solib_add (0, 0, 0);
+  update_solib_list (from_tty, 0);
 
   for (so = so_list_head; so; so = so->next)
     {
This page took 0.029374 seconds and 4 git commands to generate.