* emultempl/armelf.em (elf32_arm_add_stub_section): Use
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index 2147328f28b33b20a073f7162f034b428b90423c..235f8ffcb4d00eb0f6bfc5a6dba3ba1abb39d160 100644 (file)
@@ -1,7 +1,7 @@
 /* GDB routines for manipulating objfiles.
 
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
@@ -48,6 +48,8 @@
 #include "dictionary.h"
 #include "source.h"
 #include "addrmap.h"
+#include "arch-utils.h"
+#include "exec.h"
 
 /* Prototypes for local functions */
 
@@ -187,6 +189,9 @@ allocate_objfile (bfd *abfd, int flags)
     }
   if (abfd != NULL)
     {
+      /* Look up the gdbarch associated with the BFD.  */
+      objfile->gdbarch = gdbarch_from_bfd (abfd);
+
       objfile->name = xstrdup (bfd_get_filename (abfd));
       objfile->mtime = bfd_get_mtime (abfd);
 
@@ -234,6 +239,13 @@ allocate_objfile (bfd *abfd, int flags)
   return (objfile);
 }
 
+/* Retrieve the gdbarch associated with OBJFILE.  */
+struct gdbarch *
+get_objfile_arch (struct objfile *objfile)
+{
+  return objfile->gdbarch;
+}
+
 /* Initialize entry point information for this objfile. */
 
 void
@@ -248,6 +260,12 @@ init_entry_point_info (struct objfile *objfile)
          the startup file because it contains the entry point.  */
       objfile->ei.entry_point = bfd_get_start_address (objfile->obfd);
     }
+  else if (bfd_get_file_flags (objfile->obfd) & DYNAMIC
+          && bfd_get_start_address (objfile->obfd) != 0)
+    /* Some shared libraries may have entry points set and be
+       runnable.  There's no clear way to indicate this, so just check
+       for values other than zero.  */
+    objfile->ei.entry_point = bfd_get_start_address (objfile->obfd);    
   else
     {
       /* Examination of non-executable.o files.  Short-circuit this stuff.  */
@@ -515,6 +533,7 @@ free_all_objfiles (void)
 void
 objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
 {
+  struct obj_section *s;
   struct section_offsets *delta =
     ((struct section_offsets *) 
      alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
@@ -578,8 +597,7 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
                 But I'm leaving out that test, on the theory that
                 they can't possibly pass the tests below.  */
              if ((SYMBOL_CLASS (sym) == LOC_LABEL
-                  || SYMBOL_CLASS (sym) == LOC_STATIC
-                  || SYMBOL_CLASS (sym) == LOC_INDIRECT)
+                  || SYMBOL_CLASS (sym) == LOC_STATIC)
                  && SYMBOL_SECTION (sym) >= 0)
                {
                  SYMBOL_VALUE_ADDRESS (sym) +=
@@ -666,6 +684,15 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
       }
   }
 
+  /* Update the table in exec_ops, used to read memory.  */
+  ALL_OBJFILE_OSECTIONS (objfile, s)
+    {
+      int idx = s->the_bfd_section->index;
+
+      exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
+                               s->addr);
+    }
+
   /* Relocate breakpoints as necessary, after things are relocated. */
   breakpoint_re_set ();
 }
@@ -804,6 +831,7 @@ in_plt_section (CORE_ADDR pc, char *name)
 struct objfile_data
 {
   unsigned index;
+  void (*cleanup) (struct objfile *, void *);
 };
 
 struct objfile_data_registration
@@ -821,7 +849,7 @@ struct objfile_data_registry
 static struct objfile_data_registry objfile_data_registry = { NULL, 0 };
 
 const struct objfile_data *
-register_objfile_data (void)
+register_objfile_data_with_cleanup (void (*cleanup) (struct objfile *, void *))
 {
   struct objfile_data_registration **curr;
 
@@ -833,10 +861,17 @@ register_objfile_data (void)
   (*curr)->next = NULL;
   (*curr)->data = XMALLOC (struct objfile_data);
   (*curr)->data->index = objfile_data_registry.num_registrations++;
+  (*curr)->data->cleanup = cleanup;
 
   return (*curr)->data;
 }
 
+const struct objfile_data *
+register_objfile_data (void)
+{
+  return register_objfile_data_with_cleanup (NULL);
+}
+
 static void
 objfile_alloc_data (struct objfile *objfile)
 {
@@ -849,6 +884,7 @@ static void
 objfile_free_data (struct objfile *objfile)
 {
   gdb_assert (objfile->data != NULL);
+  clear_objfile_data (objfile);
   xfree (objfile->data);
   objfile->data = NULL;
 }
@@ -856,7 +892,17 @@ objfile_free_data (struct objfile *objfile)
 void
 clear_objfile_data (struct objfile *objfile)
 {
+  struct objfile_data_registration *registration;
+  int i;
+
   gdb_assert (objfile->data != NULL);
+
+  for (registration = objfile_data_registry.registrations, i = 0;
+       i < objfile->num_data;
+       registration = registration->next, i++)
+    if (objfile->data[i] != NULL && registration->data->cleanup)
+      registration->data->cleanup (objfile, objfile->data[i]);
+
   memset (objfile->data, 0, objfile->num_data * sizeof (void *));
 }
 
This page took 0.036284 seconds and 4 git commands to generate.