• R/O
  • HTTP
  • SSH
  • HTTPS

提交列表

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


users/simark/submit/share-dwarf-partial-symtabs-v2
RSS
Rev. 时间 作者
dd787f5 users/simark/submit/share-dwarf-partial-symtabs-v2 2020-05-13 04:24:51 Tom Tromey

Share DWARF partial symtabs

This changes the DWARF reader to share partial symtabs (or indices if
they are available) across objfiles. This has a few parts.

* If multiple objfiles backed by the same BFD can share partial symtabs
(see below), a single dwarf2_per_bfd is created. It is stored in the
per-bfd `dwarf2_per_bfd_bfd_data_key` registry. Multiple
dwarf2_per_objfile objects will point to the same instance. The
lifetime of these dwarf2_per_bfd objects is naturally handled. When
all the objfiles using the BFD are destroyed, the BFD's refount drops
to 0, which triggers the removal of the corresponding dwarf2_per_bfd
object from the registry and its destruction.

* If multiple objfiles backed by the same BFD can't share partial
symtabs (see below), one dwarf2_per_bfd object is created for each
objfile. Each dwarf2_per_objfile will point to their own instance of
dwarf2_per_bfd. These instances of dwarf2_per_bfd are kept in a
per-objfile registry, meaning that when the objfile gets destroyed,
the dwarf2_per_bfd instance gets destroyed as well.

* objfile::partial_symtabs is changed to be a shared_ptr again. This
lets us stash a second reference in dwarf2_per_bfd; if the DWARF
data is being shared, we can simply copy this value to the new
objfile.

* Two dwarf2_per_objfile objects backed by the same BFD may share a
dwarf2_per_bfd instance if:

* No other symbol reader has found symbols, and
* No BFD section rqeuires relocation

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

