* objfiles.c (objfiles_bfd_data): New global.
(get_objfile_bfd_data, free_objfile_per_bfd_storage)
(objfile_bfd_data_free, set_objfile_per_bfd): New functions.
(allocate_objfile, free_objfile): Update.
(_initialize_objfiles): Initialize objfiles_bfd_data.
* objfiles.h (struct objfile_per_bfd_storage): New.
(struct objfile) <per_bfd>: New field.
<filename_cache>: Remove.
(set_objfile_per_bfd): Declare.
* symfile.c (reread_symbols): Update. Call
set_objfile_per_bfd.
(allocate_symtab): Update.
* symmisc.c (print_symbol_bcache_statistics): Update.
(print_objfile_statistics): Print the size of the BFD obstack.
gdb/testsuite
* gdb.base/maint.exp: Update.
+2012-08-22 Tom Tromey <tromey@redhat.com>
+
+ * elfread.c (elf_symtab_read): Update.
+ * objfiles.c (objfiles_bfd_data): New global.
+ (get_objfile_bfd_data, free_objfile_per_bfd_storage)
+ (objfile_bfd_data_free, set_objfile_per_bfd): New functions.
+ (allocate_objfile, free_objfile): Update.
+ (_initialize_objfiles): Initialize objfiles_bfd_data.
+ * objfiles.h (struct objfile_per_bfd_storage): New.
+ (struct objfile) <per_bfd>: New field.
+ <filename_cache>: Remove.
+ (set_objfile_per_bfd): Declare.
+ * symfile.c (reread_symbols): Update. Call
+ set_objfile_per_bfd.
+ (allocate_symtab): Update.
+ * symmisc.c (print_symbol_bcache_statistics): Update.
+ (print_objfile_statistics): Print the size of the BFD obstack.
+
2012-08-22 Tom Tromey <tromey@redhat.com>
* gdb_bfd.h: Include registry.h. Use DECLARE_REGISTRY.
}
filesym = sym;
filesymname = bcache (filesym->name, strlen (filesym->name) + 1,
- objfile->filename_cache);
+ objfile->per_bfd->filename_cache);
}
else if (sym->flags & BSF_SECTION_SYM)
continue;
return info;
}
+\f
+
+/* Per-BFD data key. */
+
+static const struct bfd_data *objfiles_bfd_data;
+
+/* Create the per-BFD storage object for OBJFILE. If ABFD is not
+ NULL, and it already has a per-BFD storage object, use that.
+ Otherwise, allocate a new per-BFD storage object. If ABFD is not
+ NULL, the object is allocated on the BFD; otherwise it is allocated
+ on OBJFILE's obstack. Note that it is not safe to call this
+ multiple times for a given OBJFILE -- it can only be called when
+ allocating or re-initializing OBJFILE. */
+
+static struct objfile_per_bfd_storage *
+get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
+{
+ struct objfile_per_bfd_storage *storage = NULL;
+
+ if (abfd != NULL)
+ storage = bfd_data (abfd, objfiles_bfd_data);
+
+ if (storage == NULL)
+ {
+ if (abfd != NULL)
+ {
+ storage = bfd_zalloc (abfd, sizeof (struct objfile_per_bfd_storage));
+ set_bfd_data (abfd, objfiles_bfd_data, storage);
+ }
+ else
+ storage = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct objfile_per_bfd_storage);
+
+ obstack_init (&storage->storage_obstack);
+ storage->filename_cache = bcache_xmalloc (NULL, NULL);
+ }
+
+ return storage;
+}
+
+/* Free STORAGE. */
+
+static void
+free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
+{
+ bcache_xfree (storage->filename_cache);
+ obstack_free (&storage->storage_obstack, 0);
+}
+
+/* A wrapper for free_objfile_per_bfd_storage that can be passed as a
+ cleanup function to the BFD registry. */
+
+static void
+objfile_bfd_data_free (struct bfd *unused, void *d)
+{
+ free_objfile_per_bfd_storage (d);
+}
+
+/* See objfiles.h. */
+
+void
+set_objfile_per_bfd (struct objfile *objfile)
+{
+ objfile->per_bfd = get_objfile_bfd_data (objfile, objfile->obfd);
+}
+
+\f
+
/* Called via bfd_map_over_sections to build up the section table that
the objfile references. The objfile contains pointers to the start
of the table (objfile->sections) and to the first location after
objfile = (struct objfile *) xzalloc (sizeof (struct objfile));
objfile->psymbol_cache = psymbol_bcache_init ();
objfile->macro_cache = bcache_xmalloc (NULL, NULL);
- objfile->filename_cache = bcache_xmalloc (NULL, NULL);
/* We could use obstack_specify_allocation here instead, but
gdb_obstack.h specifies the alloc/dealloc functions. */
obstack_init (&objfile->objfile_obstack);
objfile->name = xstrdup ("<<anonymous objfile>>");
}
+ objfile->per_bfd = get_objfile_bfd_data (objfile, abfd);
objfile->pspace = current_program_space;
/* Initialize the section indexes for this objfile, so that we can
still may reference objfile->obfd. */
objfile_free_data (objfile);
- gdb_bfd_unref (objfile->obfd);
+ if (objfile->obfd)
+ gdb_bfd_unref (objfile->obfd);
+ else
+ free_objfile_per_bfd_storage (objfile->per_bfd);
/* Remove it from the chain of all objfiles. */
/* Free the obstacks for non-reusable objfiles. */
psymbol_bcache_free (objfile->psymbol_cache);
bcache_xfree (objfile->macro_cache);
- bcache_xfree (objfile->filename_cache);
if (objfile->demangled_names_hash)
htab_delete (objfile->demangled_names_hash);
obstack_free (&objfile->objfile_obstack, 0);
objfiles_pspace_data
= register_program_space_data_with_cleanup (NULL,
objfiles_pspace_data_cleanup);
+
+ objfiles_bfd_data = register_bfd_data_with_cleanup (NULL,
+ objfile_bfd_data_free);
}
/* Number of entries in the minimal symbol hash table. */
#define MINIMAL_SYMBOL_HASH_SIZE 2039
+/* Some objfile data is hung off the BFD. This enables sharing of the
+ data across all objfiles using the BFD. The data is stored in an
+ instance of this structure, and associated with the BFD using the
+ registry system. */
+
+struct objfile_per_bfd_storage
+{
+ /* The storage has an obstack of its own. */
+
+ struct obstack storage_obstack;
+
+ /* Byte cache for file names. */
+
+ struct bcache *filename_cache;
+};
+
/* Master structure for keeping track of each file from which
gdb reads symbols. There are several ways these get allocated: 1.
The main symbol file, symfile_objfile, set by the symbol-file command,
bfd *obfd;
+ /* The per-BFD data. Note that this is treated specially if OBFD
+ is NULL. */
+
+ struct objfile_per_bfd_storage *per_bfd;
+
/* The gdbarch associated with the BFD. Note that this gdbarch is
determined solely from BFD information, without looking at target
information. The gdbarch determined from a running target may
struct psymbol_bcache *psymbol_cache; /* Byte cache for partial syms. */
struct bcache *macro_cache; /* Byte cache for macros. */
- struct bcache *filename_cache; /* Byte cache for file names. */
/* Hash table for mapping symbol names to demangled names. Each
entry in the hash table is actually two consecutive strings,
#define MULTI_OBJFILE_P() (object_files && object_files->next)
+/* Reset the per-BFD storage area on OBJ. */
+
+void set_objfile_per_bfd (struct objfile *obj);
+
#endif /* !defined (OBJFILES_H) */
objfile->psymbol_cache = psymbol_bcache_init ();
bcache_xfree (objfile->macro_cache);
objfile->macro_cache = bcache_xmalloc (NULL, NULL);
- bcache_xfree (objfile->filename_cache);
- objfile->filename_cache = bcache_xmalloc (NULL,NULL);
if (objfile->demangled_names_hash != NULL)
{
htab_delete (objfile->demangled_names_hash);
memset (&objfile->msymbol_demangled_hash, 0,
sizeof (objfile->msymbol_demangled_hash));
+ set_objfile_per_bfd (objfile);
+
/* obstack_init also initializes the obstack so it is
empty. We could use obstack_specify_allocation but
gdb_obstack.h specifies the alloc/dealloc functions. */
obstack_alloc (&objfile->objfile_obstack, sizeof (struct symtab));
memset (symtab, 0, sizeof (*symtab));
symtab->filename = (char *) bcache (filename, strlen (filename) + 1,
- objfile->filename_cache);
+ objfile->per_bfd->filename_cache);
symtab->fullname = NULL;
symtab->language = deduce_language_from_filename (filename);
symtab->debugformat = "unknown";
print_bcache_statistics (psymbol_bcache_get_bcache (objfile->psymbol_cache),
"partial symbol cache");
print_bcache_statistics (objfile->macro_cache, "preprocessor macro cache");
- print_bcache_statistics (objfile->filename_cache, "file name cache");
+ print_bcache_statistics (objfile->per_bfd->filename_cache,
+ "file name cache");
}
}
OBJSTAT (objfile, sz_strtab));
printf_filtered (_(" Total memory used for objfile obstack: %d\n"),
obstack_memory_used (&objfile->objfile_obstack));
+ printf_filtered (_(" Total memory used for BFD obstack: %d\n"),
+ obstack_memory_used (&objfile->per_bfd->storage_obstack));
printf_filtered (_(" Total memory used for psymbol cache: %d\n"),
bcache_memory_used (psymbol_bcache_get_bcache
(objfile->psymbol_cache)));
printf_filtered (_(" Total memory used for macro cache: %d\n"),
bcache_memory_used (objfile->macro_cache));
printf_filtered (_(" Total memory used for file name cache: %d\n"),
- bcache_memory_used (objfile->filename_cache));
+ bcache_memory_used (objfile->per_bfd->filename_cache));
}
}
+2012-08-22 Tom Tromey <tromey@redhat.com>
+
+ * gdb.base/maint.exp: Update.
+
2012-08-22 Tom Tromey <tromey@redhat.com>
* lib/gdb.exp (skip_unwinder_tests): New proc.
send_gdb "maint print statistics\n"
gdb_expect {
- -re "Statistics for\[^\n\r\]*break\[^\n\r\]*:\r\n Number of \"minimal\" symbols read: $decimal\r\n Number of \"partial\" symbols read: $decimal\r\n Number of \"full\" symbols read: $decimal\r\n Number of \"types\" defined: $decimal\r\n Number of psym tables \\(not yet expanded\\): $decimal\r\n Number of symbol tables: $decimal\r\n Number of symbol tables with line tables: $decimal\r\n Number of symbol tables with blockvectors: $decimal\r\n Total memory used for objfile obstack: $decimal\r\n Total memory used for psymbol cache: $decimal\r\n Total memory used for macro cache: $decimal\r\n Total memory used for file name cache: $decimal\r\n" {
+ -re "Statistics for\[^\n\r\]*break\[^\n\r\]*:\r\n Number of \"minimal\" symbols read: $decimal\r\n Number of \"partial\" symbols read: $decimal\r\n Number of \"full\" symbols read: $decimal\r\n Number of \"types\" defined: $decimal\r\n Number of psym tables \\(not yet expanded\\): $decimal\r\n Number of symbol tables: $decimal\r\n Number of symbol tables with line tables: $decimal\r\n Number of symbol tables with blockvectors: $decimal\r\n Total memory used for objfile obstack: $decimal\r\n Total memory used for BFD obstack: $decimal\r\n Total memory used for psymbol cache: $decimal\r\n Total memory used for macro cache: $decimal\r\n Total memory used for file name cache: $decimal\r\n" {
gdb_expect {
-re "$gdb_prompt $" {
pass "maint print statistics"