* exec.c: #include "arch-utils.h"
[deliverable/binutils-gdb.git] / gdb / solib.c
index d260c12ce782de894525d39409a6ff0e480836d7..69680b455cbb2ef24099261eb4728fc9dcda427b 100644 (file)
@@ -1,13 +1,14 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -16,9 +17,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 
@@ -88,12 +87,8 @@ struct target_so_ops *current_target_so_ops;
 
 static struct so_list *so_list_head;   /* List of known shared objects */
 
-static int solib_cleanup_queued = 0;   /* make_run_cleanup called */
-
 /* Local function prototypes */
 
-static void do_clear_solib (void *);
-
 /* If non-empty, this is a search path for loading non-absolute shared library
    symbol files.  This takes precedence over the environment variables PATH
    and LD_LIBRARY_PATH.  */
@@ -176,6 +171,17 @@ solib_open (char *in_pathname, char **found_pathname)
   /* Now see if we can open it.  */
   found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
 
+  /* We try to find the library in various ways.  After each attempt
+     (except for the one above), either found_file >= 0 and
+     temp_pathname is a malloc'd string, or found_file < 0 and
+     temp_pathname does not point to storage that needs to be
+     freed.  */
+
+    if (found_file < 0)
+      temp_pathname = NULL;
+    else
+      temp_pathname = xstrdup (temp_pathname);
+
   /* If the search in gdb_sysroot failed, and the path name is
      absolute at this point, make it relative.  (openp will try and open the
      file according to its absolute path otherwise, which is not what we want.)
@@ -224,8 +230,13 @@ solib_open (char *in_pathname, char **found_pathname)
 
   /* Done.  If not found, tough luck.  Return found_file and 
      (optionally) found_pathname.  */
-  if (found_pathname != NULL && temp_pathname != NULL)
-    *found_pathname = xstrdup (temp_pathname);
+  if (temp_pathname)
+    {
+      if (found_pathname != NULL)
+       *found_pathname = temp_pathname;
+      else
+       xfree (temp_pathname);
+    }
   return found_file;
 }
 
@@ -316,9 +327,15 @@ solib_map_sections (void *arg)
          object's file by the base address to which the object was actually
          mapped. */
       ops->relocate_section_addresses (so, p);
-      if (strcmp (p->the_bfd_section->name, ".text") == 0)
+
+      /* If the target didn't provide information about the address
+        range of the shared object, assume we want the location of
+        the .text section.  */
+      if (so->addr_low == 0 && so->addr_high == 0
+         && strcmp (p->the_bfd_section->name, ".text") == 0)
        {
-         so->textsection = p;
+         so->addr_low = p->addr;
+         so->addr_high = p->endaddr;
        }
     }
 
@@ -486,15 +503,6 @@ update_solib_list (int from_tty, struct target_ops *target)
                  "Error reading attached process's symbol file.\n",
                  RETURN_MASK_ALL);
 
-  /* Since this function might actually add some elements to the
-     so_list_head list, arrange for it to be cleaned up when
-     appropriate.  */
-  if (!solib_cleanup_queued)
-    {
-      make_run_cleanup (do_clear_solib, NULL);
-      solib_cleanup_queued = 1;
-    }
-
   /* GDB and the inferior's dynamic linker each maintain their own
      list of currently loaded shared objects; we want to bring the
      former in sync with the latter.  Scan both lists, seeing which
@@ -530,8 +538,16 @@ update_solib_list (int from_tty, struct target_ops *target)
         the inferior's current list.  */
       while (i)
        {
-         if (! strcmp (gdb->so_original_name, i->so_original_name))
-           break;
+         if (ops->same)
+           {
+             if (ops->same (gdb, i))
+               break;
+           }
+         else
+           {
+             if (! strcmp (gdb->so_original_name, i->so_original_name))
+               break;        
+           }
 
          i_link = &i->next;
          i = *i_link;
@@ -725,7 +741,7 @@ info_sharedlibrary_command (char *ignore, int from_tty)
   int addr_width;
 
   /* "0x", a little whitespace, and two hex digits per byte of pointers.  */
-  addr_width = 4 + (TARGET_PTR_BIT / 4);
+  addr_width = 4 + (gdbarch_ptr_bit (current_gdbarch) / 4);
 
   update_solib_list (from_tty, 0);
 
@@ -742,15 +758,15 @@ info_sharedlibrary_command (char *ignore, int from_tty)
            }
 
          printf_unfiltered ("%-*s", addr_width,
-                            so->textsection != NULL 
+                            so->addr_high != 0
                               ? hex_string_custom (
-                                  (LONGEST) so->textsection->addr,
+                                  (LONGEST) so->addr_low,
                                   addr_width - 4)
                               : "");
          printf_unfiltered ("%-*s", addr_width,
-                            so->textsection != NULL 
+                            so->addr_high != 0
                               ? hex_string_custom (
-                                  (LONGEST) so->textsection->endaddr,
+                                  (LONGEST) so->addr_high,
                                   addr_width - 4)
                               : "");
          printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No");
@@ -832,7 +848,7 @@ clear_solib (void)
      So: disable breakpoints only if we're using ELF shared libs.  */
   if (exec_bfd != NULL
       && bfd_get_flavour (exec_bfd) != bfd_target_aout_flavour)
-    disable_breakpoints_in_shlibs (1);
+    disable_breakpoints_in_shlibs ();
 
   while (so_list_head)
     {
@@ -846,13 +862,6 @@ clear_solib (void)
   ops->clear_solib ();
 }
 
-static void
-do_clear_solib (void *dummy)
-{
-  solib_cleanup_queued = 0;
-  clear_solib ();
-}
-
 /* GLOBAL FUNCTION
 
    solib_create_inferior_hook -- shared library startup support
@@ -935,7 +944,7 @@ void
 no_shared_libraries (char *ignored, int from_tty)
 {
   objfile_purge_solibs ();
-  do_clear_solib (NULL);
+  clear_solib ();
 }
 
 static void
@@ -955,6 +964,25 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
 }
 
 
+/* Handler for library-specific lookup of global symbol NAME in OBJFILE.  Call
+   the library-specific handler if it is installed for the current target.  */
+
+struct symbol *
+solib_global_lookup (const struct objfile *objfile,
+                    const char *name,
+                    const char *linkage_name,
+                    const domain_enum domain,
+                    struct symtab **symtab)
+{
+  struct target_so_ops *ops = solib_ops (current_gdbarch);
+
+  if (ops->lookup_lib_global_symbol != NULL)
+    return ops->lookup_lib_global_symbol (objfile, name, linkage_name,
+                                         domain, symtab);
+  return NULL;
+}
+
+
 extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
 
 void
This page took 0.027046 seconds and 4 git commands to generate.