/* Externally visible variables that are owned by this module.
See declarations in objfile.h for more info. */
-struct objfile *object_files; /* Linked list of all objfiles */
struct objfile *current_objfile; /* For symbol file being read in */
-struct objfile *symfile_objfile; /* Main symbol table loaded from */
struct objfile *rt_common_objfile; /* For runtime common symbols */
+struct objfile_pspace_info
+{
+ int objfiles_changed_p;
+ struct obj_section **sections;
+ int num_sections;
+};
+
+/* Per-program-space data key. */
+static const struct program_space_data *objfiles_pspace_data;
+
+static void
+objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg)
+{
+ struct objfile_pspace_info *info;
+
+ info = program_space_data (pspace, objfiles_pspace_data);
+ if (info != NULL)
+ {
+ xfree (info->sections);
+ xfree (info);
+ }
+}
+
+/* Get the current svr4 data. If none is found yet, add it now. This
+ function always returns a valid object. */
+
+static struct objfile_pspace_info *
+get_objfile_pspace_data (struct program_space *pspace)
+{
+ struct objfile_pspace_info *info;
+
+ info = program_space_data (pspace, objfiles_pspace_data);
+ if (info == NULL)
+ {
+ info = XZALLOC (struct objfile_pspace_info);
+ set_program_space_data (pspace, objfiles_pspace_data, info);
+ }
+
+ return info;
+}
+
/* Records whether any objfiles appeared or disappeared since we last updated
address to obj section map. */
-static int objfiles_changed_p;
-
/* Locate all mappable sections of a BFD file.
objfile_p_char is a char * to get it through
bfd_map_over_sections; we cast it back to its proper type. */
objfile->name = xstrdup ("<<anonymous objfile>>");
}
+ objfile->pspace = current_program_space;
+
/* Initialize the section indexes for this objfile, so that we can
later detect if they are used w/o being properly assigned to. */
/* Save passed in flag bits. */
objfile->flags |= flags;
- objfiles_changed_p = 1; /* Rebuild section map next time we need it. */
+ /* Rebuild section map next time we need it. */
+ get_objfile_pspace_data (objfile->pspace)->objfiles_changed_p = 1;
- return (objfile);
+ return objfile;
}
/* Retrieve the gdbarch associated with OBJFILE. */
if (objfile->demangled_names_hash)
htab_delete (objfile->demangled_names_hash);
obstack_free (&objfile->objfile_obstack, 0);
+
+ /* Rebuild section map next time we need it. */
+ get_objfile_pspace_data (objfile->pspace)->objfiles_changed_p = 1;
+
xfree (objfile);
- objfile = NULL;
- objfiles_changed_p = 1; /* Rebuild section map next time we need it. */
}
static void
}
/* Rebuild section map next time we need it. */
- objfiles_changed_p = 1;
+ get_objfile_pspace_data (objfile->pspace)->objfiles_changed_p = 1;
/* Update the table in exec_ops, used to read memory. */
ALL_OBJFILE_OSECTIONS (objfile, s)
TLS, overlay and overlapping sections. */
static void
-update_section_map (struct obj_section ***pmap, int *pmap_size)
+update_section_map (struct program_space *pspace,
+ struct obj_section ***pmap, int *pmap_size)
{
int alloc_size, map_size, i;
struct obj_section *s, **map;
struct objfile *objfile;
- gdb_assert (objfiles_changed_p != 0);
+ gdb_assert (get_objfile_pspace_data (pspace)->objfiles_changed_p != 0);
map = *pmap;
xfree (map);
alloc_size = 0;
- ALL_OBJSECTIONS (objfile, s)
- if (insert_section_p (objfile->obfd, s->the_bfd_section))
- alloc_size += 1;
+ ALL_PSPACE_OBJFILES (pspace, objfile)
+ ALL_OBJFILE_OSECTIONS (objfile, s)
+ if (insert_section_p (objfile->obfd, s->the_bfd_section))
+ alloc_size += 1;
map = xmalloc (alloc_size * sizeof (*map));
i = 0;
- ALL_OBJSECTIONS (objfile, s)
- if (insert_section_p (objfile->obfd, s->the_bfd_section))
- map[i++] = s;
+ ALL_PSPACE_OBJFILES (pspace, objfile)
+ ALL_OBJFILE_OSECTIONS (objfile, s)
+ if (insert_section_p (objfile->obfd, s->the_bfd_section))
+ map[i++] = s;
qsort (map, alloc_size, sizeof (*map), qsort_cmp);
map_size = filter_debuginfo_sections(map, alloc_size);
struct obj_section *
find_pc_section (CORE_ADDR pc)
{
- static struct obj_section **sections;
- static int num_sections;
-
+ struct objfile_pspace_info *pspace_info;
struct obj_section *s, **sp;
/* Check for mapped overlay section first. */
if (s)
return s;
- if (objfiles_changed_p != 0)
+ pspace_info = get_objfile_pspace_data (current_program_space);
+ if (pspace_info->objfiles_changed_p != 0)
{
- update_section_map (§ions, &num_sections);
+ update_section_map (current_program_space,
+ &pspace_info->sections,
+ &pspace_info->num_sections);
- /* Don't need updates to section map until objfiles are added
- or removed. */
- objfiles_changed_p = 0;
+ /* Don't need updates to section map until objfiles are added,
+ removed or relocated. */
+ pspace_info->objfiles_changed_p = 0;
}
- sp = (struct obj_section **) bsearch (&pc, sections, num_sections,
- sizeof (*sections), bsearch_cmp);
+ sp = (struct obj_section **) bsearch (&pc,
+ pspace_info->sections,
+ pspace_info->num_sections,
+ sizeof (*pspace_info->sections),
+ bsearch_cmp);
if (sp != NULL)
return *sp;
return NULL;
void
objfiles_changed (void)
{
- objfiles_changed_p = 1; /* Rebuild section map next time we need it. */
+ /* Rebuild section map next time we need it. */
+ get_objfile_pspace_data (current_program_space)->objfiles_changed_p = 1;
}
/* Add reference to ABFD. Returns ABFD. */
name, bfd_errmsg (bfd_get_error ()));
xfree (name);
}
+
+/* Provide a prototype to silence -Wmissing-prototypes. */
+extern initialize_file_ftype _initialize_objfiles;
+
+void
+_initialize_objfiles (void)
+{
+ objfiles_pspace_data
+ = register_program_space_data_with_cleanup (objfiles_pspace_data_cleanup);
+}