New class allocate_on_obstack

This patch adds a new class allocate_on_obstack, and let dwarf2_per_objfile
inherit it, so that dwarf2_per_objfile is automatically allocated on
obstack, and "delete dwarf2_per_objfile" doesn't de-allocate any space.

gdb:

2018-02-16  Yao Qi  <yao.qi@linaro.org>

	* block.c (block_namespace_info): Inherit allocate_on_obstack.
	(block_initialize_namespace): Use new.
	* dwarf2read.c (dwarf2_per_objfile): Inherit allocate_on_obstack.
	(dwarf2_free_objfile): Use delete.
	* gdbtypes.c (type_pair): Inherit allocate_on_obstack.
	(copy_type_recursive): Use new.
	* gdb_obstack.h (allocate_on_obstack): New.
This commit is contained in:
Yao Qi 2018-02-16 16:20:58 +00:00
parent 75cdede099
commit fd90ace4c1
5 changed files with 50 additions and 24 deletions

View file

@ -4699,9 +4699,13 @@ recursive_dump_type (struct type *type, int spaces)
/* Trivial helpers for the libiberty hash table, for mapping one
type to another. */
struct type_pair
struct type_pair : public allocate_on_obstack
{
struct type *old, *newobj;
type_pair (struct type *old_, struct type *newobj_)
: old (old_), newobj (newobj_)
{}
struct type * const old, * const newobj;
};
static hashval_t
@ -4769,7 +4773,6 @@ copy_type_recursive (struct objfile *objfile,
struct type *type,
htab_t copied_types)
{
struct type_pair *stored, pair;
void **slot;
struct type *new_type;
@ -4780,7 +4783,8 @@ copy_type_recursive (struct objfile *objfile,
if it did, the type might disappear unexpectedly. */
gdb_assert (TYPE_OBJFILE (type) == objfile);
pair.old = type;
struct type_pair pair (type, nullptr);
slot = htab_find_slot (copied_types, &pair, INSERT);
if (*slot != NULL)
return ((struct type_pair *) *slot)->newobj;
@ -4789,9 +4793,9 @@ copy_type_recursive (struct objfile *objfile,
/* We must add the new type to the hash table immediately, in case
we encounter this type again during a recursive call below. */
stored = XOBNEW (&objfile->objfile_obstack, struct type_pair);
stored->old = type;
stored->newobj = new_type;
struct type_pair *stored
= new (&objfile->objfile_obstack) struct type_pair (type, new_type);
*slot = stored;
/* Copy the common fields of types. For the main type, we simply