* objfiles.h (struct objfile) <partial_symtabs>: Now a
shared_ptr.
* dwarf2/read.h (struct dwarf2_per_objfile) <partial_symtabs>: New
member.
* dwarf2/read.c (dwarf2_per_bfd_bfd_data_key,
dwarf2_per_bfd_objfile_data_key>: New globals.
(dwarf2_has_info): Use shared dwarf2_per_bfd if possible.
(dwarf2_get_section_info): Use get_dwarf2_per_objfile.
(dwarf2_initialize_objfile): Consider cases where per_bfd can be
shared.
(dwarf2_build_psymtabs): Set objfile::partial_symtabs and
short-circuit when sharing.
(dwarf2_build_psymtabs): Set dwarf2_per_objfile::partial_symtabs.
(dwarf2_psymtab::expand_psymtab): Use free_cached_comp_units.

fb113f4 2020-05-13 04:24:51 Simon Marchi

Make mapped_debug_names independent of objfile

mapped_debug_names currently has a dwarf2_per_objfile field. Since we
want it to become objfile-independent, this field must be removed.

This patch removes it, and then arranges for all methods that needed it
to accept a dwarf2_per_objfile parameter. This trickles down at various
places, like the dw2_debug_names_iterator type.

Ultimately, the objfile only seems to be needed because we might need to
read a string from the string section. For that, we might need to read
in the section, and if it's a relocatable section, the objfile is needed
in order to do the relocation. This pattern happens often (that we to
pass an objfile only because a section might be read). I think it's a
bit ugly, but I don't have a good alternative right now.

gdb/ChangeLog:

* dwarf2/read.c (struct mapped_index_base) <symbol_name_at,
build_name_components, find_name_components_bounds>:
Add per_objfile parameter.
(struct mapped_index) <symbol_name_at>: Likewise.
(struct mapped_debug_names): Remove constructor.
<dwarf2_per_objfile>: Remove field.
<namei_to_name, symbol_name_at>: Add per_objfile parameter.
(mapped_index_base::find_name_components_bounds,
mapped_index_base::build_name_components,
dw2_expand_symtabs_matching_symbol): Likewise.
(class mock_mapped_index) <symbol_name_at>: Likewise.
(check_match): Likewise.
(check_find_bounds_finds): Likewise.
(test_mapped_index_find_name_component_bounds): Update.
(CHECK_MATCH): Update.
(dw2_expand_symtabs_matching): Update.
(class dw2_debug_names_iterator) <dw2_debug_names_iterator>: Add
per_objfile parameter.
<find_vec_in_debug_names>: Likewise.
<m_per_objfile>: New field.
(mapped_debug_names::namei_to_name): Add dwarf2_per_objfile
parameter.
(dw2_debug_names_iterator::find_vec_in_debug_names): Likewise.
(dw2_debug_names_iterator::next): Update.
(dw2_debug_names_lookup_symbol): Update.
(dw2_debug_names_expand_symtabs_for_function): Update.
(dw2_debug_names_map_matching_symbols): Update.
(dw2_debug_names_expand_symtabs_matching): Update.
(dwarf2_read_debug_names): Update.

5b75b03 2020-05-13 04:24:51 Simon Marchi

Replace dwarf2_per_cu_data::cu backlink with per-objfile map

The dwarf2_per_cu_data type is going to become objfile-independent,
while the dwarf2_cu type will stay object-dependent. This patch removes
the backlink from dwarf2_per_cu_data to dwarf2_cu, in favor of the
dwarf2_per_objfile::m_dwarf2_cus map. It maps dwarf2_per_cu_data
objects to the corresponding dwarf2_cu objects for this objfile. If a
CU has been read in in the context of this objfile, then an entry will
be present in the map.

The dwarf2_cu objects that are read in are currently kept in a linked
list rooted in the dwarf2_per_bfd. Except that the dwarf2_cu objects
are not simply linked together, they are interleaved with their
corresponding dwarf2_per_cu_data objects. So if we have CUs A and B
read in, the dwarf2_per_bfd::read_in_chain will point to a chain like
this (DPCD == dwarf2_per_cu_data, DC == dwarf2_cu):

DPCD A -> DC A -> DPCD B -> DC B

Obviously, this can't stay as is, since a same CU can be read in for an
objfile but not read in for another objfile sharing the same BFD, and
the dwarf2_per_cu_data::cu link is removed. This is all replaced by
the dwarf2_per_objfile::m_dwarf2_cus map.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_cu): Forward-declare.
(struct dwarf2_per_bfd) <free_cached_comp_units>: Remove,
move to dwarf2_per_objfile.
<read_in_chain>: Remove.
(struct dwarf2_per_objfile) <get_cu, set_cu, remove_cu,
remove_all_cus, age_comp_units>: New methods.
<m_dwarf2_cus>: New member.
(struct dwarf2_per_cu_data) <cu>: Remove.
* dwarf2/read.c (struct dwarf2_cu) <read_in_chain>: Remove.
(age_cached_comp_units, free_one_cached_comp_unit): Remove,
moved to methods of dwarf2_per_objfile.
(dwarf2_clear_marks): Remove.
(dwarf2_queue_item::~dwarf2_queue_item): Update.
(dwarf2_per_bfd::~dwarf2_per_bfd): Don't free dwarf2_cus.
(dwarf2_per_bfd::free_cached_comp_units): Remove.
(dwarf2_per_objfile::remove_all_cus): New.
(class free_cached_comp_units) <~free_cached_comp_units>:
Update.
(load_cu): Update.
(dw2_do_instantiate_symtab): Adjust.
(fill_in_sig_entry_from_dwo_entry): Adjust.
(cutu_reader::init_tu_and_read_dwo_dies): Update.
(cutu_reader::cutu_reader): Likewise.
(cutu_reader::keep): Use dwarf2_per_objfile::set_cu.
(cutu_reader::cutu_reader): Use dwarf2_per_objfile::get_cu.
(process_psymtab_comp_unit): Use dwarf2_per_objfile::remove_cu
and dwarf2_per_objfile::age_comp_units.
(load_partial_comp_unit): Update.
(maybe_queue_comp_unit): Use dwarf2_per_objfile::get_cu.
(process_queue): Likewise.
(find_partial_die): Use dwarf2_per_objfile::get_cu instead of cu
backlink.
(dwarf2_read_addr_index): Likewise.
(follow_die_offset): Likewise.
(dwarf2_fetch_die_loc_sect_off): Likewise.
(dwarf2_fetch_constant_bytes): Likewise.
(dwarf2_fetch_die_type_sect_off): Likewise.
(follow_die_sig_1): Likewise.
(load_full_type_unit): Likewise.
(read_signatured_type): Likewise.
(dwarf2_cu::dwarf2_cu): Don't set cu field.
(dwarf2_cu::~dwarf2_cu): Remove.
(dwarf2_per_objfile::get_cu): New.
(dwarf2_per_objfile::set_cu): New.
(age_cached_comp_units): Rename to...
(dwarf2_per_objfile::age_comp_units): ... this. Adjust
to std::unordered_map.
(free_one_cached_comp_unit): Rename to...
(dwarf2_per_objfile::remove_cu): ... this. Adjust
to std::unordered_map.
(dwarf2_per_objfile::~dwarf2_per_objfile): New.
(dwarf2_mark_helper): Use dwarf2_per_objfile::get_cu, expect
a dwarf2_per_objfile in data.
(dwarf2_mark): Pass dwarf2_per_objfile in data to htab_traverse.
(dwarf2_clear_marks): Remove.

