2005-02-02 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / solib.c
index fcd2ad40ee200d393a873bcd628fb078b4148e9c..3efe57524ad3214aae445f8dfc91365ac78d7515 100644 (file)
@@ -1,7 +1,8 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2005
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -29,6 +30,7 @@
 #include "bfd.h"
 #include "symfile.h"
 #include "objfiles.h"
+#include "exceptions.h"
 #include "gdbcore.h"
 #include "command.h"
 #include "target.h"
@@ -42,7 +44,8 @@
 #include "filenames.h"         /* for DOSish file names */
 #include "exec.h"
 #include "solist.h"
-#include <readline/readline.h>
+#include "observer.h"
+#include "readline/readline.h"
 
 /* external data declarations */
 
@@ -156,15 +159,15 @@ solib_open (char *in_pathname, char **found_pathname)
   
   /* If not found, search the solib_search_path (if any).  */
   if (found_file < 0 && solib_search_path != NULL)
-    found_file = openp (solib_search_path,
-                       1, in_pathname, O_RDONLY, 0, &temp_pathname);
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+                       in_pathname, O_RDONLY, 0, &temp_pathname);
   
   /* If not found, next search the solib_search_path (if any) for the basename
      only (ignoring the path).  This is to allow reading solibs from a path
      that differs from the opened path.  */
   if (found_file < 0 && solib_search_path != NULL)
-    found_file = openp (solib_search_path, 
-                        1, lbasename (in_pathname), O_RDONLY, 0,
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+                        lbasename (in_pathname), O_RDONLY, 0,
                         &temp_pathname);
 
   /* If not found, try to use target supplied solib search method */
@@ -175,13 +178,15 @@ solib_open (char *in_pathname, char **found_pathname)
   /* If not found, next search the inferior's $PATH environment variable. */
   if (found_file < 0 && solib_absolute_prefix == NULL)
     found_file = openp (get_in_environ (inferior_environ, "PATH"),
-                       1, in_pathname, O_RDONLY, 0, &temp_pathname);
+                       OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+                       &temp_pathname);
 
   /* If not found, next search the inferior's $LD_LIBRARY_PATH 
      environment variable. */
   if (found_file < 0 && solib_absolute_prefix == NULL)
     found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
-                       1, in_pathname, O_RDONLY, 0, &temp_pathname);
+                       OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+                       &temp_pathname);
 
   /* Done.  If not found, tough luck.  Return found_file and 
      (optionally) found_pathname.  */
@@ -250,7 +255,7 @@ solib_map_sections (void *arg)
 
   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
   so->abfd = abfd;
-  abfd->cacheable = 1;
+  bfd_set_cacheable (abfd, 1);
 
   /* copy full path name into so_name, so that later symbol_file_add
      can find it */
@@ -275,7 +280,7 @@ solib_map_sections (void *arg)
          object's file by the base address to which the object was actually
          mapped. */
       TARGET_SO_RELOCATE_SECTION_ADDRESSES (so, p);
-      if (STREQ (p->the_bfd_section->name, ".text"))
+      if (strcmp (p->the_bfd_section->name, ".text") == 0)
        {
          so->textsection = p;
        }
@@ -333,6 +338,14 @@ free_so (struct so_list *so)
 }
 
 
+/* Return address of first so_list entry in master shared object list.  */
+struct so_list *
+master_so_list (void)
+{
+  return so_list_head;
+}
+
+
 /* A small stub to get us past the arg-passing pinhole of catch_errors.  */
 
 static int
@@ -358,6 +371,33 @@ symbol_add_stub (void *arg)
   return (1);
 }
 
