daily update
[deliverable/binutils-gdb.git] / gdb / solib.c
index 639788b3e50367e588a976d5cf0f4cfcdc4b4dd8..e722b985ad67e16dbe212a31e390422a93a68967 100644 (file)
@@ -1,7 +1,7 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -40,9 +40,9 @@
 #include "gdbcmd.h"
 #include "completer.h"
 #include "filenames.h"         /* for DOSish file names */
-
+#include "exec.h"
 #include "solist.h"
-#include <readline/readline.h>
+#include "readline/readline.h"
 
 /* external data declarations */
 
@@ -57,7 +57,7 @@ static int solib_cleanup_queued = 0;  /* make_run_cleanup called */
 
 /* Local function prototypes */
 
-static void do_clear_solib (PTR);
+static void do_clear_solib (void *);
 
 /* If non-zero, this is a prefix that will be added to the front of the name
    shared libraries with an absolute filename for loading.  */
@@ -87,12 +87,19 @@ static char *solib_search_path = NULL;
    (or set of directories, as in LD_LIBRARY_PATH) to search for all
    shared libraries if not found in SOLIB_ABSOLUTE_PREFIX.
 
-   Search order:
-   * If path is absolute, look in SOLIB_ABSOLUTE_PREFIX.
-   * If path is absolute or relative, look for it literally (unmodified).
+   Search algorithm:
+   * If there is a solib_absolute_prefix and path is absolute:
+   *   Search for solib_absolute_prefix/path.
+   * else
+   *   Look for it literally (unmodified).
    * Look in SOLIB_SEARCH_PATH.
-   * Look in inferior's $PATH.
-   * Look in inferior's $LD_LIBRARY_PATH.
+   * If available, use target defined search function.
+   * If solib_absolute_prefix is NOT set, perform the following two searches:
+   *   Look in inferior's $PATH.
+   *   Look in inferior's $LD_LIBRARY_PATH.
+   *   
+   * The last check avoids doing this search when targetting remote
+   * machines since solib_absolute_prefix will almost always be set.
 
    RETURNS
 
@@ -147,29 +154,36 @@ solib_open (char *in_pathname, char **found_pathname)
         in_pathname++;
     }
   
-  /* If not found, next search the solib_search_path (if any).  */
+  /* 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 */
+  if (found_file < 0 && TARGET_SO_FIND_AND_OPEN_SOLIB != NULL)
+    found_file = TARGET_SO_FIND_AND_OPEN_SOLIB
+                 (in_pathname, O_RDONLY, &temp_pathname);
+
   /* If not found, next search the inferior's $PATH environment variable. */
-  if (found_file < 0 && solib_search_path != NULL)
+  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_search_path != NULL)
+  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.  */
@@ -207,7 +221,7 @@ solib_open (char *in_pathname, char **found_pathname)
  */
 
 static int
-solib_map_sections (PTR arg)
+solib_map_sections (void *arg)
 {
   struct so_list *so = (struct so_list *) arg; /* catch_errors bogon */
   char *filename;
@@ -238,7 +252,7 @@ solib_map_sections (PTR 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 */
@@ -263,7 +277,7 @@ solib_map_sections (PTR 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;
        }
@@ -321,12 +335,20 @@ 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
-symbol_add_stub (PTR arg)
+symbol_add_stub (void *arg)
 {
-  register struct so_list *so = (struct so_list *) arg;  /* catch_errs bogon */
+  struct so_list *so = (struct so_list *) arg;  /* catch_errs bogon */
   struct section_addr_info *sap;
 
   /* Have we already loaded this shared object?  */
@@ -376,7 +398,7 @@ symbol_add_stub (PTR arg)
    the section table.  But we only use this for core files and
    processes we've just attached to, so that's okay.  */
 
-void
+static void
 update_solib_list (int from_tty, struct target_ops *target)
 {
   struct so_list *inferior = TARGET_SO_CURRENT_SOS ();
@@ -387,7 +409,7 @@ update_solib_list (int from_tty, struct target_ops *target)
      symbols now!  */
   if (attach_flag &&
       symfile_objfile == NULL)
-    catch_errors (TARGET_SO_OPEN_SYMBOL_FILE_OBJECT, (PTR) &from_tty, 
+    catch_errors (TARGET_SO_OPEN_SYMBOL_FILE_OBJECT, &from_tty, 
                  "Error reading attached process's symbol file.\n",
                  RETURN_MASK_ALL);
 
@@ -615,7 +637,7 @@ solib_add (char *pattern, int from_tty, struct target_ops *target, int readsyms)
 static void
 info_sharedlibrary_command (char *ignore, int from_tty)
 {
-  register struct so_list *so = NULL;  /* link map state variable */
+  struct so_list *so = NULL;   /* link map state variable */
   int header_done = 0;
   int addr_width;
   char *addr_fmt;
@@ -697,7 +719,7 @@ info_sharedlibrary_command (char *ignore, int from_tty)
 char *
 solib_address (CORE_ADDR address)
 {
-  register struct so_list *so = 0;     /* link map state variable */
+  struct so_list *so = 0;      /* link map state variable */
 
   for (so = so_list_head; so; so = so->next)
     {
@@ -755,7 +777,7 @@ clear_solib (void)
 }
 
 static void
-do_clear_solib (PTR dummy)
+do_clear_solib (void *dummy)
 {
   solib_cleanup_queued = 0;
   clear_solib ();
@@ -844,6 +866,15 @@ no_shared_libraries (char *ignored, int from_tty)
   do_clear_solib (NULL);
 }
 
+static void
+reload_shared_libraries (char *ignored, int from_tty)
+{
+  no_shared_libraries (NULL, from_tty);
+  solib_add (NULL, from_tty, NULL, auto_solib_add);
+}
+
+extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
+
 void
 _initialize_solib (void)
 {
@@ -856,7 +887,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\
@@ -872,14 +903,20 @@ 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);
 
+  /* Set the default value of "solib-absolute-prefix" from the sysroot, if
+     one is set.  */
+  solib_absolute_prefix = xstrdup (gdb_sysroot);
+
   c = add_set_cmd ("solib-search-path", class_support, var_string,
                   (char *) &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.026963 seconds and 4 git commands to generate.