bd6776c 2020-05-13 04:24:51 Simon Marchi

Pass existing_cu object to cutu_reader

It is possible, seemingly for a special case described in
find_partial_die, for cutu_reader to re-use an existing dwarf2_cu
instead of creating a new one. This happens

d8ec151 2020-05-13 04:24:51 Simon Marchi

Add comp_unit_head to dwarf2_per_cu_data

The per_cu_header_read_in function allows obtaining a filled
comp_unit_head object for a given dwarf2_per_cu_data object. If a
dwarf2_cu object exists for this dwarf2_per_cu_data, then it just
returns a pointer to the comp_unit_head from that dwarf2_cu. Otherwise,
it reads the header into a temporary buffer provided by the caller, and
returns a pointer to that.

Since the dwarf2_per_cu_data::cu link is going to be removed
(dwarf2_per_cu_data will become objfile-independent while dwarf2_cu
stays objfile-dependent), we cannot rely anymore on returning the header
from the dwarf2_cu object.

The not too complex solution implemented by this patch is to keep a copy
of the header in the dwarf2_per_cu_data object, independent from the
copy in dwarf2_cu. The new copy is only used in the addr_size,
offset_size and ref_addr_size methods of dwarf2_per_cu_data.

There's nothing intrinsic to the comp_unit_head object that prevents it
to be shared between two dwarf2_cu objects (belonging to different
objfiles) representing the same CU. In other words, I think we could
eventually get rid of the copy in dwarf2_cu to only keep the one in
dwarf2_per_cu_data. It is not trivial, however, so I have decided not
to do it for the moment.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <m_header,
m_header_read_in>: New fields.
<get_header>: New method.
* dwarf2/read.c (per_cu_header_read_in): Remove.
(dwarf2_per_cu_data::get_header): New.
(dwarf2_per_cu_data::addr_size): Update.
(dwarf2_per_cu_data::offset_size): Update.
(dwarf2_per_cu_data::ref_addr_size): Update.

7d58fe1 2020-05-13 04:24:51 Simon Marchi

Make load_cu return the loaded dwarf2_cu

In a subsequent patch, the dwarf2_per_cu_data::cu link will be removed.
dwarf2_cu objects will instead need to be looked up from a per-objfile
map, using the dwarf2_per_cu_data object as the key.

To make it easier for some callers, this patch makes load_cu return the
dwarf2_cu it creates. If the caller needs to use the created dwarf2_cu,
it will have it available right away, rather than having to do a map
lookup.

At the same time, this allows changing queue_and_load_all_dwo_tus to
take a dwarf2_cu instead of a dwarf2_per_cu_data.

gdb/ChangeLog:

* dwarf2/read.c (load_cu): Return dwarf2_cu.
(dw2_do_instantiate_symtab): Update.
(queue_and_load_all_dwo_tus): Change parameter from
dwarf2_per_cu_data to dwarf2_cu.
(dwarf2_fetch_die_loc_sect_off): Update.
(dwarf2_fetch_constant_bytes): Update.
(dwarf2_fetch_die_type_sect_off): Update.

a3ddd1a 2020-05-13 04:24:51 Simon Marchi

Pass dwarf2_cu to process_full_{comp,type}_unit

These two functions work on a dwarf2_cu. It is currently obtained from
the per_cu->cu link, which we want to remove. Make them accept the
dwarf2_cu directly as a parameter. This moves the per_cu->cu references
one level up, but that one will be removed too in a subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (process_full_comp_unit,
process_full_type_unit): Remove per_cu, per_objfile paramters.
Add dwarf2_cu parameter.
(process_queue): Update.

d4b0ea1 2020-05-13 04:24:51 Simon Marchi

Pass dwarf2_per_bfd instead of dwarf2_per_objfile to some index-related functions

All these functions actually only need to receive a dwarf2_per_bfd, pass
that instead of dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.c (create_cu_from_index_list): Replace
dwarf2_per_objfile parameter with dwarf2_per_bfd.
(create_cus_from_index_list): Likewise.
(create_cus_from_index): Likewise.
(create_signatured_type_table_from_index): Likewise.
(create_cus_from_debug_names_list): Likewise.
(create_cus_from_debug_names): Likewise.
(dwarf2_read_gdb_index): Update.
(dwarf2_read_debug_names): Update.

