Move signatured_type::type to unshareable object

signatured_type has a link to the "struct type".  However, types are
inherently objfile-specific, so once sharing is implemented, this will
be incorrect.

This patch moves the type to a new map in the DWARF unshareable
object.

gdb/ChangeLog:

YYYY-MM-DD  Tom Tromey  <tom@tromey.com>
YYYY-MM-DD  Simon Marchi  <simon.marchi@efficios.com>

	* dwarf2/read.h (struct dwarf2_per_objfile)
	<get_type_for_signatured_type, set_type_for_signatured_type>:
	New methods.
	<m_type_map>: New member.
	(struct signatured_type) <type>: Remove.
	* dwarf2/read.c
	(dwarf2_per_objfile::get_type_for_signatured_type,
	dwarf2_per_objfile::set_type_for_signatured_type): New.
	(get_signatured_type): Use new methods.

Change-Id: I765ae3c43fae1064f51ced352167a57638609f02
This commit is contained in:
Tom Tromey 2020-05-27 11:19:35 -04:00 committed by Simon Marchi
parent 8adb84872b
commit e286671bf9
3 changed files with 47 additions and 10 deletions

View File

@ -1,3 +1,16 @@
2020-05-27 Tom Tromey <tom@tromey.com>
Simon Marchi <simon.marchi@efficios.com>
* dwarf2/read.h (struct dwarf2_per_objfile)
<get_type_for_signatured_type, set_type_for_signatured_type>:
New methods.
<m_type_map>: New member.
(struct signatured_type) <type>: Remove.
* dwarf2/read.c
(dwarf2_per_objfile::get_type_for_signatured_type,
dwarf2_per_objfile::set_type_for_signatured_type): New.
(get_signatured_type): Use new methods.
2020-05-27 Tom Tromey <tom@tromey.com>
Simon Marchi <simon.marchi@efficios.com>

View File

@ -9630,6 +9630,25 @@ dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group *tu_group)
return result;
}
struct type *
dwarf2_per_objfile::get_type_for_signatured_type
(signatured_type *sig_type) const
{
auto iter = this->m_type_map.find (sig_type);
if (iter == this->m_type_map.end ())
return nullptr;
return iter->second;
}
void dwarf2_per_objfile::set_type_for_signatured_type
(signatured_type *sig_type, struct type *type)
{
gdb_assert (this->m_type_map.find (sig_type) == this->m_type_map.end ());
this->m_type_map[sig_type] = type;
}
/* A helper function for computing the list of all symbol tables
included by PER_CU. */
@ -22720,8 +22739,9 @@ get_signatured_type (struct die_info *die, ULONGEST signature,
}
/* If we already know the type we're done. */
if (sig_type->type != NULL)
return sig_type->type;
type = dwarf2_per_objfile->get_type_for_signatured_type (sig_type);
if (type != nullptr)
return type;
type_cu = cu;
type_die = follow_die_sig_1 (die, sig_type, &type_cu);
@ -22748,7 +22768,8 @@ get_signatured_type (struct die_info *die, ULONGEST signature,
objfile_name (dwarf2_per_objfile->objfile));
type = build_error_marker_type (cu, die);
}
sig_type->type = type;
dwarf2_per_objfile->set_type_for_signatured_type (sig_type, type);
return type;
}

View File

@ -329,11 +329,16 @@ struct dwarf2_per_objfile
/* Set the compunit_symtab associated to PER_CU. */
void set_symtab (const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab);
/* Get the type_unit_group_unshareable corresponding to TU_GROUP. If one
does not exist, create it. */
/* Get the type_unit_group_unshareable corresponding to TU_GROUP. If one
does not exist, create it. */
type_unit_group_unshareable *get_type_unit_group_unshareable
(type_unit_group *tu_group);
struct type *get_type_for_signatured_type (signatured_type *sig_type) const;
void set_type_for_signatured_type (signatured_type *sig_type,
struct type *type);
/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
UNSIGNED_P controls if the integer is unsigned or not. */
struct type *int_type (int size_in_bytes, bool unsigned_p) const;
@ -363,6 +368,9 @@ private:
std::unordered_map<type_unit_group *, type_unit_group_unshareable_up>
m_type_units;
/* Map from signatured types to the corresponding struct type. */
std::unordered_map<signatured_type *, struct type *> m_type_map;
};
/* Get the dwarf2_per_objfile associated to OBJFILE. */
@ -584,11 +592,6 @@ struct signatured_type
can share them. This points to the containing symtab. */
struct type_unit_group *type_unit_group;
/* The type.
The first time we encounter this type we fully read it in and install it
in the symbol tables. Subsequent times we only need the type. */
struct type *type;
/* Containing DWO unit.
This field is valid iff per_cu.reading_dwo_directly. */
struct dwo_unit *dwo_unit;