mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 09:08:59 +00:00
Fix assertion failure in copy_type
PR exp/20630 points out a simple way to cause an assertion failure in copy_type -- but this was found in the wild a few times as well. copy_type only works for objfile-owned types, but there isn't a deep reason for this. This patch fixes the bug by updating copy_type to work for any sort of type. Better would perhaps be to finally implement type GC, but I still haven't attempted this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20630
This commit is contained in:
@@ -5796,27 +5796,24 @@ copy_type_recursive (struct objfile *objfile,
|
||||
}
|
||||
|
||||
/* Make a copy of the given TYPE, except that the pointer & reference
|
||||
types are not preserved.
|
||||
|
||||
This function assumes that the given type has an associated objfile.
|
||||
This objfile is used to allocate the new type. */
|
||||
types are not preserved. */
|
||||
|
||||
struct type *
|
||||
copy_type (const struct type *type)
|
||||
{
|
||||
struct type *new_type;
|
||||
|
||||
gdb_assert (type->is_objfile_owned ());
|
||||
|
||||
new_type = alloc_type_copy (type);
|
||||
struct type *new_type = alloc_type_copy (type);
|
||||
new_type->set_instance_flags (type->instance_flags ());
|
||||
TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
|
||||
memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
|
||||
sizeof (struct main_type));
|
||||
if (type->main_type->dyn_prop_list != NULL)
|
||||
new_type->main_type->dyn_prop_list
|
||||
= copy_dynamic_prop_list (&type->objfile_owner ()->objfile_obstack,
|
||||
type->main_type->dyn_prop_list);
|
||||
{
|
||||
struct obstack *storage = (type->is_objfile_owned ()
|
||||
? &type->objfile_owner ()->objfile_obstack
|
||||
: gdbarch_obstack (type->arch_owner ()));
|
||||
new_type->main_type->dyn_prop_list
|
||||
= copy_dynamic_prop_list (storage, type->main_type->dyn_prop_list);
|
||||
}
|
||||
|
||||
return new_type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user