f4a3bd8 2020-05-13 04:24:51 Tom Tromey

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.

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.

5b9cfc4 2020-05-13 04:24:51 Tom Tromey

Split type_unit_group

type_unit_group has links to the compunit_symtab and other symtabs.
However, once this object is shared across objfiles, this will no
longer be ok.

This patch introduces a new type_unit_group_unshareable and arranges to
store a map from type unit groups to type_unit_group_unshareable objects
in dwarf2_per_objfile.

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

* dwarf2/read.h (struct type_unit_group_unshareable): New.
(struct dwarf2_per_objfile) <type_units>: New member.
<get_type_unit_group_unshareable>: New method.
* dwarf2/read.c (struct type_unit_group) <compunit_symtab,
num_symtabs, symtabs>: Remove; move to
type_unit_group_unshareable.
(dwarf2_per_objfile::get_type_unit_group_unshareable): New.
(process_full_type_unit, dwarf2_cu::setup_type_unit_groups)
(dwarf2_cu::setup_type_unit_groups): Use type_unit_group_unshareable.

a35610c 2020-05-13 04:24:51 Simon Marchi

Remove dwarf2_per_cu_data::dwarf2_per_objfile

Nothing references this field anymore, remove it.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data):
<dwarf2_per_objfile>: Remove.
* dwarf2/read.c (create_cu_from_index_list): Don't assign
dwarf2_per_objfile.
(create_signatured_type_table_from_index): Likewise.
(create_signatured_type_table_from_debug_names): Likewise.
(create_debug_type_hash_table): Likewise.
(fill_in_sig_entry_from_dwo_entry): Likewise.
(create_type_unit_group): Likewise.
(read_comp_units_from_section): Likewise.
(create_cus_hash_table): Likewise.

df7a679 2020-05-13 04:24:51 Simon Marchi

Remove leftover references to dwarf2_per_cu_data::dwarf2_per_objfile

This patch removes the remaining references to that field in obvious
ways (the same object is already available some other way in these
contexts).

gdb/ChangeLog:

* dwarf2/read.c (process_psymtab_comp_unit): Remove reference to
dwarf2_per_cu_data::dwarf2_per_objfile.
(compute_compunit_symtab_includes): Likewise.
(dwarf2_cu::start_symtab): Likewise.

2a651b1 2020-05-13 04:24:51 Simon Marchi

Add dwarf2_per_objfile parameter to get_die_type_at_offset

This allows removing some dwarf2_per_cu_data::dwarf2_per_objfile
references.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_get_die_type): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (get_die_type_at_offset): Likewise.
(read_namespace_alias): Update.
(lookup_die_type): Update.
(dwarf2_get_die_type): Add dwarf2_per_objfile parameter.
* dwarf2/loc.c (class dwarf_evaluate_loc_desc) <get_base_type>:
Update.
(disassemble_dwarf_expression): Update.

bd3914c 2020-05-13 04:24:51 Simon Marchi

Add dwarf2_per_objfile parameter to free_one_cached_comp_unit

This allows removing some references to
dwarf2_per_cu_data::dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_queue_item): Add
dwarf2_per_objfile parameter, assign new parameter.
<per_objfile>: New field.
* dwarf2/read.c (free_one_cached_comp_unit): Add
dwarf2_per_objfile parameter.
(queue_comp_unit): Likewise.
(dw2_do_instantiate_symtab): Update.
(process_psymtab_comp_unit): Update.
(maybe_queue_comp_unit): Add dwarf2_per_objfile parameter.
(process_imported_unit_die): Update.
(queue_and_load_dwo_tu): Update.
(follow_die_offset): Update.
(follow_die_sig_1): Update.

c8b4219 2020-05-13 04:24:51 Simon Marchi

Remove dwarf2_per_cu_data::objfile ()

Since dwarf2_per_cu_data objects are going to become
objfile-independent, the backlink from dwarf2_per_cu_data to one
particular objfile must be removed. Instead, users of
dwarf2_per_cu_data that need an objfile must know from somewhere else in
the context of which objfile they are using this CU.

This also helps remove a dwarf2_per_cu_data::dwarf2_per_objfile
reference (from where the objfile was obtained).

