* config/tc-hppa.c: Fix comment typos.
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index 90844018fc489d959fee33be88bf0aa27cf1a83f..9ea0dc9ba47f0627b86385912fc3d4b8ee034c1e 100644 (file)
@@ -34,6 +34,7 @@
 #include "target.h"
 #include "bcache.h"
 
+#include "gdb_assert.h"
 #include <sys/types.h>
 #include "gdb_stat.h"
 #include <fcntl.h>
@@ -42,6 +43,8 @@
 #include "hashtab.h"
 
 #include "breakpoint.h"
+#include "block.h"
+#include "dictionary.h"
 
 /* Prototypes for local functions */
 
@@ -57,7 +60,8 @@ static void *map_to_file (int);
 
 #endif /* defined(USE_MMALLOC) && defined(HAVE_MMAP) */
 
-static void add_to_objfile_sections (bfd *, sec_ptr, void *);
+static void objfile_alloc_data (struct objfile *objfile);
+static void objfile_free_data (struct objfile *objfile);
 
 /* Externally visible variables that are owned by this module.
    See declarations in objfile.h for more info. */
@@ -83,7 +87,8 @@ int mapped_symbol_files;      /* Try to use mapped symbol files */
    the end of the table (objfile->sections_end). */
 
 static void
-add_to_objfile_sections (bfd *abfd, sec_ptr asect, void *objfile_p_char)
+add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
+                        void *objfile_p_char)
 {
   struct objfile *objfile = (struct objfile *) objfile_p_char;
   struct obj_section section;
@@ -150,6 +155,15 @@ build_objfile_section_table (struct objfile *objfile)
    OBJF_SHARED are simply copied through to the new objfile flags
    member. */
 
+/* NOTE: carlton/2003-02-04: This function is called with args NULL, 0
+   by jv-lang.c, to create an artificial objfile used to hold
+   information about dynamically-loaded Java classes.  Unfortunately,
+   that branch of this function doesn't get tested very frequently, so
+   it's prone to breakage.  (E.g. at one time the name was set to NULL
+   in that situation, which broke a loop over all names in the dynamic
+   library loader.)  If you change this function, please try to leave
+   things in a consistent state even if abfd is NULL.  */
+
 struct objfile *
 allocate_objfile (bfd *abfd, int flags)
 {
@@ -291,6 +305,8 @@ allocate_objfile (bfd *abfd, int flags)
       terminate_minimal_symbol_table (objfile);
     }
 
+  objfile_alloc_data (objfile);
+
   /* Update the per-objfile information that comes from the bfd, ensuring
      that any data that is reference is saved in the per-objfile data
      region. */
@@ -313,14 +329,22 @@ allocate_objfile (bfd *abfd, int flags)
                 objfile->name, bfd_errmsg (bfd_get_error ()));
        }
     }
+  else
+    {
+      objfile->name = mstrsave (objfile->md, "<<anonymous objfile>>");
+    }
 
   /* Initialize the section indexes for this objfile, so that we can
      later detect if they are used w/o being properly assigned to. */
 
-    objfile->sect_index_text = -1;
-    objfile->sect_index_data = -1;
-    objfile->sect_index_bss = -1;
-    objfile->sect_index_rodata = -1;
+  objfile->sect_index_text = -1;
+  objfile->sect_index_data = -1;
+  objfile->sect_index_bss = -1;
+  objfile->sect_index_rodata = -1;
+
+  /* We don't yet have a C++-specific namespace symtab.  */
+
+  objfile->cp_namespace_symtab = NULL;
 
   /* Add this file onto the tail of the linked list of other such files. */
 
@@ -359,9 +383,10 @@ terminate_minimal_symbol_table (struct objfile *objfile)
       = &objfile->msymbols[objfile->minimal_symbol_count];
 
     memset (m, 0, sizeof (*m));
-    SYMBOL_NAME (m) = NULL;
+    DEPRECATED_SYMBOL_NAME (m) = NULL;
     SYMBOL_VALUE_ADDRESS (m) = 0;
     MSYMBOL_INFO (m) = NULL;
+    MSYMBOL_SIZE (m) = 0;
     MSYMBOL_TYPE (m) = mst_unknown;
     SYMBOL_INIT_LANGUAGE_SPECIFIC (m, language_unknown);
   }
