diff options
author | Yao Qi <yao.qi@linaro.org> | 2018-02-16 16:20:58 +0000 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2018-02-16 16:20:58 +0000 |
commit | fd90ace4c1e77c94e90d2942cebe84e9a2019c0f (patch) | |
tree | 238171dee65bdaa736aadcc8413208f70f084a54 /gdb/gdbtypes.c | |
parent | 75cdede09952b5aa8c6d4ceb0de10c5e93002a6d (diff) | |
download | gdb-fd90ace4c1e77c94e90d2942cebe84e9a2019c0f.zip gdb-fd90ace4c1e77c94e90d2942cebe84e9a2019c0f.tar.gz gdb-fd90ace4c1e77c94e90d2942cebe84e9a2019c0f.tar.bz2 |
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.
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r-- | gdb/gdbtypes.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 79bb659..b3a0379 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -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 |