Note that the dwarf2_per_cu_data::objfile method has a special case to
make sure to return the main objfile, if the objfile associated to the
dwarf2_per_cu_data is a separate debug objfile. I don't really know if
this is necessary: I ignored that, and didn't see any regression when
testing with the various Dejagnu boards with separate debug info, so I
presume it wasn't needed. If it turns out this was needed, then we can
have a helper method on the objfile type for that.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <objfile>: Remove.
* dwarf2/read.c (dwarf2_compute_name): Pass per_objfile down.
(read_call_site_scope): Assign per_objfile.
(dwarf2_per_cu_data::objfile): Remove.
* gdbtypes.h (struct call_site) <per_objfile>: New member.
* dwarf2/loc.h (dwarf2_evaluate_loc_desc): Add
dwarf2_per_objfile parameter.
* dwarf2/loc.c (dwarf2_evaluate_loc_desc_full): Add
dwarf2_per_objfile parameter.
(dwarf_expr_reg_to_entry_parameter): Add output
dwarf2_per_objfile parameter.
(locexpr_get_frame_base): Update.
(class dwarf_evaluate_loc_desc) <get_tls_address>: Update.
<push_dwarf_reg_entry_value>: Update.
<call_site_to_target_addr>: Update.
(dwarf_entry_parameter_to_value): Add dwarf2_per_objfile
parameter.
(value_of_dwarf_reg_entry): Update.
(rw_pieced_value): Update.
(indirect_synthetic_pointer): Update.
(dwarf2_evaluate_property): Update.
(dwarf2_loc_desc_get_symbol_read_needs): Add dwarf2_per_objfile
parameter.
(locexpr_read_variable): Update.
(locexpr_get_symbol_read_needs): Update.
(loclist_read_variable): Update.

2a2b2a7 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameters to dwarf2_fetch_* functions

This allows removing dwarf2_per_cu_data references.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_fetch_die_loc_sect_off,
dwarf2_fetch_die_loc_cu_off, dwarf2_fetch_constant_bytes,
dwarf2_fetch_die_type_sect_off): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (dwarf2_fetch_die_loc_sect_off,
dwarf2_fetch_die_loc_cu_off, dwarf2_fetch_constant_bytes,
dwarf2_fetch_die_type_sect_off): Add dwarf2_per_objfile
parameter.
* dwarf2/loc.c (indirect_synthetic_pointer, per_cu_dwarf_call,
sect_variable_value): Add dwarf2_per_objfile parameter.
(class dwarf_evaluate_loc_desc) <dwarf_call,
dwarf_variable_value>: Update.
(fetch_const_value_from_synthetic_pointer): Add
dwarf2_per_objfile parameter.
(fetch_const_value_from_synthetic_pointer): Update.
(coerced_pieced_ref): Update.
(class symbol_needs_eval_context) <dwarf_call,
dwarf_variable_value>: Update.
(dwarf2_compile_expr_to_ax): Update.

caca6f5 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to allocate_piece_closure

This allows removing a dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/loc.c (allocate_piece_closure): Add dwarf2_per_objfile
parameter.
(dwarf2_evaluate_loc_desc_full): Update.

7b9424e 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to dwarf2_read_addr_index

Pass it all the way from the symbol batons. This allows removing a
dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_read_addr_index): Add dwarf2_per_objfile
parameter.
* dwarf2/read.c (dwarf2_read_addr_index): Likewise.
* dwarf2/loc.c (decode_debug_loclists_addresses): Add
dwarf2_per_objfile parameter.
(decode_debug_loc_dwo_addresses): Likewise.
(dwarf2_find_location_expression): Update.
(class dwarf_evaluate_loc_desc) <get_addr_index>: Update.
(locexpr_describe_location_piece): Add dwarf2_per_objfile
parameter.
(disassemble_dwarf_expression): Add dwarf2_per_objfile
parameter.
(locexpr_describe_location_1): Likewise.
(locexpr_describe_location): Update.

a2ffabb 2020-05-13 04:24:50 Simon Marchi

Remove dwarf2_per_cu_data::text_offset

This method simply returns the text offset of the objfile associated to
the dwarf2_per_cu_data object. Since dwarf2_per_cu_data objects are
going to become objfile-independent, we can't keep this method. This
patch removes it.

