Add dwarf2_per_objfile field to dwarf2_cu

Subsequent patches will make dwarf2_per_cu_data objfile-independent.
This means that the dwarf2_per_cu_data::dwarf2_per_objfile field must
go.

The code using a dwarf2_cu structure currently accesses the current
dwarf2_per_objfile object through dwarf2_cu->per_cu->dwarf2_per_objfile.
Since it's ok for the dwarf2_cu to know about the current objfile (a
dwarf2_cu is always used in the context of a particular objfile), add a
dwarf2_per_objfile field to dwarf2_cu.  Upcoming patches will gradually
remove uses of dwarf2_per_cu_data::dwarf2_per_objfile in favor of
dwarf2_cu::dwarf2_per_objfile, until the former can be removed.

gdb/ChangeLog:

	* dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter.
	<per_objfile>: New member.
	(class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter.
	(cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update
	call to dwarf2_cu.
	(cutu_reader::cutu_reader): Update.
	(dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile.

Change-Id: I8fd0da7371f65baea1ea7787aad08e10453bc565
This commit is contained in:
Simon Marchi 2020-05-27 11:13:52 -04:00
parent ae090bdbf8
commit 9e021579fa
2 changed files with 28 additions and 10 deletions

View File

@ -1,3 +1,13 @@
2020-05-27 Simon Marchi <simon.marchi@efficios.com>
* dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter.
<per_objfile>: New member.
(class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter.
(cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update
call to dwarf2_cu.
(cutu_reader::cutu_reader): Update.
(dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile.
2020-05-27 Simon Marchi <simon.marchi@efficios.com>
* dwarf2/read.h (struct dwarf2_per_bfd) <die_type_hash>: Move to

View File

@ -399,7 +399,8 @@ struct delayed_method_info
/* Internal state when decoding a particular compilation unit. */
struct dwarf2_cu
{
explicit dwarf2_cu (struct dwarf2_per_cu_data *per_cu);
explicit dwarf2_cu (dwarf2_per_cu_data *per_cu,
dwarf2_per_objfile *per_objfile);
~dwarf2_cu ();
DISABLE_COPY_AND_ASSIGN (dwarf2_cu);
@ -466,6 +467,9 @@ public:
/* Backlink to our per_cu entry. */
struct dwarf2_per_cu_data *per_cu;
/* The dwarf2_per_objfile that owns this. */
struct dwarf2_per_objfile *per_objfile;
/* How many compilation units ago was this CU last referenced? */
int last_used = 0;
@ -928,7 +932,8 @@ public:
void keep ();
private:
void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
void init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
dwarf2_per_objfile *per_objfile,
int use_existing_cu);
struct dwarf2_per_cu_data *m_this_cu;
@ -6888,7 +6893,8 @@ lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
Read a TU directly from a DWO file, bypassing the stub. */
void
cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
dwarf2_per_objfile *per_objfile,
int use_existing_cu)
{
struct signatured_type *sig_type;
@ -6909,7 +6915,7 @@ cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
{
/* If !use_existing_cu, this_cu->cu must be NULL. */
gdb_assert (this_cu->cu == NULL);
m_new_cu.reset (new dwarf2_cu (this_cu));
m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
}
/* A future optimization, if needed, would be to use an existing
@ -6970,7 +6976,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
/* Narrow down the scope of possibilities to have to understand. */
gdb_assert (this_cu->is_debug_types);
gdb_assert (abbrev_table == NULL);
init_tu_and_read_dwo_dies (this_cu, use_existing_cu);
init_tu_and_read_dwo_dies (this_cu, dwarf2_per_objfile, use_existing_cu);
return;
}
@ -6997,7 +7003,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
{
/* If !use_existing_cu, this_cu->cu must be NULL. */
gdb_assert (this_cu->cu == NULL);
m_new_cu.reset (new dwarf2_cu (this_cu));
m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
cu = m_new_cu.get ();
}
@ -7189,7 +7195,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
/* This is cheap if the section is already read in. */
section->read (objfile);
m_new_cu.reset (new dwarf2_cu (this_cu));
m_new_cu.reset (new dwarf2_cu (this_cu, dwarf2_per_objfile));
begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
@ -23514,10 +23520,12 @@ run_test ()
#endif /* GDB_SELF_TEST */
/* Initialize dwarf2_cu CU, owned by PER_CU. */
/* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data *per_cu_)
: per_cu (per_cu_),
dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu,
dwarf2_per_objfile *per_objfile)
: per_cu (per_cu),
per_objfile (per_objfile),
mark (false),
has_loclist (false),
checked_producer (false),