+/* Read in symbols for shared object SO.  If FROM_TTY is non-zero, be
+   chatty about it.  Return non-zero if any symbols were actually
+   loaded.  */
+
+int
+solib_read_symbols (struct so_list *so, int from_tty)
+{
+  if (so->symbols_loaded)
+    {
+      if (from_tty)
+       printf_unfiltered ("Symbols already loaded for %s\n", so->so_name);
+    }
+  else
+    {
+      if (catch_errors (symbol_add_stub, so,
+                       "Error while reading shared library symbols:\n",
+                       RETURN_MASK_ALL))
+       {
+         if (from_tty)
+           printf_unfiltered ("Loaded symbols for %s\n", so->so_name);
+         so->symbols_loaded = 1;
+         return 1;
+       }
+    }
+
+  return 0;
+}
 
 /* LOCAL FUNCTION
 
@@ -468,6 +508,10 @@ update_solib_list (int from_tty, struct target_ops *target)
       /* If it's not on the inferior's list, remove it from GDB's tables.  */
       else
        {
+         /* Notify any observer that the shared object has been
+            unloaded before we remove it from GDB's tables.  */
+         observer_notify_solib_unloaded (gdb);
+
          *gdb_link = gdb->next;
 
          /* Unless the user loaded it explicitly, free SO's objfile.  */
@@ -518,6 +562,10 @@ update_solib_list (int from_tty, struct target_ops *target)
                          count * sizeof (i->sections[0]));
                }
            }
+
+         /* Notify any observer that the shared object has been
+             loaded now that we've added it to GDB's tables.  */
+         observer_notify_solib_loaded (i);
        }
     }
 }
@@ -569,27 +617,8 @@ solib_add (char *pattern, int from_tty, struct target_ops *target, int readsyms)
       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 (readsyms)
-           {
-             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 (readsyms && solib_read_symbols (gdb, from_tty))
+           loaded_any_symbols = 1;
        }
 
     if (from_tty && pattern && ! any_matches)
@@ -630,18 +659,11 @@ info_sharedlibrary_command (char *ignore, int from_tty)
   struct so_list *so = NULL;   /* link map state variable */
   int header_done = 0;
   int addr_width;
-  char *addr_fmt;
 
   if (TARGET_PTR_BIT == 32)
-    {
-      addr_width = 8 + 4;
-      addr_fmt = "08l";
-    }
+    addr_width = 8 + 4;
   else if (TARGET_PTR_BIT == 64)
-    {
-      addr_width = 16 + 4;
-      addr_fmt = "016l";
-    }
+    addr_width = 16 + 4;
   else
     {
       internal_error (__FILE__, __LINE__,
@@ -665,15 +687,15 @@ info_sharedlibrary_command (char *ignore, int from_tty)
 
          printf_unfiltered ("%-*s", addr_width,
                             so->textsection != NULL 
-                              ? local_hex_string_custom (
+                              ? hex_string_custom (
                                   (LONGEST) so->textsection->addr,
-                                  addr_fmt)
+                                  addr_width - 4)
                               : "");
          printf_unfiltered ("%-*s", addr_width,
                             so->textsection != NULL 
-                              ? local_hex_string_custom (
+                              ? hex_string_custom (
                                   (LONGEST) so->textsection->endaddr,
-                                  addr_fmt)
+                                  addr_width - 4)
                               : "");
          printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No");
          printf_unfiltered ("%s\n", so->so_name);
@@ -779,7 +801,7 @@ do_clear_solib (void *dummy)
 
    SYNOPSIS
 
-   void solib_create_inferior_hook()
+   void solib_create_inferior_hook ()
 
    DESCRIPTION
 
@@ -877,7 +899,7 @@ _initialize_solib (void)
   add_com ("nosharedlibrary", class_files, no_shared_libraries,
           "Unload all shared object library symbols.");
 
-  add_show_from_set
+  deprecated_add_show_from_set
     (add_set_cmd ("auto-solib-add", class_support, var_boolean,
                  (char *) &auto_solib_add,
                  "Set autoloading of shared library symbols.\n\
@@ -893,7 +915,7 @@ inferior.  Otherwise, symbols must be loaded manually, using `sharedlibrary'.",
                   "Set prefix for loading absolute shared library symbol files.\n\
 For other (relative) files, you can add values using `set solib-search-path'.",
                   &setlist);
-  add_show_from_set (c, &showlist);
+  deprecated_add_show_from_set (c, &showlist);
   set_cmd_cfunc (c, reload_shared_libraries);
   set_cmd_completer (c, filename_completer);
 
@@ -906,7 +928,7 @@ For other (relative) files, you can add values using `set solib-search-path'.",
                   "Set the search path for loading non-absolute shared library symbol files.\n\
 This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
                   &setlist);
-  add_show_from_set (c, &showlist);
+  deprecated_add_show_from_set (c, &showlist);
   set_cmd_cfunc (c, reload_shared_libraries);
   set_cmd_completer (c, filename_completer);
 }
This page took 0.02831 seconds and 4 git commands to generate.