Existing callers need to figure out the in the context of which objfile
this is being used, and call text_offset on it. Typically, this comes
from a symbol baton, where we store the corresponding
dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <text_offset>:
Remove.
* dwarf2/read.c (dwarf2_per_cu_data::text_offset): Remove.
* dwarf2/loc.c (dwarf2_find_location_expression): Update.
(dwarf2_compile_property_to_c): Update.
(dwarf2_compile_expr_to_ax): Add dwarf2_per_objfile parameter,
use text offset from objfile.
(locexpr_tracepoint_var_ref): Update.
(locexpr_generate_c_location): Update.
(loclist_describe_location): Update.
(loclist_tracepoint_var_ref): Update.
* dwarf2/compile.h (compile_dwarf_bounds_to_c): Add
dwarf2_per_objfile parameter.
* dwarf2/loc2c.c (do_compile_dwarf_expr_to_c): Likewise,
use text offset from objfile.
(compile_dwarf_expr_to_c): Add dwarf2_per_objfile parameter.

a03eab7 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache

Evaluating DWARF expressions (such as location expressions) requires
knowing about the current objfile. For example, it may call functions
like dwarf2_fetch_die_loc_sect_off, which currently obtain the
dwarf2_per_objfile object it needs from the dwarf2_per_cu_data object.
However, since we are going to remove this
dwarf2_per_cu_data::dwarf2_per_objfile link, these functions will need
to obtain the current dwarf2_per_objfile by parmeter.

If we go up the stack, we see that the DWARF expression contexts
(dwarf_expr_context and the classes that derive from it) need to store
the dwarf2_per_objfile, to be able to pass it to those functions that
will need it.

This patch adds a constructor to all these dwarf_expr_context variants,
accepting a dwarf2_per_objfile parameter. This dwarf2_per_objfile
generally comes from a symbol baton created earlier.

For frame-related expressions, the dwarf2_per_objfile object must be
passed through the dwarf2_frame_cache object. This lead to the
dwarf2_frame_find_fde function returning (by parameter) a
dwarf2_per_objfile object. I then realized that this made the existing
"out_offset" parameter redundant. This offset is
`objfile->text_section_offset ()`, so it can be recomputed from the
dwarf2_per_objfile object at any time. I therefore opted to remove this
output parameter, as well as the offset field of dwarf2_frame_cache.

*Note*, there's one spot I'm particularly unsure about. In
dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value, we would save and
overwrite the offset value in the context, along with a bunch of other
state. This is because we might be about to evaluate something in a
different CU that the current one. If the two CUs are in the same
objfile, then the text_offset is the same, as it's a property of the
objfile. However, if the two CUs are possibly in different objfiles,
then it means the text_offsets are different. It would also mean we
would need to save and restore the dwarf2_per_objfile in the context.
Is that even possible?

gdb/ChangeLog:

* dwarf2/expr.h (struct dwarf_expr_context)
<dwarf_expr_context>: Add dwarf2_per_objfile parameter.
<offset>: Remove.
<per_objfile>: New member.
* dwarf2/expr.c (dwarf_expr_context::dwarf_expr_context): Add
dwarf2_per_objfile parameter. Don't set offset, set
per_objfile.
(dwarf_expr_context::execute_stack_op): Use offset from objfile.
* dwarf2/frame.c (dwarf2_frame_find_fde): Return (by parameter)
a dwarf2_per_objfile object instead of an offset.
(class dwarf_expr_executor) <dwarf_expr_executor>: Add
constructor.
(execute_stack_op): Add dwarf2_per_objfile parameter, pass it
to dwarf2_expr_executor constructor. Don't set offset.
(dwarf2_fetch_cfa_info): Update.
(struct dwarf2_frame_cache) <text_offset>: Remove.
<per_objfile>: New field.
(dwarf2_frame_cache): Update.
(dwarf2_frame_prev_register): Update.
* dwarf2/loc.c (class dwarf_evaluate_loc_desc)
<dwarf_evaluate_loc_desc>: Add constructor.
(dwarf2_evaluate_loc_desc_full): Update.
(dwarf2_locexpr_baton_eval): Update.
(class symbol_needs_eval_context) <symbol_needs_eval_context>:
Add constructor.
(dwarf2_loc_desc_get_symbol_read_needs): Update.

d263409 2020-05-13 04:24:50 Simon Marchi

Move int type methods out of dwarf2_per_cu_data

These methods rely on the current objfile to create types based on it.
Since dwarf2_per_cu_data is to become objfile-independent, these methods
need to mvoe.

int_type can be in dwarf2_per_objfile, as it only requires knowing about
the objfile.

