2003-04-13 Michael Snyder <msnyder@redhat.com>
[binutils-gdb.git] / gdb / solib.c
index ddf317146b752e16428f2022b645d960dca88afb..289b84f34bfc4478a723383cd12597c491538132 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
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -42,6 +42,7 @@
 #include "filenames.h"         /* for DOSish file names */
 
 #include "solist.h"
+#include <readline/readline.h>
 
 /* external data declarations */
 
@@ -56,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.  */
@@ -159,6 +160,11 @@ solib_open (char *in_pathname, char **found_pathname)
                         1, 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)
     found_file = openp (get_in_environ (inferior_environ, "PATH"),
@@ -206,7 +212,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;
@@ -237,7 +243,7 @@ solib_map_sections (PTR arg)
 
   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
   so->abfd = abfd;
-  abfd->cacheable = true;
+  abfd->cacheable = 1;
 
   /* copy full path name into so_name, so that later symbol_file_add
      can find it */
@@ -323,7 +329,7 @@ free_so (struct so_list *so)
 /* 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 section_addr_info *sap;
@@ -386,7 +392,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);
 
@@ -618,25 +624,13 @@ info_sharedlibrary_command (char *ignore, int from_tty)
   int header_done = 0;
   int addr_width;
   char *addr_fmt;
-  int arch_size;
-
-  if (exec_bfd == NULL)
-    {
-      printf_unfiltered ("No executable file.\n");
-      return;
-    }
-
-  arch_size = bfd_get_arch_size (exec_bfd);
-  if (arch_size == -1)
-    arch_size = bfd_arch_bits_per_address(exec_bfd);
 
-  /* Default to 32-bit in case of failure.  */
-  if (arch_size == 32 || arch_size == -1)
+  if (TARGET_PTR_BIT == 32)
     {
       addr_width = 8 + 4;
       addr_fmt = "08l";
     }
-  else if (arch_size == 64)
+  else if (TARGET_PTR_BIT == 64)
     {
       addr_width = 16 + 4;
       addr_fmt = "016l";
@@ -644,8 +638,8 @@ info_sharedlibrary_command (char *ignore, int from_tty)
   else
     {
       internal_error (__FILE__, __LINE__,
-                     "bfd_get_arch_size() returned unknown size %d",
-                     arch_size);
+                     "TARGET_PTR_BIT returned unknown size %d",
+                     TARGET_PTR_BIT);
     }
 
   update_solib_list (from_tty, 0);
@@ -664,13 +658,13 @@ info_sharedlibrary_command (char *ignore, int from_tty)
 
          printf_unfiltered ("%-*s", addr_width,
                             so->textsection != NULL 
-                              ? longest_local_hex_string_custom (
+                              ? local_hex_string_custom (
                                   (LONGEST) so->textsection->addr,
                                   addr_fmt)
                               : "");
          printf_unfiltered ("%-*s", addr_width,
                             so->textsection != NULL 
-                              ? longest_local_hex_string_custom (
+                              ? local_hex_string_custom (
                                   (LONGEST) so->textsection->endaddr,
                                   addr_fmt)
                               : "");
@@ -766,7 +760,7 @@ clear_solib (void)
 }
 
 static void
-do_clear_solib (PTR dummy)
+do_clear_solib (void *dummy)
 {
   solib_cleanup_queued = 0;
   clear_solib ();
@@ -855,6 +849,13 @@ 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);
+}
+
 void
 _initialize_solib (void)
 {
@@ -884,7 +885,12 @@ inferior.  Otherwise, symbols must be loaded manually, using `sharedlibrary'.",
 For other (relative) files, you can add values using `set solib-search-path'.",
                   &setlist);
   add_show_from_set (c, &showlist);
-  c->completer = filename_completer;
+  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,
@@ -892,5 +898,6 @@ For other (relative) files, you can add values using `set solib-search-path'.",
 This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
                   &setlist);
   add_show_from_set (c, &showlist);
-  c->completer = filename_completer;
+  set_cmd_cfunc (c, reload_shared_libraries);
+  set_cmd_completer (c, filename_completer);
 }