@@ -546,6 +571,7 @@ free_objfile (struct objfile *objfile)
 
   if (objfile != NULL)
     {
+      objfile_free_data (objfile);
       if (objfile->name != NULL)
        {
          xmfree (objfile->md, objfile->name);
@@ -599,7 +625,8 @@ void
 objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
 {
   struct section_offsets *delta =
-    (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
+    ((struct section_offsets *) 
+     alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
 
   {
     int i;
@@ -642,18 +669,18 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
        {
          struct block *b;
          struct symbol *sym;
-         int j;
+         struct dict_iterator iter;
 
          b = BLOCKVECTOR_BLOCK (bv, i);
          BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
          BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
 
-         ALL_BLOCK_SYMBOLS (b, j, sym)
+         ALL_BLOCK_SYMBOLS (b, iter, sym)
            {
              fixup_symbol_section (sym, objfile);
 
              /* The RS6000 code from which this was taken skipped
-                any symbols in STRUCT_NAMESPACE or UNDEF_NAMESPACE.
+                any symbols in STRUCT_DOMAIN or UNDEF_DOMAIN.
                 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
@@ -668,8 +695,8 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
              /* Relocate Extra Function Info for ecoff.  */
 
              else if (SYMBOL_CLASS (sym) == LOC_CONST
-                      && SYMBOL_NAMESPACE (sym) == LABEL_NAMESPACE
-                      && strcmp (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
+                      && SYMBOL_DOMAIN (sym) == LABEL_DOMAIN
+                      && strcmp (DEPRECATED_SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0)
                ecoff_relocate_efi (sym, ANOFFSET (delta,
                                                   s->block_line_section));
 #endif
@@ -760,10 +787,10 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
       objfile->ei.entry_func_highpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
     }
 
-  if (objfile->ei.entry_file_lowpc != INVALID_ENTRY_LOWPC)
+  if (objfile->ei.deprecated_entry_file_lowpc != INVALID_ENTRY_LOWPC)
     {
-      objfile->ei.entry_file_lowpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-      objfile->ei.entry_file_highpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
+      objfile->ei.deprecated_entry_file_lowpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
+      objfile->ei.deprecated_entry_file_highpc += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
     }
 
   if (objfile->ei.main_func_lowpc != INVALID_ENTRY_LOWPC)
@@ -1017,14 +1044,14 @@ map_to_file (int fd)
 
 #endif /* defined(USE_MMALLOC) && defined(HAVE_MMAP) */
 
-/* Returns a section whose range includes PC and SECTION, 
-   or NULL if none found.  Note the distinction between the return type, 
-   struct obj_section (which is defined in gdb), and the input type
-   struct sec (which is a bfd-defined data type).  The obj_section
-   contains a pointer to the bfd struct sec section.  */
+/* Returns a section whose range includes PC and SECTION, or NULL if
+   none found.  Note the distinction between the return type, struct
+   obj_section (which is defined in gdb), and the input type "struct
+   bfd_section" (which is a bfd-defined data type).  The obj_section
+   contains a pointer to the "struct bfd_section".  */
 
 struct obj_section *
-find_pc_sect_section (CORE_ADDR pc, struct sec *section)
+find_pc_sect_section (CORE_ADDR pc, struct bfd_section *section)
 {
   struct obj_section *s;
   struct objfile *objfile;
@@ -1061,7 +1088,7 @@ in_plt_section (CORE_ADDR pc, char *name)
 
   retval = (s != NULL
            && s->the_bfd_section->name != NULL
-           && STREQ (s->the_bfd_section->name, ".plt"));
+           && strcmp (s->the_bfd_section->name, ".plt") == 0);
   return (retval);
 }
 
@@ -1071,7 +1098,7 @@ in_plt_section (CORE_ADDR pc, char *name)
 int
 is_in_import_list (char *name, struct objfile *objfile)
 {
-  register int i;
+  int i;
 
   if (!objfile || !name || !*name)
     return 0;
@@ -1081,4 +1108,81 @@ is_in_import_list (char *name, struct objfile *objfile)
       return 1;
   return 0;
 }
+\f
+
+/* Keep a registry of per-objfile data-pointers required by other GDB
+   modules.  */
+
+struct objfile_data
+{
+  unsigned index;
+};
+
+struct objfile_data_registration
+{
+  struct objfile_data *data;
+  struct objfile_data_registration *next;
+};
+  
+struct objfile_data_registry
+{
+  struct objfile_data_registration *registrations;
+  unsigned num_registrations;
+};
+
+static struct objfile_data_registry objfile_data_registry = { NULL, 0 };
+
+const struct objfile_data *
+register_objfile_data (void)
+{
+  struct objfile_data_registration **curr;
+
+  /* Append new registration.  */
+  for (curr = &objfile_data_registry.registrations;
+       *curr != NULL; curr = &(*curr)->next);
+
+  *curr = XMALLOC (struct objfile_data_registration);
+  (*curr)->next = NULL;
+  (*curr)->data = XMALLOC (struct objfile_data);
+  (*curr)->data->index = objfile_data_registry.num_registrations++;
+
+  return (*curr)->data;
+}
+
+static void
+objfile_alloc_data (struct objfile *objfile)
+{
+  gdb_assert (objfile->data == NULL);
+  objfile->num_data = objfile_data_registry.num_registrations;
+  objfile->data = XCALLOC (objfile->num_data, void *);
+}
+
+static void
+objfile_free_data (struct objfile *objfile)
+{
+  gdb_assert (objfile->data != NULL);
+  xfree (objfile->data);
+  objfile->data = NULL;
+}
 
+void
+clear_objfile_data (struct objfile *objfile)
+{
+  gdb_assert (objfile->data != NULL);
+  memset (objfile->data, 0, objfile->num_data * sizeof (void *));
+}
+
+void
+set_objfile_data (struct objfile *objfile, const struct objfile_data *data,
+                 void *value)
+{
+  gdb_assert (data->index < objfile->num_data);
+  objfile->data[data->index] = value;
+}
+
+void *
+objfile_data (struct objfile *objfile, const struct objfile_data *data)
+{
+  gdb_assert (data->index < objfile->num_data);
+  return objfile->data[data->index];
+}
This page took 0.027463 seconds and 4 git commands to generate.