addr_sized_int_type and addr_type also need to know about the DWARF
address type size, which is CU-specific. The dwarf2_cu objects seems
like a good place for it, as it knows both about the current objfile and
the current CU.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_type,
addr_sized_int_type>: Move to dwarf2_cu.
<int_type>: Move to dwarf2_per_objfile.
(struct dwarf2_per_objfile) <int_type>: Move here.
* dwarf2/read.c (struct dwarf2_cu) <addr_type,
addr_sized_int_type>: Move here.
(read_func_scope): Update.
(read_array_type): Update.
(read_tag_string_type): Update.
(attr_to_dynamic_prop): Update.
(dwarf2_per_cu_data::int_type): Rename to...
(dwarf2_per_objfile::int_type): ... this.
(dwarf2_per_cu_data::addr_sized_int_type): Rename to...
(dwarf2_cu::addr_sized_int_type): ... this.
(read_subrange_type): Update.
(dwarf2_per_cu_data::addr_type): Rename to...
(dwarf2_cu::addr_type): ... this.
(set_die_type): Update.

30677c8 2020-05-13 04:24:50 Simon Marchi

Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in queue_and_load_all_dwo_tus

In this context, we know that per_cu->cu will be set, as there is this
assertion:

gdb_assert (per_cu->cu != NULL)

So in order to remove the dwarf2_per_cu_data::dwarf2_per_objfile
reference in queue_and_load_all_dwo_tus, we can go through per_cu->cu.
This adds a reference to dwarf2_per_cu_data::cu, but it will get removed
eventually, in a subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (queue_and_load_all_dwo_tus): Access per_objfile
data through per_cu->cu.

9e575d4 2020-05-13 04:24:50 Simon Marchi

Pass dwarf2_cu objects to dwo-related functions, instead of dwarf2_per_cu_data

This allows removing references to the
dwarf2_per_cu_data::dwarf2_per_objfile field.

I am not too sure of the code flow here, but ultimately
open_and_init_dwo_file calls create_cus_hash_table, and passes it
per_cu->cu. create_cus_hash_table requires a dwarf2_cu to pass to
cutu_reader, as the "parent_cu".

The dwarf2_per_cu_data::cu link is only set when in a certain context.
It's not easy to convince myself in which situations it's safe to use
it. Instead, if a function is going to use a dwarf2_cu, I think it's
simpler if it takes that object directly. If it needs access to the
corresponding dwarf2_per_cu_data object, then it can used the
dwarf2_cu::per_cu field, which we know is always set.

This patch adds some references to dwarf2_per_cu_data::cu in the
cutu_reader context. In this context, we know this field will be set,
as it's cutu_reader that is responsible for instantiating the dwarf2_cu
and assigning the field.

gdb/ChangeLog:

* dwarf2/read.c (lookup_dwo_comp_unit): Change
dwarf2_per_cu_data parameter fo dwarf2_cu.
(lookup_dwo_type_unit): Likewise.
(read_cutu_die_from_dwo): Likewise.
(lookup_dwo_unit): Likewise.
(open_and_init_dwo_file): Likewise.
(lookup_dwo_cutu): Likewise.
(lookup_dwo_comp_unit): Likewise.
(lookup_dwo_type_unit): Likewise.
(cutu_reader::init_tu_and_read_dwo_dies): Update.
(cutu_reader::cutu_reader): Update.

e734976 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to process_full_{comp,type}_unit

This allows removing the dwarf2_per_cu_data::dwarf2_per_objfile
references in them.

gdb/ChangeLog:

* dwarf2/read.c (process_full_comp_unit): Add dwarf2_per_objfile
parameter.
(process_full_type_unit): Likewise.
(process_queue): Update.

6174efd 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to recursively_compute_inclusions

This allows removing dwarf2_per_cu_data::dwarf2_per_objfile references
in recursively_compute_inclusions and compute_compunit_symtab_includes.

gdb/ChangeLog:

* dwarf2/read.c (recursively_compute_inclusions): Add
dwarf2_per_objfile parameter.
(compute_compunit_symtab_includes): Likewise.
(process_cu_includes): Update.

d4ea1c4 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to create_partial_symtab

This allows removing a dwarf2_per_cu_data::dwarf2_per_objfile reference.

gdb/ChangeLog:

* dwarf2/read.c (create_partial_symtab): Add dwarf2_per_objfile
parameter.
(create_type_unit_group): Update.
(process_psymtab_comp_unit_reader): Update.
(build_type_psymtabs_reader): Update.

68a4419 2020-05-13 04:24:50 Simon Marchi

Remove dwarf2_per_cu_data::dwarf2_per_objfile reference in cutu_reader::keep

