[PATCH v2 34/42] Move signatured_type::type to unshareable object

Simon Marchi
2020-05-12T21:17:47Z

From: Tom Tromey <tom@tromey.com>

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.

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.
---
gdb/dwarf2/read.c | 27 ++++++++++++++++++++++++---
gdb/dwarf2/read.h | 17 ++++++++++-------
2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9a9fd05ec26..853dd5884a4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9592,6 +9592,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. */

@@ -22680,8 +22699,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);
@@ -22708,7 +22728,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;
}
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 13d31a97d3d..3500b0e7ba9 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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 @@ struct dwarf2_per_objfile

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;
--
2.26.2