mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-29 15:18:34 +08:00
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:
@ -1,3 +1,13 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2018-02-15 Yao Qi <yao.qi@linaro.org>
|
2018-02-15 Yao Qi <yao.qi@linaro.org>
|
||||||
|
|
||||||
PR gdb/22849
|
PR gdb/22849
|
||||||
|
12
gdb/block.c
12
gdb/block.c
@ -31,10 +31,10 @@
|
|||||||
C++ files, namely using declarations and the current namespace in
|
C++ files, namely using declarations and the current namespace in
|
||||||
scope. */
|
scope. */
|
||||||
|
|
||||||
struct block_namespace_info
|
struct block_namespace_info : public allocate_on_obstack
|
||||||
{
|
{
|
||||||
const char *scope;
|
const char *scope = nullptr;
|
||||||
struct using_direct *using_decl;
|
struct using_direct *using_decl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void block_initialize_namespace (struct block *block,
|
static void block_initialize_namespace (struct block *block,
|
||||||
@ -350,11 +350,7 @@ static void
|
|||||||
block_initialize_namespace (struct block *block, struct obstack *obstack)
|
block_initialize_namespace (struct block *block, struct obstack *obstack)
|
||||||
{
|
{
|
||||||
if (BLOCK_NAMESPACE (block) == NULL)
|
if (BLOCK_NAMESPACE (block) == NULL)
|
||||||
{
|
BLOCK_NAMESPACE (block) = new (obstack) struct block_namespace_info ();
|
||||||
BLOCK_NAMESPACE (block) = XOBNEW (obstack, struct block_namespace_info);
|
|
||||||
BLOCK_NAMESPACE (block)->scope = NULL;
|
|
||||||
BLOCK_NAMESPACE (block)->using_decl = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the static block associated to BLOCK. Return NULL if block
|
/* Return the static block associated to BLOCK. Return NULL if block
|
||||||
|
@ -380,7 +380,7 @@ struct tu_stats
|
|||||||
/* Collection of data recorded per objfile.
|
/* Collection of data recorded per objfile.
|
||||||
This hangs off of dwarf2_objfile_data_key. */
|
This hangs off of dwarf2_objfile_data_key. */
|
||||||
|
|
||||||
struct dwarf2_per_objfile
|
struct dwarf2_per_objfile : public allocate_on_obstack
|
||||||
{
|
{
|
||||||
/* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
|
/* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
|
||||||
dwarf2 section names, or is NULL if the standard ELF names are
|
dwarf2 section names, or is NULL if the standard ELF names are
|
||||||
@ -2525,10 +2525,9 @@ dwarf2_has_info (struct objfile *objfile,
|
|||||||
if (dwarf2_per_objfile == NULL)
|
if (dwarf2_per_objfile == NULL)
|
||||||
{
|
{
|
||||||
/* Initialize per-objfile state. */
|
/* Initialize per-objfile state. */
|
||||||
struct dwarf2_per_objfile *data
|
dwarf2_per_objfile
|
||||||
= XOBNEW (&objfile->objfile_obstack, struct dwarf2_per_objfile);
|
= new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile,
|
||||||
|
names);
|
||||||
dwarf2_per_objfile = new (data) struct dwarf2_per_objfile (objfile, names);
|
|
||||||
set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
|
set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
|
||||||
}
|
}
|
||||||
return (!dwarf2_per_objfile->info.is_virtual
|
return (!dwarf2_per_objfile->info.is_virtual
|
||||||
@ -25202,10 +25201,7 @@ dwarf2_free_objfile (struct objfile *objfile)
|
|||||||
struct dwarf2_per_objfile *dwarf2_per_objfile
|
struct dwarf2_per_objfile *dwarf2_per_objfile
|
||||||
= get_dwarf2_per_objfile (objfile);
|
= get_dwarf2_per_objfile (objfile);
|
||||||
|
|
||||||
if (dwarf2_per_objfile == NULL)
|
delete dwarf2_per_objfile;
|
||||||
return;
|
|
||||||
|
|
||||||
dwarf2_per_objfile->~dwarf2_per_objfile ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
|
/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
|
||||||
|
@ -78,4 +78,24 @@ struct auto_obstack : obstack
|
|||||||
{ obstack_free (this, obstack_base (this)); }
|
{ obstack_free (this, obstack_base (this)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Objects are allocated on obstack instead of heap. */
|
||||||
|
|
||||||
|
struct allocate_on_obstack
|
||||||
|
{
|
||||||
|
allocate_on_obstack () = default;
|
||||||
|
|
||||||
|
void* operator new (size_t size, struct obstack *obstack)
|
||||||
|
{
|
||||||
|
return obstack_alloc (obstack, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* operator new[] (size_t size, struct obstack *obstack)
|
||||||
|
{
|
||||||
|
return obstack_alloc (obstack, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator delete (void *memory) {}
|
||||||
|
void operator delete[] (void *memory) {}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4699,9 +4699,13 @@ recursive_dump_type (struct type *type, int spaces)
|
|||||||
/* Trivial helpers for the libiberty hash table, for mapping one
|
/* Trivial helpers for the libiberty hash table, for mapping one
|
||||||
type to another. */
|
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
|
static hashval_t
|
||||||
@ -4769,7 +4773,6 @@ copy_type_recursive (struct objfile *objfile,
|
|||||||
struct type *type,
|
struct type *type,
|
||||||
htab_t copied_types)
|
htab_t copied_types)
|
||||||
{
|
{
|
||||||
struct type_pair *stored, pair;
|
|
||||||
void **slot;
|
void **slot;
|
||||||
struct type *new_type;
|
struct type *new_type;
|
||||||
|
|
||||||
@ -4780,7 +4783,8 @@ copy_type_recursive (struct objfile *objfile,
|
|||||||
if it did, the type might disappear unexpectedly. */
|
if it did, the type might disappear unexpectedly. */
|
||||||
gdb_assert (TYPE_OBJFILE (type) == objfile);
|
gdb_assert (TYPE_OBJFILE (type) == objfile);
|
||||||
|
|
||||||
pair.old = type;
|
struct type_pair pair (type, nullptr);
|
||||||
|
|
||||||
slot = htab_find_slot (copied_types, &pair, INSERT);
|
slot = htab_find_slot (copied_types, &pair, INSERT);
|
||||||
if (*slot != NULL)
|
if (*slot != NULL)
|
||||||
return ((struct type_pair *) *slot)->newobj;
|
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 must add the new type to the hash table immediately, in case
|
||||||
we encounter this type again during a recursive call below. */
|
we encounter this type again during a recursive call below. */
|
||||||
stored = XOBNEW (&objfile->objfile_obstack, struct type_pair);
|
struct type_pair *stored
|
||||||
stored->old = type;
|
= new (&objfile->objfile_obstack) struct type_pair (type, new_type);
|
||||||
stored->newobj = new_type;
|
|
||||||
*slot = stored;
|
*slot = stored;
|
||||||
|
|
||||||
/* Copy the common fields of types. For the main type, we simply
|
/* Copy the common fields of types. For the main type, we simply
|
||||||
|
Reference in New Issue
Block a user