Here, it should be safe to use dwarf2_per_cu_data->cu->per_objfile, as
we know that dwarf2_per_cu_data->cu will be set at this point.

Note that this adds a reference to dwarf2_per_cu_data::cu, which we'll
want to remove later, but the current focus is to remove references to
dwarf2_per_cu_data::dwarf2_per_objfile. We'll deal with that in a
subsequent patch.

gdb/ChangeLog:

* dwarf2/read.c (cutu_reader::keep): Access dwarf2_per_objfile
object through m_this_cu->cu.

4132873 2020-05-13 04:24:50 Simon Marchi

Make queue_and_load_dwo_tu receive a dwarf2_cu

queue_and_load_dwo_tu, used as a callback for htab_traverse_noresize,
currently receives a dwarf2_per_cu_data as its `info` user data. It
accesses the current dwarf2_cu object through the dwarf2_per_cu_data::cu field.
This field will be removed, because the dwarf2_per_cu_data will become
objfile-independent, while dwarf_cu will remain objfile-dependent.

To remove references to this field, change queue_and_load_dwo_tu so
that it expects to receive a pointer to the dwarf2_cu as its info
parameter.

A reference to dwarf2_per_cu_data::cu needs to be added, but it will get
removed in a subsequent patch, when this function gets re-worked.

I kept this as a separate patch, because since there's no strong typing
here, it's easy to miss something.

gdb/ChangeLog:

* dwarf2/read.c (queue_and_load_dwo_tu): Expect a dwarf2_cu as
the info parameter.
(queue_and_load_all_dwo_tus): Pass per_cu->cu.

9fb9ca8 2020-05-13 04:24:50 Simon Marchi

Add dwarf2_per_objfile parameter to cutu_reader's constructors

The cutu_reader type is used for reading the CU represented by the
passed dwarf2_per_cu_data object. This reading is done in the context
of a given obfile, which is currently the one associated to the passed
dwarf2_per_cu_data object. Since the dwarf2_per_cu_data type will
become objfile-independent, we will need to pass the objfile separately.

This patch therefore adds a dwarf2_per_objfile parameter to the
cutu_reader constructors, as well as to their callers, up until the
point where we can get the dwarf2_per_objfile object from somewhere
else. In the end, this allows removing the reference to
dwarf2_per_cu_data::dwarf2_per_objfile in cutu_reader::cutu_reader.

A few dwarf2_per_cu_data::dwarf2_per_objfile references are added (e.g.
in dwarf2_fetch_die_type_sect_off). This is temporary, this will be
removed once these functions will get re-worked in subsequent patches.

gdb/ChangeLog:

* dwarf2/read.c (class cutu_reader) <cutu_reader>: Add
per_objfile parameter.
(load_full_type_unit): Add per_objfile parameter.
(read_signatured_type): Likewise.
(load_full_comp_unit): Likewise.
(load_cu): Likewise.
(dw2_do_instantiate_symtab): Likewise.
(dw2_get_file_names): Likewise.
(dw2_map_symtabs_matching_filename): Update.
(dw_expand_symtabs_matching_file_matcher): Update.
(dw2_map_symbol_filenames): Update.
(process_psymtab_comp_unit): Add per_objfile parameter.
(build_type_psymtabs_1): Update.
(process_skeletonless_type_unit): Update.
(dwarf2_build_psymtabs_hard): Update.
(load_partial_comp_unit): Add per_objfile parameter.
(scan_partial_symbols): Update.
(load_full_comp_unit): Add per_objfile parameter.
(process_imported_unit_die): Update.
(create_cus_hash_table): Update.
(find_partial_die): Update.
(dwarf2_read_addr_index): Update.
(follow_die_offset): Update.
(dwarf2_fetch_die_loc_sect_off): Update.
(dwarf2_fetch_constant_bytes): Update.
(dwarf2_fetch_die_type_sect_off): Update.
(follow_die_sig_1): Update.
(load_full_type_unit): Add per_objfile parameter.
(read_signatured_type): Likewise.

bf1c1db 2020-05-13 04:24:50 Simon Marchi

Use bfd_get_filename instead of objfile_name in lookup_dwo_unit

There should be no functional difference, as objfile_name defers to
bfd_get_filename if objfile::obfd is non-NULL, which should be the case
here. This allows to remove a reference to
dwarf2_per_cu_data::dwarf2_per_objfile.

gdb/ChangeLog:

* dwarf2/read.c (lookup_dwo_unit): Use bfd_get_filename instead
of objfile_name.