/* Trivial helpers for the libiberty hash table, for mapping one
type to another. */
-struct type_pair : public allocate_on_obstack
+struct type_pair
{
type_pair (struct type *old_, struct type *newobj_)
: old (old_), newobj (newobj_)
}
/* Allocate the hash table used by copy_type_recursive to walk
- types without duplicates. We use OBJFILE's obstack, because
- OBJFILE is about to be deleted. */
+ types without duplicates. */
htab_up
-create_copied_types_hash (struct objfile *objfile)
+create_copied_types_hash ()
{
- return htab_up (htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
- NULL, &objfile->objfile_obstack,
- hashtab_obstack_allocate,
- dummy_obstack_deallocate));
+ return htab_up (htab_create_alloc (1, type_pair_hash, type_pair_eq,
+ htab_delete_entry<type_pair>,
+ xcalloc, xfree));
}
/* Recursively copy (deep copy) a dynamic attribute list of a type. */
static struct dynamic_prop_list *
-copy_dynamic_prop_list (struct obstack *objfile_obstack,
+copy_dynamic_prop_list (struct obstack *storage,
struct dynamic_prop_list *list)
{
struct dynamic_prop_list *copy = list;
struct dynamic_prop_list *node_copy;
node_copy = ((struct dynamic_prop_list *)
- obstack_copy (objfile_obstack, *node_ptr,
+ obstack_copy (storage, *node_ptr,
sizeof (struct dynamic_prop_list)));
node_copy->prop = (*node_ptr)->prop;
*node_ptr = node_copy;
it is not associated with OBJFILE. */
struct type *
-copy_type_recursive (struct objfile *objfile,
- struct type *type,
- htab_t copied_types)
+copy_type_recursive (struct type *type, htab_t copied_types)
{
void **slot;
struct type *new_type;
if (!type->is_objfile_owned ())
return type;
- /* This type shouldn't be pointing to any types in other objfiles;
- if it did, the type might disappear unexpectedly. */
- gdb_assert (type->objfile_owner () == objfile);
-
struct type_pair pair (type, nullptr);
slot = htab_find_slot (copied_types, &pair, INSERT);
/* We must add the new type to the hash table immediately, in case
we encounter this type again during a recursive call below. */
- struct type_pair *stored
- = new (&objfile->objfile_obstack) struct type_pair (type, new_type);
+ struct type_pair *stored = new type_pair (type, new_type);
*slot = stored;
TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
if (type->field (i).type ())
new_type->field (i).set_type
- (copy_type_recursive (objfile, type->field (i).type (),
- copied_types));
+ (copy_type_recursive (type->field (i).type (), copied_types));
if (type->field (i).name ())
new_type->field (i).set_name (xstrdup (type->field (i).name ()));
if (type->main_type->dyn_prop_list != NULL)
new_type->main_type->dyn_prop_list
- = copy_dynamic_prop_list (&objfile->objfile_obstack,
+ = copy_dynamic_prop_list (gdbarch_obstack (new_type->arch_owner ()),
type->main_type->dyn_prop_list);
/* Copy pointers to other types. */
if (TYPE_TARGET_TYPE (type))
TYPE_TARGET_TYPE (new_type) =
- copy_type_recursive (objfile,
- TYPE_TARGET_TYPE (type),
- copied_types);
+ copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types);
/* Maybe copy the type_specific bits.
break;
case TYPE_SPECIFIC_SELF_TYPE:
set_type_self_type (new_type,
- copy_type_recursive (objfile, TYPE_SELF_TYPE (type),
+ copy_type_recursive (TYPE_SELF_TYPE (type),
copied_types));
break;
case TYPE_SPECIFIC_FIXED_POINT:
htab_t copied_types)
{
if (value->type->objfile_owner () == objfile)
- value->type = copy_type_recursive (objfile, value->type, copied_types);
+ value->type = copy_type_recursive (value->type, copied_types);
if (value->enclosing_type->objfile_owner () == objfile)
- value->enclosing_type = copy_type_recursive (objfile,
- value->enclosing_type,
+ value->enclosing_type = copy_type_recursive (value->enclosing_type,
copied_types);
}
if (var->u.integer.type
&& var->u.integer.type->objfile_owner () == objfile)
var->u.integer.type
- = copy_type_recursive (objfile, var->u.integer.type, copied_types);
+ = copy_type_recursive (var->u.integer.type, copied_types);
break;
case INTERNALVAR_VALUE:
&& varobj->type->objfile_owner () == objfile)
{
varobj->type
- = copy_type_recursive (objfile, varobj->type, copied_types);
+ = copy_type_recursive (varobj->type, copied_types);
}
if (varobj->value != nullptr)
/* Create the hash table. We allocate on the objfile's obstack, since
it is soon to be deleted. */
- htab_up copied_types = create_copied_types_hash (objfile);
+ htab_up copied_types = create_copied_types_hash ();
for (const value_ref_ptr &item : value_history)
preserve_one_value (item.get (), objfile, copied_types.get ());