]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
3 years agoShare DWARF partial symtabs users/simark/submit/share-dwarf-partial-symtabs-v2
Tom Tromey [Sat, 15 Feb 2020 16:54:44 +0000 (09:54 -0700)] 
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.

3 years agoMake mapped_debug_names independent of objfile
Simon Marchi [Sat, 7 Mar 2020 19:02:43 +0000 (14:02 -0500)] 
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.

3 years agoReplace dwarf2_per_cu_data::cu backlink with per-objfile map
Simon Marchi [Thu, 9 Apr 2020 18:06:04 +0000 (14:06 -0400)] 
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.

3 years agoPass existing_cu object to cutu_reader
Simon Marchi [Thu, 9 Apr 2020 17:46:41 +0000 (13:46 -0400)] 
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

3 years agoAdd comp_unit_head to dwarf2_per_cu_data
Simon Marchi [Wed, 8 Apr 2020 16:33:53 +0000 (12:33 -0400)] 
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.

3 years agoMake load_cu return the loaded dwarf2_cu
Simon Marchi [Wed, 8 Apr 2020 12:40:18 +0000 (08:40 -0400)] 
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.

3 years agoPass dwarf2_cu to process_full_{comp,type}_unit
Simon Marchi [Wed, 8 Apr 2020 12:30:06 +0000 (08:30 -0400)] 
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.

3 years agoPass dwarf2_per_bfd instead of dwarf2_per_objfile to some index-related functions
Simon Marchi [Wed, 8 Apr 2020 03:38:53 +0000 (23:38 -0400)] 
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.

3 years agoMove signatured_type::type to unshareable object
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
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.

3 years agoSplit type_unit_group
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
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.

3 years agoRemove dwarf2_per_cu_data::dwarf2_per_objfile
Simon Marchi [Tue, 25 Feb 2020 07:41:23 +0000 (02:41 -0500)] 
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.

3 years agoRemove leftover references to dwarf2_per_cu_data::dwarf2_per_objfile
Simon Marchi [Tue, 25 Feb 2020 22:33:37 +0000 (17:33 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to get_die_type_at_offset
Simon Marchi [Mon, 6 Apr 2020 17:01:05 +0000 (13:01 -0400)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to free_one_cached_comp_unit
Simon Marchi [Wed, 26 Feb 2020 15:11:55 +0000 (10:11 -0500)] 
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.

3 years agoRemove dwarf2_per_cu_data::objfile ()
Simon Marchi [Wed, 26 Feb 2020 14:49:42 +0000 (09:49 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameters to dwarf2_fetch_* functions
Simon Marchi [Wed, 26 Feb 2020 06:52:21 +0000 (01:52 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to allocate_piece_closure
Simon Marchi [Wed, 26 Feb 2020 06:41:01 +0000 (01:41 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to dwarf2_read_addr_index
Simon Marchi [Wed, 26 Feb 2020 04:40:06 +0000 (23:40 -0500)] 
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.

3 years agoRemove dwarf2_per_cu_data::text_offset
Simon Marchi [Wed, 26 Feb 2020 05:48:10 +0000 (00:48 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile to dwarf_expr_context and dwarf2_frame_cache
Simon Marchi [Tue, 12 May 2020 16:05:24 +0000 (12:05 -0400)] 
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.

3 years agoMove int type methods out of dwarf2_per_cu_data
Simon Marchi [Wed, 26 Feb 2020 04:25:19 +0000 (23:25 -0500)] 
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.

3 years agoRemove reference to dwarf2_per_cu_data::dwarf2_per_objfile in queue_and_load_all_dwo_tus
Simon Marchi [Wed, 26 Feb 2020 04:12:11 +0000 (23:12 -0500)] 
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.

3 years agoPass dwarf2_cu objects to dwo-related functions, instead of dwarf2_per_cu_data
Simon Marchi [Wed, 26 Feb 2020 03:47:57 +0000 (22:47 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to process_full_{comp,type}_unit
Simon Marchi [Tue, 25 Feb 2020 22:44:03 +0000 (17:44 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to recursively_compute_inclusions
Simon Marchi [Tue, 25 Feb 2020 22:39:45 +0000 (17:39 -0500)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to create_partial_symtab
Simon Marchi [Tue, 25 Feb 2020 22:31:43 +0000 (17:31 -0500)] 
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.

3 years agoRemove dwarf2_per_cu_data::dwarf2_per_objfile reference in cutu_reader::keep
Simon Marchi [Tue, 25 Feb 2020 22:21:54 +0000 (17:21 -0500)] 
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.

3 years agoMake queue_and_load_dwo_tu receive a dwarf2_cu
Simon Marchi [Sat, 4 Apr 2020 23:46:25 +0000 (19:46 -0400)] 
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.

3 years agoAdd dwarf2_per_objfile parameter to cutu_reader's constructors
Simon Marchi [Wed, 8 Apr 2020 14:21:46 +0000 (10:21 -0400)] 
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.

3 years agoUse bfd_get_filename instead of objfile_name in lookup_dwo_unit
Simon Marchi [Tue, 25 Feb 2020 16:57:12 +0000 (11:57 -0500)] 
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.

3 years agoMake dwarf2_get_dwz_file take a dwarf2_per_bfd
Simon Marchi [Mon, 6 Apr 2020 16:55:09 +0000 (12:55 -0400)] 
Make dwarf2_get_dwz_file take a dwarf2_per_bfd

This allows removing a per_bfd->dwarf2_per_objfile reference in
get_abbrev_section_for_cu.

This requires saving the bfd in dwarf2_per_bfd.  The constructor of
dwarf2_per_bfd already accepts the bfd, so it's just a matter of saving
it in a field.

I replaced uses of objfile_name with bfd_get_filename, which should be
equivalent in this case.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <obfd>: New member.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
* dwarf2/read.c (dwarf2_per_bfd::dwarf2_per_bfd): Assign obfd
field.
(dwarf2_get_dwz_file): Replace parameter with dwarf2_per_bfd.
(create_cus_from_index): Update.
(dwarf2_read_gdb_index): Update.
(create_cus_from_debug_names): Update.
(dwarf2_read_debug_names): Update.
(get_abbrev_section_for_cu): Update.
(create_all_comp_units): Update.
(read_attribute_value): Update.
(get_debug_line_section): Update.
* dwarf2/index-cache.c (index_cache::store): Update.
* dwarf2/index-write.c (save_gdb_index_command): Update.
* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.

3 years agoAdd dwarf2_per_bfd field to dwarf2_per_cu_data
Simon Marchi [Mon, 6 Apr 2020 16:53:11 +0000 (12:53 -0400)] 
Add dwarf2_per_bfd field to dwarf2_per_cu_data

Some code using dwarf2_per_cu_data objects accesses the corresponding
dwarf2_per_bfd using the following pattern:

    per_cu->dwarf2_per_objfile->per_bfd

Since dwarf2_per_cu_data objects are going to become
objfile-independent, the dwarf2_per_objfile link must go.  To replace
it, add a dwarf2_per_cu_data->per_bfd link.  It makes sense to have it
there because the dwarf2_per_cu_data objects belong to the
dwarf2_per_bfd, so this is essentially just a backlink to their owner.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_cu_data) <per_bfd>: New
member.
* dwarf2/read.c (dwarf2_per_bfd::allocate_per_cu): Initialize
dwarf2_per_cu_data::per_bfd.
(dwarf2_per_bfd::allocate_signatured_type): Likewise.
(create_type_unit_group): Likewise.
(queue_comp_unit): Remove reference to
per_cu->dwarf2_per_objfile.
(maybe_queue_comp_unit): Likewise.
(fill_in_sig_entry_from_dwo_entry): Assign new field.
(create_cus_hash_table): Assign new field.

3 years agoRemove dwarf2_cu->per_cu->dwarf2_per_objfile references
Simon Marchi [Tue, 25 Feb 2020 06:54:56 +0000 (01:54 -0500)] 
Remove dwarf2_cu->per_cu->dwarf2_per_objfile references

Change spots that access the dwarf2_per_objfile object through this
pattern:

  dwarf2_cu->per_cu->dwarf2_per_objfile

to

  dwarf2_cu->per_objfile

This allows removing many references to
dwarf2_per_cu_data::dwarf2_per_objfile.

Again, I hope the following ChangeLog entry will be fine.  I'd rather not
list all the affected functions, as it would be time-consuming and a bit
pointless.

gdb/ChangeLog:

* dwarf2/read.c: Replace
dwarf2_cu->per_cu->dwarf2_per_objfile references with
dwarf2_cu->per_objfile throughout.

3 years agoRemove reference to dwarf2_per_cu_data::dwarf2_per_objfile in dw2_do_instantiate_symtab
Simon Marchi [Sat, 29 Feb 2020 06:34:24 +0000 (01:34 -0500)] 
Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in dw2_do_instantiate_symtab

This patch begins by removing the per_cu->dwarf2_per_objfile reference
in dw2_do_instantiate_symtab, instead accepting a dwarf2_per_objfile
object as a parameter.  It then fixes the fallouts.  In this context,
the dwarf2_per_objfile is generally derived from an objfile passed to a
quick_symbol_functions callback.

gdb/ChangeLog:

* dwarf2/read.c (dw2_do_instantiate_symtab): Add per_objfile
parameter, don't use per_cu->dwarf2_per_objfile.
(dw2_instantiate_symtab): Likewise.
(dw2_find_last_source_symtab): Update.
(dw2_map_expand_apply): Update.
(dw2_lookup_symbol): Update.
(dw2_expand_symtabs_for_function): Update.
(dw2_expand_all_symtabs): Update.
(dw2_expand_symtabs_with_fullname): Update.
(dw2_expand_symtabs_matching_one): Add per_objfile parameter,
don't use per_cu->dwarf2_per_objfile.
(dw2_expand_marked_cus): Update.
(dw2_find_pc_sect_compunit_symtab): Update.
(dw2_debug_names_lookup_symbol): Update.
(dw2_debug_names_expand_symtabs_for_function): Update.
(dw2_debug_names_map_matching_symbols): Update.
(dwarf2_psymtab::expand_psymtab): Update.

3 years agoAdd dwarf2_per_objfile field to dwarf2_cu
Simon Marchi [Tue, 25 Feb 2020 05:38:02 +0000 (00:38 -0500)] 
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.

3 years agoMove die_type_hash to dwarf2_per_objfile
Simon Marchi [Tue, 25 Feb 2020 04:39:47 +0000 (23:39 -0500)] 
Move die_type_hash to dwarf2_per_objfile

The die_type_hash field can't be shared between multiple obfiles, as it
holds `struct type` objects, which are objfile-specific.  Move it from
dwarf2_per_bfd to dwarf2_per_objfile and update all references.

gdb/ChangeLog:

* dwarf2/read.h (struct dwarf2_per_bfd) <die_type_hash>: Move to
struct dwarf2_per_objfile.
(struct dwarf2_per_objfile) <die_type_hash>: Move from struct
dwarf2_per_bfd.
* dwarf2/read.c (set_die_type): Update.
(get_die_type_at_offset): Update.

3 years agoRemove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data
Simon Marchi [Tue, 7 Apr 2020 22:05:22 +0000 (18:05 -0400)] 
Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data

The dwarf2_psymtab and dwarf2_per_cu_quick_data types contain a pointer
to a compunit_symtab, which is a pointer to the corresponding full
symtab.  The dwarf2_psymtab and dwarf2_per_cu_quick_data objects are
going to become objfile-independent, and possibly shared by multiple
objfiles, whereas compunit_symtab will stay objfile-dependent.  This
backlink to the compunit_symtab must therefore be removed.

This patch replaces them with a vector in the dwarf2_per_objfile type,
that serves as a mapping from dwarf2_per_cu_data objects to
compunit_symtab objects, for this particular objfile.  The vector is
indexed using the index assigned to the dwarf2_per_cu_data at its
creation.

I removed the get_compunit_symtab, as it appears to bring not much value
over calling dwarf2_per_objfile::get_symtab directly.

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

* dwarf2/read.h (struct dwarf2_per_bfd) <num_psymtabs>: New
method.
(struct dwarf2_per_objfile) <resize_symtabs, symtab_set_p,
get_symtab, set_symtab>: New methods.
<m_symtabs>: New field.
(struct dwarf2_psymtab): Derive from partial_symtab.
<readin_p, get_compunit_symtab>: Declare methods.
* dwarf2/read.c (dwarf2_per_objfile::symtab_set_p,
dwarf2_per_objfile::get_symtab, dwarf2_per_objfile::set_symtab):
New methods.
(struct dwarf2_per_cu_quick_data) <compunit_symtab>: Remove.
(dw2_do_instantiate_symtab, dw2_instantiate_symtab)
(dw2_map_expand_apply, dw2_map_symtabs_matching_filename)
(dw2_symtab_iter_next, dw2_print_stats)
(dw2_expand_symtabs_with_fullname)
(dw2_expand_symtabs_matching_one)
(dw_expand_symtabs_matching_file_matcher)
(dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames)
(dw2_debug_names_iterator::next)
(dw2_debug_names_map_matching_symbols)
(fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab)
(process_queue, dwarf2_psymtab::expand_psymtab): Update.
(dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab):
New methods.
(get_compunit_symtab, process_full_comp_unit)
(process_full_type_unit): Update.
(dwarf2_build_psymtabs, dwarf2_initialize_objfile, add_type_unit): Call

3 years agoSplit dwarf2_per_objfile into dwarf2_per_objfile and dwarf2_per_bfd
Simon Marchi [Mon, 6 Apr 2020 16:21:53 +0000 (12:21 -0400)] 
Split dwarf2_per_objfile into dwarf2_per_objfile and dwarf2_per_bfd

This is the first step of splitting dwarf2_per_objfile in two, one
structure for objfile-independent data (dwarf2_per_bfd) and one for
objfile-dependent data (dwarf2_per_objfile).

The existing dwarf2_per_objfile is renamed dwarf2_per_bfd, and a new
dwarf2_per_objfile type is introduced, which sits "in between" the
objfile and dwarf2_per_bfd.

So where we had this before:

  objfile -> dwarf2_per_objfile (*)

we now have this:

  objfile -> dwarf2_per_objfile -> dwarf2_per_bfd (*)

(*) Note that the dwarf2_per_objfile in the former corresponds to
the dwarf2_per_bfd in the latter.

I've done the minimal amount of changes in this patch: following patches
will incrementally move things that are not actually shareable between
objfiles from dwarf2_per_bfd to dwarf2_per_objfile.

Most references to dwarf2_per_objfile objects are changed to
dwarf2_per_objfile->per_bfd.  To avoid many of these replacements, which
would have to be reverted later anyway, I've moved right away the
objfile backlink to the new dwarf2_per_objfile structure in this patch.
I've also moved the read_line_string method, since it references the
objfile backlink, and it's actually not difficult to move.

Once the moves are completed, multiple dwarf2_per_objfile sharing the
same BFD will point to the same single instance of dwarf2_per_bfd (as
long as they don't require relocation).

dwarf2_has_info, where we create these objects, is updated to the new
architecture.

I've had to change the get_gdb_index_contents_ftype typedef and related
functions.  The parameter type was changed from dwarf2_per_objfile to
dwarf2_per_bfd, otherwise the template wouldn't work.

Please excuse the terse ChangeLog entry, I have not listed all the
functions where dwarf2_per_objfile has been changed to
dwarf2_per_objfile->per_bfd.  It would take a considerable amount of
time and would not really be useful in the end.

gdb/ChangeLog:

* dwarf2/read.h (dwarf2_per_objfile): Rename to dwarf2_per_bfd,
then introduce a new dwarf2_per_objfile type.
<read_line_string>: Move to the new dwarf2_per_objfile type.
<objfile>: Likewise.
(dwarf2_per_bfd): Rename dwarf2_per_objfile to this.
* dwarf2/read.c: Replace references to dwarf2_per_objfile with
dwarf2_per_objfile->per_bfd.
(dwarf2_per_objfile::dwarf2_per_objfile): Rename to...
(dwarf2_per_bfd::dwarf2_per_bfd): ... this.
(dwarf2_per_objfile::free_cached_comp_units): Rename to...
(dwarf2_per_bfd::free_cached_comp_units): ... this.
(dwarf2_has_info): Allocate dwarf2_per_bfd.
(dwarf2_per_objfile::locate_sections): Rename to...
(dwarf2_per_bfd::locate_sections): ... this.
(dwarf2_per_objfile::get_cutu): Rename to...
(dwarf2_per_bfd::get_cutu): ... this.
(dwarf2_per_objfile::get_cu): Rename to...
(dwarf2_per_bfd::get_cu): ... this.
(dwarf2_per_objfile::get_tu): Rename to...
(dwarf2_per_bfd::get_tu): ... this.
(dwarf2_per_objfile::allocate_per_cu): Rename to...
(dwarf2_per_bfd::allocate_per_cu): ... this.
(dwarf2_per_objfile::allocate_signatured_type): Rename to...
(dwarf2_per_bfd::allocate_signatured_type): ... this.
(get_gdb_index_contents_ftype): Change parameter from
dwarf2_per_objfile to dwarf2_per_bfd.
* dwarf2/macro.c, dwarf2/index-write.c: Replace references to
dwarf2_per_objfile with dwarf2_per_objfile->per_bfd.

3 years agoAdd dwarf2_per_objfile member to DWARF batons
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
Add dwarf2_per_objfile member to DWARF batons

Various DWARF callbacks expect to be able to fetch the objfile and / or
dwarf2_per_objfile from the DWARF CU object.  However, this won't be
possible once sharing is implemented.

Because these objects are related to full symbols (e.g., they are used
to implement location expressions), they can simply store the
dwarf2_per_objfile they need.

This patch adds a per_objfile member to the various "baton" structures
and arranges to set this value when constructing the baton.

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

* dwarf2/loc.c (struct piece_closure) <per_objfile>: New member.
(allocate_piece_closure): Set "per_objfile" member.
(dwarf2_find_location_expression, dwarf2_locexpr_baton_eval)
(locexpr_describe_location, loclist_describe_location): Use new
member.
* dwarf2/read.c (read_call_site_scope)
(mark_common_block_symbol_computed, attr_to_dynamic_prop)
(dwarf2_const_value_attr, dwarf2_fetch_die_loc_sect_off)
(fill_in_loclist_baton, dwarf2_symbol_mark_computed): Set
per_objfile member.
* dwarf2/loc.h (struct dwarf2_locexpr_baton) <per_objfile>: New
member.
(struct dwarf2_loclist_baton) <per_objfile>: New member.

3 years agoAdd dwarf2_per_cu_data::index
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
Add dwarf2_per_cu_data::index

Currently, a dwarf2_per_cu_data can hold a link to the corresponding
expanded compunit_symtab.  However, the dwarf2_per_cu_data objects are
shared across objfiles, a simple pointer won't work: each objfile
sharing the dwarf2_per_cu_data instance will have a corresponding
compunit_symtab.

Instead, this link will be stored in the dwarf2_per_objfile object
(which will contain the objfile-specific data).  To enable this, we add
an index to each dwarf2_per_cu_data and signatured_type.  The data
structure in the dwarf2_per_objfile will use this new index to map a
dwarf2_per_cu_data to its corresponding compunit_symtab, for this
objfile.

2020-02-21  Tom Tromey  <tom@tromey.com>

* dwarf2/read.h (struct dwarf2_per_objfile) <allocate_per_cu,
allocate_signatured_type>: Declare new methods.
<m_num_psymtabs>: New member.
(struct dwarf2_per_cu_data) <index>: New member.
* dwarf2/read.c (dwarf2_per_objfile::allocate_per_cu)
(dwarf2_per_objfile::allocate_signatured_type): New methods.
(create_cu_from_index_list): Use allocate_per_cu.
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(create_debug_type_hash_table, add_type_unit)
(read_comp_units_from_section): Use allocate_signatured_type.

3 years agoAdd "objfile" parameter to two partial_symtab methods
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
Add "objfile" parameter to two partial_symtab methods

This series will cause partial symtabs to be shared across objfiles.
However, full symtabs and symbols will still be objfile-dependent, so
will be expanded separately for each objfile.  So, a debug info reader
will need to know which objfile to consult when expanding a partial
symtab.

This patch adds an objfile parameter to the two relevant methods of
partial_symtab.  Current implementations simply ignore them.

2020-02-21  Tom Tromey  <tom@tromey.com>

* psymtab.c (partial_map_expand_apply)
(psym_find_pc_sect_compunit_symtab, psym_lookup_symbol)
(psym_lookup_global_symbol_language)
(psymtab_to_symtab, psym_find_last_source_symtab, dump_psymtab)
(psym_print_stats, psym_expand_symtabs_for_function)
(psym_map_symbol_filenames, psym_map_matching_symbols)
(psym_expand_symtabs_matching)
(partial_symtab::read_dependencies, maintenance_info_psymtabs)
(maintenance_check_psymtabs): Update.
* psympriv.h (struct partial_symtab) <readin_p,
get_compunit_symtab>: Add objfile parameter.
(struct standard_psymtab) <readin_p, get_compunit_symtab>:
Likewise.
* dwarf2/read.c (struct dwarf2_include_psymtab) <readin_p,
get_compunit_symtab>: Likewise.
(dwarf2_psymtab::expand_psymtab): Pass objfile argument.

3 years agoIntroduce dwarf2_per_objfile::obstack
Tom Tromey [Sat, 22 Feb 2020 00:47:36 +0000 (17:47 -0700)] 
Introduce dwarf2_per_objfile::obstack

Currently much of the DWARF-related data is stored on the objfile
obstack.  This prevents sharing this data across objfiles, so this patch
adds a new obstack to dwarf2_per_objfile.  Note that the
dwarf2_per_objfile type is going to become "dwarf2_per_bfd" in a
subsequent patch, which is indeed going to be shared between objfiles.

One way to check whether this is correct is to look at the remaining
uses of objfile_obstack in the DWARF code and note that they all
appear in the "full CU" code paths.

The converse -- storing per-objfile data on the shared obstack -- is
not good, but it is just a memory leak, not a potential
use-after-free.  Double-checking this would also be useful, though.

2020-02-21  Tom Tromey  <tom@tromey.com>

* dwarf2/read.h (struct dwarf2_per_objfile) <obstack>: New
member.
* dwarf2/read.c (delete_file_name_entry): Fix comment.
(create_cu_from_index_list)
(create_signatured_type_table_from_index)
(create_signatured_type_table_from_debug_names)
(dw2_get_file_names_reader, dwarf2_initialize_objfile)
(dwarf2_create_include_psymtab)
(create_debug_type_hash_table, add_type_unit)
(create_type_unit_group, read_comp_units_from_section)
(dwarf2_compute_name, create_cus_hash_table)
(create_dwp_hash_table, create_dwo_unit_in_dwp_v1)
(create_dwo_unit_in_dwp_v2, open_and_init_dwp_file): Use new
obstack.
(dw2_get_real_path): Likewise.  Change argument to
dwarf2_per_objfile.

3 years agogdb/testsuite: Disable path and duplicate checks when parallel testing
Andrew Burgess [Tue, 12 May 2020 16:38:17 +0000 (17:38 +0100)] 
gdb/testsuite: Disable path and duplicate checks when parallel testing

This commit disables the recently added checking for paths in test
names, and for duplicate test names, when the gdb tests are run in
parallel.

When running the gdb tests in parallel the extra result count lines
produced cause the dg-extract-results scripts to exit with an error.

The patches for the dg-extract-results scripts have been posted to the
gcc-patches mailing list here:

https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545562.html

Once they are merged there then these changes can be merged over to
binutils-gdb, and this commit can be reverted.

gdb/testsuite/ChangeLog:

* lib/check-test-names.exp: Disable when testing is being run in
parallel.

3 years agogdb: make two objfile functions return bool
Simon Marchi [Tue, 12 May 2020 15:17:01 +0000 (11:17 -0400)] 
gdb: make two objfile functions return bool

gdb/ChangeLog:

* objfiles.h (is_addr_in_objfile,
shared_objfile_contains_address_p): Return bool.
* objfile.c (is_addr_in_objfile,
shared_objfile_contains_address_p): Return bool.

3 years ago[gdb/testsuite] Fix incorrect string concat in jit-elf.exp
Tom de Vries [Tue, 12 May 2020 12:59:01 +0000 (14:59 +0200)] 
[gdb/testsuite] Fix incorrect string concat in jit-elf.exp

When running test-case gdb.base/jit-elf.exp with target board
cc-with-gdb-index, we get:
...
spawn -ignore SIGHUP gdb/contrib/cc-with-tweaks.sh -i gcc \
  -fno-stack-protector src/gdb/testsuite/gdb.base/jit-elf-main.c \
  -fdiagnostics-color=never -DATTACH=1 -DLOAD_ADDRESS=0x7000000 \
  -DLOAD_INCREMENT=0x1000000 -g -lm \
  -o outputs/gdb.base/jit-elf/jit-elf-main"-attach"^M
outputs/gdb.base/jit-elf/.tmp/jit-elf-main-attach: \
  No such file or directory.^M
output is:
outputs/gdb.base/jit-elf/.tmp/jit-elf-main-attach: \
  No such file or directory.^M

gdb compile failed, outputs/gdb.base/jit-elf/.tmp/jit-elf-main-attach: \
  No such file or directory.
UNTESTED: gdb.base/jit-elf.exp: failed to compile jit-elf-main"-attach"
...

The problem is a string concat in jit-elf.exp:
...
  ${main_binfile}"-attach"
...
which is intended to generate string 'jit-elf-main-attach' but instead
generates string 'jit-elf-main"-attach"'.

Fix this by using "${main_binfile}-attach" instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.base/jit-elf.exp: Fix string concat.

3 years ago[gdb/testsuite] Fix tcl error in jit-elf-helpers.exp
Tom de Vries [Tue, 12 May 2020 12:41:47 +0000 (14:41 +0200)] 
[gdb/testsuite] Fix tcl error in jit-elf-helpers.exp

When running test-case jit-elf.exp with target board cc-with-gdb-index, I run
into:
...
gdb compile failed, outputs/gdb.base/jit-elf/.tmp/jit-elf-main-attach: \
  No such file or directory.
ERROR: tcl error sourcing src/gdb/testsuite/gdb.base/jit-elf.exp.
ERROR: can't read "main_basename": no such variable
    while executing
"untested "failed to compile ${main_basename}.c""
    (procedure "compile_jit_main" line 7)
...

The problem is in compile_jit_main in lib/jit-elf-helpers.exp, where we try to
emit an untested message using global variable main_basename.c.

Fixing this by declaring the variable global results in duplicate test-names,
because the same source file is compiled more than once.

Instead, fix this by using the result name in the untested message.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* lib/jit-elf-helpers.exp: Don't use undefined variables in untested
messages.

3 years ago [PATCH] bfd: Fix 64-bit relocation handling for a.out
Gunther Nikl [Tue, 12 May 2020 11:18:09 +0000 (12:18 +0100)] 
 [PATCH] bfd: Fix 64-bit relocation handling for a.out

* aoutx.h (NAME (aout, swap_std_reloc_out)): Reject an unsupported
relocation size.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.multi
Tom de Vries [Tue, 12 May 2020 09:18:14 +0000 (11:18 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.multi

In gdb.multi we have:
...
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=run: inf2_how=run: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=run: inf2_how=attach: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=run: inf2_how=tty: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=attach: inf2_how=run: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=attach: inf2_how=attach: attach
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=attach: inf2_how=attach: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=attach: inf2_how=tty: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=tty: inf2_how=run: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=tty: inf2_how=attach: info inferiors
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=tty: inf2_how=tty: tty TTY
DUPLICATE: gdb.multi/multi-term-settings.exp: \
  inf1_how=tty: inf2_how=tty: info inferiors
...

Fix these using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.multi/multi-term-settings.exp: Use with_test_prefix.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.ada
Tom de Vries [Tue, 12 May 2020 09:05:44 +0000 (11:05 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.ada

In gdb.ada we have these duplicate test-names:
...
DUPLICATE: gdb.ada/catch_ex.exp: continuing to program completion
DUPLICATE: gdb.ada/mi_catch_ex.exp: breakpoint at main
DUPLICATE: gdb.ada/mi_catch_ex.exp: mi runto main
DUPLICATE: gdb.ada/mi_catch_ex_hand.exp: breakpoint at main
DUPLICATE: gdb.ada/mi_catch_ex_hand.exp: mi runto main
...

Fix these using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.ada/catch_ex.exp: Use with_test_prefix.
* gdb.ada/mi_catch_ex.exp: Same.
* gdb.ada/mi_catch_ex_hand.exp: Same.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.fortran
Tom de Vries [Tue, 12 May 2020 08:53:47 +0000 (10:53 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.fortran

In gdb.fortran we have:
...
DUPLICATE: gdb.fortran/complex.exp: whatis $
DUPLICATE: gdb.fortran/complex.exp: whatis $
DUPLICATE: gdb.fortran/complex.exp: whatis $
DUPLICATE: gdb.fortran/complex.exp: whatis $
...

Fix this by using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.fortran/complex.exp: Use with_test_prefix.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.trace
Tom de Vries [Tue, 12 May 2020 08:45:20 +0000 (10:45 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.trace

In gdb.trace we have these duplicates:
...
DUPLICATE: gdb.trace/passcount.exp: 4.20a: set all three passcounts to three
DUPLICATE: gdb.trace/passcount.exp: 4.6: set passcount to zero
DUPLICATE: gdb.trace/passcount.exp: 4.7: set passcount to large number (32767)
...

Fix these by fixing the test-names.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.trace/passcount.exp: Fix test-names.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.pascal
Tom de Vries [Tue, 12 May 2020 08:37:04 +0000 (10:37 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.pascal

In gdb.pascal we have these duplicates:
...
DUPLICATE: gdb.pascal/gdb11492.exp: next
DUPLICATE: gdb.pascal/gdb11492.exp: print char_array
...

Fix these by using with_test_prefix.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.pascal/gdb11492.exp: Use with_test_prefix.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.{gdb,opt,xml}
Tom de Vries [Tue, 12 May 2020 08:28:44 +0000 (10:28 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.{gdb,opt,xml}

There are 3 test directories with one duplicate test-name: gdb.gdb, gdb.opt
and gdb.xml.  The duplicates are:
...
DUPLICATE: gdb.gdb/complaints.exp: call complaint_internal ($cstr)
DUPLICATE: gdb.opt/inline-locals.exp: info locals above bar 2 \
  (PRMS: gdb/25695)
DUPLICATE: gdb.xml/tdesc-regs.exp: ptype $extrareg
...

Fix as appropriate.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.gdb/complaints.exp: Use with_test_prefix.
* gdb.xml/tdesc-regs.exp: Same.
* gdb.opt/inline-locals.exp: Fix test name.

3 years ago[gdb/testsuite] add jit-elf-util.h and run jit function
Mihails Strasuns [Tue, 18 Feb 2020 11:30:54 +0000 (12:30 +0100)] 
[gdb/testsuite] add jit-elf-util.h and run jit function

Splits ELF related symbols into a separate jit-elf-util.h header and
enhances it with a few more.

Intention is to make adding new JIT tests possible without repeating
most of the common boilerplate.

As a test enhancement, jit-elf-main.c now calls the renamed function
after registering the jit object and ensures it returns an expected
result.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

* gdb.base/jit-elf-util.h: New header file.
* gdb.base/jit-elf-main.c: Use jit-elf-util.h, add a call to
  the renamed JIT function to verify its result.

3 years ago[gdb/testsuite] define jit function name via macro
Mihails Strasuns [Fri, 27 Mar 2020 10:21:01 +0000 (11:21 +0100)] 
[gdb/testsuite] define jit function name via macro

Replaces previous approach with patching resulting ELF binary after
loading - now that each test iteration works on a separately compiled
binary it is not necessary anymore.

Tests are still being ran without debug info to preserve original test
functionality but this change opens up the possibility to enable debug
info if needed too.

gdb/testsuite/ChangeLog:

2020-03-27  Mihails Strasuns  <mihails.strasuns@intel.com>

* lib/jit-elf-helpers.exp: Supply -DFUNCTION_NAME macro
  definition when compiling jit-elf-solib.co.
* gdb.base/jit-elf-main.c: Stop patching jit function name.
* gdb.base/jit-elf-solib.c: Use FUNCTION_NAME macro value as a
  function name.

3 years ago[gdb/testsuite] use -Ttext-segment for jit-elf tests
Mihails Strasuns [Mon, 17 Feb 2020 10:36:47 +0000 (11:36 +0100)] 
[gdb/testsuite] use -Ttext-segment for jit-elf tests

Removes the need to manually relocate loaded ELF binary by using a fixed
constant as both mmap base address and as a requested first segment
address supplied to the linker.

In future will enable JIT tests with a valid DWARF debug info.  Current
tests still need to compile without a debug info though, because they do
a function name modification.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

* lib/jit-elf-helpers.exp: Supply -Ttext-segment linker flag and
  define LOAD_ADDRESS/LOAD_INCREMENT macros for the compiled binaries.
* gdb.base/jit-elf-main.c: Use LOAD_ADDRESS/LOAD_INCREMENT to
  calculate the mmap address.

3 years ago[gdb/testsuite] add lib/jit-elf-helpers.exp
Mihails Strasuns [Mon, 17 Feb 2020 10:24:14 +0000 (11:24 +0100)] 
[gdb/testsuite] add lib/jit-elf-helpers.exp

New utility library to be used by jit-elf tests responsible for
compiling binary artifacts. In the next commit the compilation process
will become more complicated because of extra mandatory flag - keeping
it in one place will make tests less fragile.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

* lib/jit-elf-helpers.exp: New file.
* gdb.base/jit-elf.exp: Updated to use jit-elf-helpers.exp.
* gdb.base/jit-elf-so.exp: Updated to use jit-elf-helpers.exp.

3 years ago[gdb/testsuite] use args as lib list for jit-elf tests
Mihails Strasuns via Gdb-patches [Tue, 31 Mar 2020 17:13:51 +0000 (19:13 +0200)] 
[gdb/testsuite] use args as lib list for jit-elf tests

Old usage: jit-elf-main lib.so 2
New usage: jit-elf-main lib.so.1 lib.so.2

Refactoring necessary to support running tests over multiple jit
binaries rather than mapping the same binary muultiple times.

gdb/testsuite/ChangeLog:

2020-02-18  Mihails Strasuns  <mihails.strasuns@intel.com>

* gdb.base/jit-elf-main.c: Read lib list from argc/argv.
* gdb.base/jit-elf.exp: Compile N jit libraries and use the list.
* gdb.base/jit-elf-so.exp: Ditto.

3 years ago[gdb/testsuite] Fix duplicate test-names in gdb.dwarf2
Tom de Vries [Tue, 12 May 2020 07:47:15 +0000 (09:47 +0200)] 
[gdb/testsuite] Fix duplicate test-names in gdb.dwarf2

We currently have these duplicate test-names in gdb.dwarf2:
...
$ grep ^DUPLICATE: gdb.sum
DUPLICATE: gdb.dwarf2/comp-unit-lang.exp: show language
DUPLICATE: gdb.dwarf2/data-loc.exp: get integer valueof "sizeof (int)"
DUPLICATE: gdb.dwarf2/data-loc.exp: get integer valueof "sizeof (void *)"
DUPLICATE: gdb.dwarf2/data-loc.exp: get integer valueof "sizeof (int)"
DUPLICATE: gdb.dwarf2/data-loc.exp: get integer valueof "sizeof (int)"
DUPLICATE: gdb.dwarf2/data-loc.exp: ptype foo.array_type
DUPLICATE: gdb.dwarf2/varval.exp: get integer valueof "sizeof (int)"
DUPLICATE: gdb.dwarf2/varval.exp: get integer valueof "sizeof (void *)"
DUPLICATE: gdb.dwarf2/implref-struct.exp: print-object=off: \
  set print object off
DUPLICATE: gdb.dwarf2/implref-struct.exp: print-object=on: \
  set print object on
DUPLICATE: gdb.dwarf2/dw2-bad-parameter-type.exp: ptype f
...

Fix as appropriate.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-12  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/comp-unit-lang.exp: Use with_test_prefix.
* gdb.dwarf2/dw2-bad-parameter-type.exp: Same.
* gdb.dwarf2/implref-struct.exp: Same.
* gdb.dwarf2/varval.exp: Ensure get_sizeof is called once per type.
* gdb.dwarf2/data-loc.exp: Same.  Remove duplicate test.

3 years agogdb: change duplicate test name in gdb.base/jit-so.exp
Simon Marchi [Tue, 12 May 2020 00:10:35 +0000 (20:10 -0400)] 
gdb: change duplicate test name in gdb.base/jit-so.exp

When running gdb.base/jit-so.exp, we see duplicate test names:

$ grep PASS testsuite/gdb.sum | sort | uniq -c | sort -n
      ...
      2 PASS: gdb.base/jit-so.exp: one_jit_test-1: info function jit_function
      2 PASS: gdb.base/jit-so.exp: one_jit_test-2: info function jit_function

Give an explicit name to one test to avoid this.

gdb/testsuite/ChangeLog:

* gdb.base/jit-so.exp (one_jit_test): Change test name.

3 years agoAutomatic date update in version.in
GDB Administrator [Tue, 12 May 2020 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoRegen ld/Makefile.in
Alan Modra [Mon, 11 May 2020 23:48:06 +0000 (09:18 +0930)] 
Regen ld/Makefile.in

Missed from c578f16ef18fd.

3 years agoRestore info_command and breakpoint
Tom Tromey [Mon, 11 May 2020 21:28:12 +0000 (15:28 -0600)] 
Restore info_command and breakpoint

As discussed on gdb-patches, this restores info_command and the
breakpoint on info_command in gdb-gdb.gdb.  This reverts a tiny part
of 0743fc83c03 ("Replace most calls to help_list and cmd_show_list"),
as well as 652fc23a30a ("Remove gdb-gdb.gdb breakpoint on disappeared
function info_command.").

gdb/ChangeLog
2020-05-11  Tom Tromey  <tromey@adacore.com>

* cli/cli-cmds.c (info_command): Restore.
(_initialize_cli_cmds): Use add_prefix_command for "info".
* gdb-gdb.gdb.in: Restore breakpoint on info_command.

3 years agogdb/testsuite: Detect and warn about duplicate test names
Andrew Burgess [Thu, 23 Apr 2020 14:19:15 +0000 (15:19 +0100)] 
gdb/testsuite: Detect and warn about duplicate test names

Building on the previous commit, this patch detects when two tests
have the same test name and causes Dejagnu to print a new result type
'# of duplicate test names' in the result summary.  A line starting
with 'DUPLICATE: ' is also added to the gdb.sum and gdb.log files.

The DUPLICATE markers will be printed the second time a duplicate test
name is seen, and every time after that.  So you might see:

  PASS: gdb.base/sometest.exp: foo
  PASS: gdb.base/sometest.exp: bar
  PASS: gdb.base/sometest.exp: foo
  DUPLICATE: gdb.base/sometest.exp: foo
  PASS: gdb.base/sometest.exp: baz
  PASS: gdb.base/sometest.exp: foo
  DUPLICATE: gdb.base/sometest.exp: foo

However, the results will report a duplicate count of 1, indicating
that just one test name (foo) was duplicated.

Currently if the tests are run in parallel mode the new result type is
not merged into the combined summary file so users will need to run in
non-parallel mode to check this result.  Similarly, the 'DUPLICATE: '
markers will not be merged into the final gdb.sum file.  A later
commit will fix this.

gdb/testsuite/ChangeLog:

* lib/check-test-names.exp (all_test_names): New module variable.
(counts): Add 'duplicates' field.
(_check_duplicates): New procedure.
(check): Also check for duplicates.
(do_log_summary): Print duplicates count.
(do_reset_vars): Reset counter for duplicate test names, and
discard all know test names.

3 years agogdb/testsuite: Detect and warn if paths are used in test names
Andrew Burgess [Thu, 23 Apr 2020 09:47:29 +0000 (10:47 +0100)] 
gdb/testsuite: Detect and warn if paths are used in test names

A new library is introduced that hooks into the core of Dejagnu and
detects when a test's name includes either the source or build paths.
If any offending test names are detected then Dejagnu will print a
new result type, '# of paths in test names'.  Users should treat this
result type just like other bad results types, and aim not to increase
this number.

As well as displaying the total number of offending tests as part of
the final results, a new marker is included in both the gdb.log and
gdb.sum files, this marker starts with 'PATH: ', so an offending test
would be expected to appear like this:

  PASS: gdb.base/sometest.exp: Loaded /path/to/build/testsuite/foo.exe
  PATH: gdb.base/sometest.exp: Loaded /path/to/build/testsuite/foo.exe

This should make it easier to track down offending tests.

Currently for a local run on my machine, I don't see any offending
test names, but it is possible that different targets, or different
configurations, might currently be breaking the no paths rule.

In order to get this working I have needed to wrap two core Dejagnu
functions, log_summary, and reset_vars.  Relying on core functions
that are not part of any API is always going to be risky, given the
relatively slow rate of Dejagnu change this is probably OK for now,
and we can possibly upstream some changes to Dejagnu that would allow
this functionality to be supported in a more official way later on.

Currently if the tests are run in parallel mode the new result type is
not merged into the combined summary file so users will need to run in
non-parallel mode to check this result.  Similarly, the 'PATH: '
markers will not be merged into the combined summary file.  A later
commit will fix this.

gdb/testsuite/ChangeLog:

* lib/gdb.exp: Include check-test-names.exp library.
* lib/check-test-names.exp: New file.

3 years agoFix Ada value printing on PPC64
Tom Tromey [Mon, 11 May 2020 20:57:49 +0000 (14:57 -0600)] 
Fix Ada value printing on PPC64

The val_print removal patches introduced an Ada regression on PPC64
(probably any big-endian system).

The issue comes because value_field does not understand that Ada
wrapper fields can be bitfields that wrap a non-scalar type.  In this
case the value is already left-justified, so the justification done
there does the wrong thing.

Perhaps it would be good, eventually, to change value_field to
understand this case.  In the meantime this implements an Ada-specific
solution.

gdb/ChangeLog
2020-05-11  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_value_primitive_field): Now public.
* ada-lang.h (ada_value_primitive_field): Declare.
* ada-valprint.c (print_field_values): Use
ada_value_primitive_field for wrapper fields.

3 years ago[gdb/testsuite] Change kfail into xfail in gdb.ada/packed_tagged.exp
Tom de Vries [Mon, 11 May 2020 20:30:18 +0000 (22:30 +0200)] 
[gdb/testsuite] Change kfail into xfail in gdb.ada/packed_tagged.exp

Test-case gdb.ada/packed_tagged.exp contains a kfail:
...
setup_kfail "gnat compiler bug" *-*-*
...

Kfails are used to indicate problems in gdb, xfails are used to indicate
problems in the environment.

A bug in the gnat compiler is a problem in the environment rather than gdb.

Fix this by changing the kfail into an xfail.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-05-11  Tom de Vries  <tdevries@suse.de>

* gdb.ada/packed_tagged.exp: Change kfail into xfail.

3 years agoFix gdb.ada/attr_ref_and_charlit.exp typo
Keith Seitz [Mon, 11 May 2020 19:22:25 +0000 (12:22 -0700)] 
Fix gdb.ada/attr_ref_and_charlit.exp typo

... introduced by my last commit:

-gdb_test "print s'last"  " = 3"
+    gdb_test "print s'last"  " = 3Z

gdb/testsuite/ChangeLog
2020-05-11  Keith Seitz  <keiths@redhat.com>

* gdb.ada/attr_ref_and_charlit.exp: Fix typo.

3 years ago[gdb/testsuite] Fix gdb.cp/cpexprs-debug-types.exp inclusion
Tom de Vries [Mon, 11 May 2020 18:36:11 +0000 (20:36 +0200)] 
[gdb/testsuite] Fix gdb.cp/cpexprs-debug-types.exp inclusion

When running tests using RUNTESTFLAGS="cpexprs.exp cpexprs-debug-types.exp",
we have:
...
Running src/gdb/testsuite/gdb.cp/cpexprs-debug-types.exp ...
Running src/gdb/testsuite/gdb.cp/cpexprs.exp ...
...

In the first test-case, we have -fdebug-types-section as expected:
...
Running src/gdb/testsuite/gdb.cp/cpexprs-debug-types.exp ...
g++ -fno-stack-protector -fdiagnostics-color=never \
  -fdebug-types-section \
  -c -g \
  -o outputs/gdb.cp/cpexprs-debug-types/cpexprs-debug-types0.o \
  src/gdb/testsuite/gdb.cp/cpexprs.cc
...
but in the second test-case, we have also have -fdebug-types-section:
...
Running src/gdb/testsuite/gdb.cp/cpexprs.exp ...
g++ -fno-stack-protector -fdiagnostics-color=never \
  -fdebug-types-section \
  -c -g -g \
  -o outputs/gdb.cp/cpexprs/cpexprs0.o \
  src/gdb/testsuite/gdb.cp/cpexprs.cc
...

This is due to using a global variable flags, which is set in
cpexprs-debug-types.exp and tested for existence in cpexprs.exp.

Fix this by using a more robust inclusion mechanism, that is:
- move the bulk of the test-case cpexprs.exp to cpexprs.exp.in,
- include it from cpexprs.exp and cpexprs-debug-types.exp, and
- set flags in both .exp files

gdb/testsuite/ChangeLog:

2020-05-11  Tom de Vries  <tdevries@suse.de>

* gdb.cp/cpexprs.exp: Move everything except flags setting ...
* gdb.cp/cpexprs.exp.in: .. here.
* gdb.cp/cpexprs-debug-types.exp: Include cpexprs.exp.in instead of
cpexprs.exp.

3 years agoClean-up gdb.ada test names
Keith Seitz [Mon, 11 May 2020 17:27:32 +0000 (10:27 -0700)] 
Clean-up gdb.ada test names

This patch fixes all duplicate and tail parentheses test names.
These can really hinder automated test analysis such as used by
the buildbot.

Before:
$ cat testsuite/gdb.sum | egrep "^(PASS|FAIL|XPASS|XFAIL|KPASS|KFAIL)" \
  | sort | uniq -c | sort -n | grep -v " 1 "
      2 PASS: gdb.ada/attr_ref_and_charlit.exp: print s'last
      2 PASS: gdb.ada/bp_on_var.exp: set breakpoint pending off
      2 PASS: gdb.ada/complete.exp: complete p pck.inne
      2 PASS: gdb.ada/fun_overload_menu.exp: multiple matches for f (f (1, null))
      2 PASS: gdb.ada/type_coercion.exp: p q
      2 PASS: gdb.ada/unc_arr_ptr_in_var_rec.exp: print My_P_Object.Ptr when no longer null
      3 PASS: gdb.ada/fun_overload_menu.exp: 1

After:
<empty>

For parentheses, I've audited all occurrences of trailing parentheses.
Most offenders are of the form:

   gdb_test "p func (..)" $expected_result

I've either added a unique test name or simply removed the whitespace
between the function name and the argument list.

gdb/testsuite/ChangeLog
2020-05-11  Keith Seitz  <keiths@redhat.com>

* gdb.ada/arrayparam.exp: Resolve duplicate and tail parentheses
test names.
* gdb.ada/arrayptr.exp: Likewise.
* gdb.ada/assign_arr.exp: Likewise.
* gdb.ada/attr_ref_and_charlit.exp: Likewise.
* gdb.ada/bp_on_var.exp: Likewise.
* gdb.ada/call_pn.exp: Likewise.
* gdb.ada/complete.exp: Likewise.
* gdb.ada/fun_overload_menu.exp: Likewise.
* gdb.ada/funcall_param.exp: Likewise.
* gdb.ada/funcall_ref.exp: Likewise.
* gdb.ada/packed_array_assign.exp: Likewise.
* gdb.ada/same_component_name.exp: Likewise.
* gdb.ada/type_coercion.exp: Likewise.
* gdb.ada/unc_arr_ptr_in_var_rec.exp: Likewise.
* gdb.ada/variant_record_packed_array.exp: Likewise.

3 years ago[gdb/symtab] Save modules in .debug_names
Tom de Vries [Mon, 11 May 2020 15:13:49 +0000 (17:13 +0200)] 
[gdb/symtab] Save modules in .debug_names

When running test-case gdb.fortran/info-modules.exp with target board
debug-names, I run into:
...
FAIL: gdb.fortran/info-modules.exp: info modules: check for entry \
  'info-types-2.f90', '18', 'mod2'
...

In more detail, comparing the behaviour of the executable without and with
.debug_names section, we have:
...
-$ gdb -batch info-modules -ex "info modules"
+$ gdb -batch info-modules.debugnames -ex "info modules"
 All defined modules:

-File /data/gdb_versions/devel/src/gdb/testsuite/gdb.fortran/info-types-2.f90:
-18:     mod2
-
 File /data/gdb_versions/devel/src/gdb/testsuite/gdb.fortran/info-types.f90:
 16:     mod1
...

This is due to the fact that the .debug_names section does not contain
DW_TAG_module entries.

Fix this in debug_names::psymbol_tag.

Build and tested on x86_64-linux with target board debug-names.

gdb/ChangeLog:

2020-05-11  Tom de Vries  <tdevries@suse.de>

* dwarf2/index-write.c (debug_names::psymbol_tag): Handle
MODULE_DOMAIN.

3 years ago[gdb/symtab] Fix incomplete CU list assert in .debug_names
Tom de Vries [Mon, 11 May 2020 13:03:54 +0000 (15:03 +0200)] 
[gdb/symtab] Fix incomplete CU list assert in .debug_names

Consider the following two-file test-case:
...
$ cat main.c
extern int foo (void);

int
main (void)
{
  int sum, a, b;
  sum = a + b + foo ();
  return sum;
}
$ cat foo.c
int
foo (void)
{
  return 3;
}
...

Compiled like this:
...
$ clang-10 -gdwarf-5 -gpubnames -c main.c
$ clang-10 -gdwarf-5 -c foo.c
$ clang-10 -gdwarf-5 -gpubnames main.o foo.o
...

When loading this exec into gdb, we run into this assert:
...
$ gdb a.out
Reading symbols from a.out...

warning: Section .debug_aranges in a.out entry at offset 0 \
  debug_info_offset 0 does not exists, ignoring .debug_aranges.
src/gdb/dwarf2/read.c:6949: \
  internal-error: cutu_reader::cutu_reader(dwarf2_per_cu_data*, \
                              abbrev_table*, int, bool): \
  Assertion `this_cu->length == cu->header.get_length ()' failed.
...

The problem is that the determined length of the CU:
...
(gdb) p /x this_cu->length
$4 = 0x26a
...
does not match the actual length:
...
(gdb) p /x cu->header.get_length ()
$5 = 0x59
...

The length of the CU is determined in create_cus_from_debug_names_list, and
set based on this list in the .debug_names section:
...
  Compilation Unit offsets [
    CU[0]: 0x000000c7
  ]
...
and it is assumed that this is a complete list, so the size of the CU is
calculated using the end of the .debug_section at 0x331, making it 0x331 -
0xc7 == 0x26a.

However, the CU list is not complete:
...
$ llvm-dwarfdump -debug-info a.out \
  | grep "Compile Unit" \
  | sed 's/Compile Unit.*//'
0x00000000:
0x0000002e:
0x000000a5:
0x000000c7:
0x00000120:
0x00000157:
0x0000030f:
...
In particular, because the CU for foo.c is there at 0x120 (the rest of the CUs
is due to openSUSE having debug info for various linked in objects).

Fix the assert by not assuming to know the length of CUs in
create_cus_from_debug_names_list (if the .debug_names is not produced by GDB),
and setting it to 0, and setting it later to the actual length.

Note that this does not fix the .debug_aranges warning, that's PR25969.

Build and tested on x86_64-linux, with native and debug-names.

gdb/ChangeLog:

2020-05-11  Tom de Vries  <tdevries@suse.de>

PR symtab/25941
* dwarf2/read.c (create_cus_from_debug_names_list): Initialize CUs
with length 0, if not gdb-produced.
(cutu_reader::cutu_reader): Set CU length to actual length if 0.

gdb/testsuite/ChangeLog:

2020-05-11  Tom de Vries  <tdevries@suse.de>

PR symtab/25941
* gdb.dwarf2/clang-debug-names.exp.in: New include exp file, factored
out of ...
* gdb.dwarf2/clang-debug-names.exp: ... here.
* gdb.dwarf2/clang-debug-names-2.exp: New file.  Include
clang-debug-names.exp.in.
* gdb.dwarf2/clang-debug-names-2-foo.c: New test.
* gdb.dwarf2/clang-debug-names-2.c: New test.

3 years agoPower10 VSX scalar min-max-compare quad precision operations
Alan Modra [Mon, 11 May 2020 00:19:29 +0000 (09:49 +0930)] 
Power10 VSX scalar min-max-compare quad precision operations

opcodes/
* ppc-opc (powerpc_opcodes): Add xscmpeqqp, xscmpgeqp, xscmpgtqp,
xsmaxcqp, xsmincqp.
gas/
* testsuite/gas/ppc/scalarquad.d,
* testsuite/gas/ppc/scalarquad.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 VSX load/store rightmost element operations
Alan Modra [Mon, 11 May 2020 00:18:29 +0000 (09:48 +0930)] 
Power10 VSX load/store rightmost element operations

opcodes/
* ppc-opc.c (powerpc_opcodes): Add lxvrbx, lxvrhx, lxvrwx, lxvrdx,
stxvrbx, stxvrhx, stxvrwx, stxvrdx.
gas/
* testsuite/gas/ppc/rightmost.d,
* testsuite/gas/ppc/rightmost.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 test lsb by byte operation
Alan Modra [Mon, 11 May 2020 00:17:38 +0000 (09:47 +0930)] 
Power10 test lsb by byte operation

opcodes/
* ppc-opc.c (powerpc_opcodes): Add xvtlsbb.
gas/
* testsuite/gas/ppc/xvtlsbb.d,
* testsuite/gas/ppc/xvtlsbb.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 string operations
Alan Modra [Mon, 11 May 2020 00:16:45 +0000 (09:46 +0930)] 
Power10 string operations

opcodes/
* ppc-opc.c (powerpc_opcodes): Add vstribl, vstribr, vstrihl, vstrihr,
vclrlb, vclrrb, vstribl., vstribr., vstrihl., vstrihr..
gas/
* testsuite/gas/ppc/stringop.d,
* testsuite/gas/ppc/stringop.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 Set boolean extension
Peter Bergner [Mon, 11 May 2020 00:15:42 +0000 (09:45 +0930)] 
Power10 Set boolean extension

opcodes/
* ppc-opc.c (powerpc_opcodes) <setbc, setbcr, setnbc, setnbcr>: New
mnemonics.
gas/
* testsuite/gas/ppc/set_bool.d,
* testsuite/gas/ppc/set_bool.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 bit manipulation operations
Alan Modra [Mon, 11 May 2020 00:14:25 +0000 (09:44 +0930)] 
Power10 bit manipulation operations

opcodes/
* ppc-opc.c (UIM8, P_U8XX4_MASK): Define.
(powerpc_opcodes): Add vgnb, vcfuged, vpextd, vpdepd, vclzdm,
vctzdm, cntlzdm, pdepd, pextd, cfuged, cnttzdm.
(prefix_opcodes): Add xxeval.
gas/
* testsuite/gas/ppc/bitmanip.d,
* testsuite/gas/ppc/bitmanip.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 VSX PCV generate operations
Alan Modra [Mon, 11 May 2020 00:13:15 +0000 (09:43 +0930)] 
Power10 VSX PCV generate operations

opcodes/
* ppc-opc.c (powerpc_opcodes): Add xxgenpcvbm, xxgenpcvhm,
xxgenpcvwm, xxgenpcvdm.
gas/
* testsuite/gas/ppc/genpcv.d,
* testsuite/gas/ppc/genpcv.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 VSX Mask Manipulation Operations
Alan Modra [Mon, 11 May 2020 00:11:57 +0000 (09:41 +0930)] 
Power10 VSX Mask Manipulation Operations

opcodes/
* ppc-opc.c (MP, VXVAM_MASK): Define.
(VXVAPS_MASK): Use VXVA_MASK.
(powerpc_opcodes): Add mtvsrbmi, vexpandbm, vexpandhm, vexpandwm,
vexpanddm, vexpandqm, vextractbm, vextracthm, vextractwm,
vextractdm, vextractqm, mtvsrbm, mtvsrhm, mtvsrwm, mtvsrdm, mtvsrqm,
vcntmbb, vcntmbh, vcntmbw, vcntmbd.
gas/
* testsuite/gas/ppc/maskmanip.d,
* testsuite/gas/ppc/maskmanip.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 Reduced precision outer product operations
Alan Modra [Mon, 11 May 2020 00:10:42 +0000 (09:40 +0930)] 
Power10 Reduced precision outer product operations

include/
* opcode/ppc.h (PPC_OPERAND_ACC): Define.  Renumber following
PPC_OPERAND defines.
opcodes/
* ppc-opc.c (insert_xa6a, extract_xa6a, insert_xb6a, extract_xb6a):
New functions.
(powerpc_operands): Define ACC, PMSK8, PMSK4, PMSK2, XMSK, YMSK,
YMSK2, XA6a, XA6ap, XB6a entries.
(PMMIRR, P_X_MASK, P_XX1_MASK, P_GER_MASK): Define
(P_GER2_MASK, P_GER4_MASK, P_GER8_MASK, P_GER64_MASK): Define.
(PPCVSX4): Define.
(powerpc_opcodes): Add xxmfacc, xxmtacc, xxsetaccz,
xvi8ger4pp, xvi8ger4, xvf16ger2pp, xvf16ger2, xvf32gerpp, xvf32ger,
xvi4ger8pp, xvi4ger8, xvi16ger2spp, xvi16ger2s, xvbf16ger2pp,
xvbf16ger2, xvf64gerpp, xvf64ger, xvi16ger2, xvf16ger2np,
xvf32gernp, xvi8ger4spp, xvi16ger2pp, xvbf16ger2np, xvf64gernp,
xvf16ger2pn, xvf32gerpn, xvbf16ger2pn, xvf64gerpn, xvf16ger2nn,
xvf32gernn, xvbf16ger2nn, xvf64gernn, xvcvbf16sp, xvcvspbf16.
(prefix_opcodes): Add pmxvi8ger4pp, pmxvi8ger4, pmxvf16ger2pp,
pmxvf16ger2, pmxvf32gerpp, pmxvf32ger, pmxvi4ger8pp, pmxvi4ger8,
pmxvi16ger2spp, pmxvi16ger2s, pmxvbf16ger2pp, pmxvbf16ger2,
pmxvf64gerpp, pmxvf64ger, pmxvi16ger2, pmxvf16ger2np, pmxvf32gernp,
pmxvi8ger4spp, pmxvi16ger2pp, pmxvbf16ger2np, pmxvf64gernp,
pmxvf16ger2pn, pmxvf32gerpn, pmxvbf16ger2pn, pmxvf64gerpn,
pmxvf16ger2nn, pmxvf32gernn, pmxvbf16ger2nn, pmxvf64gernn.
gas/
* config/tc-ppc.c (pre_defined_registers): Add accumulators.
(md_assemble): Check acc specified in correct operand.
* testsuite/gas/ppc/outerprod.d,
* testsuite/gas/ppc/outerprod.s,
* testsuite/gas/ppc/vsx4.d,
* testsuite/gas/ppc/vsx4.s: New tests.
* testsuite/gas/ppc/ppc.exp: Run them.

3 years agoPower10 SIMD permute class operations
Alan Modra [Mon, 11 May 2020 00:07:14 +0000 (09:37 +0930)] 
Power10 SIMD permute class operations

opcodes/
* ppc-opc.c (insert_imm32, extract_imm32): New functions.
(insert_xts, extract_xts): New functions.
(IMM32, UIM3, IX, UIM5, SH3, XTS, P8RR): Define.
(P_XX4_MASK, P_UXX4_MASK, VSOP, P_VS_MASK, P_VSI_MASK): Define.
(VXRC_MASK, VXSH_MASK): Define.
(powerpc_opcodes): Add vinsbvlx, vsldbi, vextdubvlx, vextdubvrx,
vextduhvlx, vextduhvrx, vextduwvlx, vextduwvrx, vextddvlx,
vextddvrx, vinshvlx, vinswvlx, vinsw, vinsbvrx, vinshvrx,
vinswvrx, vinsd, vinsblx, vsrdbi, vinshlx, vinswlx, vinsdlx,
vinsbrx, vinshrx, vinswrx, vinsdrx, lxvkq.
(prefix_opcodes): Add xxsplti32dx, xxspltidp, xxspltiw, xxblendvb,
xxblendvh, xxblendvw, xxblendvd, xxpermx.
gas/
* testsuite/gas/ppc/simd_perm.d,
* testsuite/gas/ppc/simd_perm.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 128-bit binary integer operations
Alan Modra [Mon, 11 May 2020 00:06:11 +0000 (09:36 +0930)] 
Power10 128-bit binary integer operations

opcodes/
* ppc-opc.c (powerpc_opcodes): Add vrlq, vdivuq, vmsumcud, vrlqmi,
vmuloud, vcmpuq, vslq, vdivsq, vcmpsq, vrlqnm, vcmpequq, vmulosd,
vsrq, vdiveuq, vcmpgtuq, vmuleud, vsraq, vdivesq, vcmpgtsq, vmulesd,
vcmpequq., vextsd2q, vmoduq, vcmpgtuq., vmodsq, vcmpgtsq., xscvqpuqz,
xscvuqqp, xscvqpsqz, xscvsqqp, dcffixqq, dctfixqq.
gas/
* testsuite/gas/ppc/int128.d,
* testsuite/gas/ppc/int128.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 VSX 32-byte storage access
Alan Modra [Mon, 11 May 2020 00:04:49 +0000 (09:34 +0930)] 
Power10 VSX 32-byte storage access

bfd/
* elf64-ppc.c (xlate_pcrel_opt): Handle lxvp and stxvp.
opcodes/
* ppc-opc.c (insert_xtp, extract_xtp): New functions.
(XTP, DQXP, DQXP_MASK): Define.
(powerpc_opcodes): Add lxvp, stxvp, lxvpx, stxvpx.
(prefix_opcodes): Add plxvp and pstxvp.
gas/
* testsuite/gas/ppc/vsx_32byte.d,
* testsuite/gas/ppc/vsx_32byte.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.
ld/
* testsuite/ld-powerpc/pcrelopt.s: Add lxvp and stxvp.
* testsuite/ld-powerpc/pcrelopt.d: Update.

3 years agoPower10 vector integer multiply, divide, modulo insns
Alan Modra [Mon, 11 May 2020 00:02:56 +0000 (09:32 +0930)] 
Power10 vector integer multiply, divide, modulo insns

opcodes/
* ppc-opc.c (powerpc_opcodes): Add vdivuw, vdivud, vdivsw, vmulld,
vdivsd, vmulhuw, vdiveuw, vmulhud, vdiveud, vmulhsw, vdivesw,
vmulhsd, vdivesd, vmoduw, vmodud, vmodsw, vmodsd.
gas/
* testsuite/gas/ppc/vec_mul.s,
* testsuite/gas/ppc/vec_mul.d: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 byte reverse instructions
Peter Bergner [Mon, 11 May 2020 00:01:40 +0000 (09:31 +0930)] 
Power10 byte reverse instructions

opcodes/
* ppc-opc.c (powerpc_opcodes) <brd, brh, brw>: New mnemonics.
gas/
* testsuite/gas/ppc/byte_rev.d,
* testsuite/gas/ppc/byte_rev.s: New test.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPower10 Copy/Paste Extensions
Peter Bergner [Mon, 11 May 2020 00:00:19 +0000 (09:30 +0930)] 
Power10 Copy/Paste Extensions

opcodes/
* opcodes/ppc-opc.c (insert_l1opt, extract_l1opt): New functions.
(L1OPT): Define.
(powerpc_opcodes) <paste.>: Add L operand for cpu POWER10.
gas/
* testsuite/gas/ppc/power10.d: Add paste. tests.
* testsuite/gas/ppc/power10.s: Likewise.

3 years agoPower10 Add new L operand to the slbiag instruction
Peter Bergner [Sun, 10 May 2020 23:57:48 +0000 (09:27 +0930)] 
Power10 Add new L operand to the slbiag instruction

opcodes/
* ppc-opc.c (powerpc_opcodes) <slbiag>: Add variant with L operand.
gas/
* testsuite/gas/ppc/power10.s: New test.
* testsuite/gas/ppc/power10.d: Likewise.
* testsuite/gas/ppc/ppc.exp: Run it.

3 years agoPowerPC Default disassembler to -Mpower10
Alan Modra [Sun, 10 May 2020 23:55:30 +0000 (09:25 +0930)] 
PowerPC Default disassembler to -Mpower10

* ppc-dis.c (powerpc_init_dialect): Default to "power10".

3 years agoPowerPC Rename powerxx to power10
Alan Modra [Sun, 10 May 2020 23:54:14 +0000 (09:24 +0930)] 
PowerPC Rename powerxx to power10

Now that ISA3.1 is out we can finish with the powerxx silliness.

bfd/
* elf64-ppc.c: Rename powerxx to power10 throughout.
gas/
* config/tc-ppc.c (md_assemble): Update for PPC_OPCODE_POWER10
renaming.
* testsuite/gas/ppc/prefix-align.d: Use -mpower10/-Mpower10 in
place of -mfuture/-Mfuture.
* testsuite/gas/ppc/prefix-pcrel.d: Likewise.
* testsuite/gas/ppc/prefix-reloc.d: Likewise.
gold/
* powerpc.cc: Rename powerxx to power10 throughout.
include/
* elf/ppc64.h: Update comment.
* opcode/ppc.h (PPC_OPCODE_POWER10): Rename from PPC_OPCODE_POWERXX.
ld/
* testsuite/ld-powerpc/callstub-1.d: Use -mpower10/-Mpower10 in
place of -mfuture/-Mfuture.
* testsuite/ld-powerpc/notoc2.d: Likewise.
* testsuite/ld-powerpc/powerpc.exp: Likewise.
* testsuite/ld-powerpc/tlsgd.d: Likewise.
* testsuite/ld-powerpc/tlsie.d: Likewise.
* testsuite/ld-powerpc/tlsld.d: Likewise.
opcodes/
* ppc-dis.c (ppc_opts): Add "power10" entry.
(print_insn_powerpc): Update for PPC_OPCODE_POWER10 renaming.
* ppc-opc.c (POWER10): Rename from POWERXX.  Update all uses.

3 years agoUpdated French translation for the ld sub-directory and an update Spanish translation...
Nick Clifton [Mon, 11 May 2020 11:02:26 +0000 (12:02 +0100)] 
Updated French translation for the ld sub-directory and an update Spanish translation for the opcodes subdirectory.

3 years agoPR25961, buffer overflow in coff_swap_aux_in
Alan Modra [Mon, 11 May 2020 08:30:31 +0000 (18:00 +0930)] 
PR25961, buffer overflow in coff_swap_aux_in

PR 25961
* coffgen.c (coff_get_normalized_symtab): Check that buffer
contains required number of auxents before processing any auxent.
* coffswap.h (coff_swap_aux_in <C_FILE>): Only swap in extended
file name from auxents for PE.

3 years agoAutomatic date update in version.in
GDB Administrator [Mon, 11 May 2020 00:00:07 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agogdb/fortran: Allow Flang MAIN_ in Fortran testing
Alok Kumar Sharma [Sun, 10 May 2020 19:12:00 +0000 (00:42 +0530)] 
gdb/fortran: Allow Flang MAIN_ in Fortran testing

Name of fortran main function for Flang compiler is MAIN_ while
for gfortran it is MAIN__ . In test cases MAIN__ is hardcoded for
the purpose of inserting breakpoint.

New proc is added to detect main function name depending on the
compiler used.
Fortran specific version of runto_main named fortran_runto_main
is added.

This commit adds support for Flang main function, there should be
no change for gfortran.

gdb/testsuite/ChangeLog

* lib/fortran.exp (fortran_main): New Proc, handle flang MAIN_,
(fortran_runto_main): New Proc, fortran version of runto_main.
* gdb.fortran/array-bounds-high.exp: Handle flang MAIN_.
* gdb.fortran/array-bounds.exp: Likewise.
* gdb.fortran/array-slices.exp: Likewise.
* gdb.fortran/block-data.exp: Likewise.
* gdb.fortran/charset.exp: Likewise.
* gdb.fortran/common-block.exp: Likewise.
* gdb.fortran/complex.exp: Likewise.
* gdb.fortran/derived-type-function.exp: Likewise.
* gdb.fortran/derived-type.exp: Likewise.
* gdb.fortran/info-modules.exp: Likewise.
* gdb.fortran/info-types.exp: Likewise.
* gdb.fortran/intrinsics.exp: Likewise.
* gdb.fortran/library-module.exp: Likewise.
* gdb.fortran/logical.exp: Likewise.
* gdb.fortran/max-depth.exp: Likewise.
* gdb.fortran/module.exp: Likewise.
* gdb.fortran/multi-dim.exp: Likewise.
* gdb.fortran/nested-funcs.exp: Likewise.
* gdb.fortran/print-formatted.exp: Likewise.
* gdb.fortran/print_type.exp: Likewise.
* gdb.fortran/printing-types.exp: Likewise.
* gdb.fortran/ptr-indentation.exp: Likewise.
* gdb.fortran/ptype-on-functions.exp: Likewise.
* gdb.fortran/subarray.exp: Likewise.
* gdb.fortran/vla-alloc-assoc.exp: Likewise.
* gdb.fortran/vla-datatypes.exp: Likewise.
* gdb.fortran/vla-history.exp: Likewise.
* gdb.fortran/vla-ptr-info.exp: Likewise.
* gdb.fortran/vla-ptype-sub.exp: Likewise.
* gdb.fortran/vla-ptype.exp: Likewise.
* gdb.fortran/vla-sizeof.exp: Likewise.
* gdb.fortran/vla-type.exp: Likewise.
* gdb.fortran/vla-value-sub-arbitrary.exp: Likewise.
* gdb.fortran/vla-value-sub-finish.exp: Likewise.
* gdb.fortran/vla-value-sub.exp: Likewise.
* gdb.fortran/vla-value.exp: Likewise.
* gdb.fortran/whatis_type.exp: Likewise.
* gdb.mi/mi-var-child-f.exp: Likewise.

3 years agoAutomatic date update in version.in
GDB Administrator [Sun, 10 May 2020 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years ago[gdb] Fix catch throw regexp matching
Tom de Vries [Sat, 9 May 2020 18:17:10 +0000 (20:17 +0200)] 
[gdb] Fix catch throw regexp matching

When running test-case gdb.mi/mi-catch-cpp-exceptions.exp, we have:
...
FAIL: gdb.mi/mi-catch-cpp-exceptions.exp: all with invalid regexp: run until \
  breakpoint in main (unknown output after running)
...

This is a regression since commit 596dc4adff "Speed up psymbol reading by
removing a copy".

Before that commit, we have:
...
$ gdb \
    -batch \
    ./outputs/gdb.mi/mi-catch-cpp-exceptions/mi-catch-cpp-exceptions \
    -ex "break 67" \
    -ex "catch throw -r blahblah" \
    -ex r
Breakpoint 1 at 0x4008e5: file mi-catch-cpp-exceptions.cc, line 67.
Catchpoint 2 (throw)

Breakpoint 1, main () at mi-catch-cpp-exceptions.cc:67
67                  return 1;   /* Stop here.  */
...
In other words:
- we set a breakpoint somewhere in main,
- we set a catchpoint with a regexp that is intended to not match any
  exception, and
- run to the breakpoint, without the catchpoint triggering.

After the commit, we have:
...
$ gdb \
    -batch \
    ./outputs/gdb.mi/mi-catch-cpp-exceptions/mi-catch-cpp-exceptions \
    -ex "break 67" \
    -ex "catch throw -r blahblah" \
    -ex r
Breakpoint 1 at 0x4008e5: file mi-catch-cpp-exceptions.cc, line 67.
Catchpoint 2 (throw)

Catchpoint 2 (exception thrown), 0x00007ffff7ab037e in __cxa_throw () from \
  /usr/lib64/libstdc++.so.6
...
In other words, the catchpoint triggers.

This is caused by this bit of the commit:
...
       type_name = cplus_typename_from_type_info (typeinfo_arg);

       canon = cp_canonicalize_string (type_name.c_str ());
-      if (!canon.empty ())
-       std::swap (type_name, canon);
+      name = (canon == nullptr
+       ? canon.get ()
+       : type_name.c_str ());
     }
   catch (const gdb_exception_error &e)
     {
       exception_print (gdb_stderr, e);
     }

-  if (!type_name.empty ())
+  if (name != nullptr)
     {
-      if (self->pattern->exec (type_name.c_str (), 0, NULL, 0) != 0)
+      if (self->pattern->exec (name, 0, NULL, 0) != 0)
...

Before the commit, we have:
- type_name == "my_exception"
- canon = ""
and the !type_name.empty () test succeeds, and gdb executes the
self->pattern->exec call.

After the commit, we have:
- type_name == "my_exception"
- canon == NULL
- name == NULL
and the name != nullptr test fails, and gdb doesn't execute the
self->pattern->exec call.

Fix this by inverting the condition for the calculation of name:
...
-      name = (canon == nullptr
+      name = (canon != nullptr
...

Build and tested on x86_64-linux.

gdb/ChangeLog:

2020-05-09  Tom de Vries  <tdevries@suse.de>

PR gdb/25955
* break-catch-throw.c (check_status_exception_catchpoint): Fix name
calculation.

3 years agoChange server_command to bool
Tom Tromey [Sat, 9 May 2020 18:04:58 +0000 (12:04 -0600)] 
Change server_command to bool

I noticed that "server_command" is an int, but really it should be a
bool.

gdb/ChangeLog
2020-05-09  Tom Tromey  <tom@tromey.com>

* top.c (server_command): Now bool.
* top.h (server_command): Now bool.

3 years agoFix for the complaint observed when symbol reading due to unsupported .debug_names...
nitachra [Sat, 9 May 2020 08:03:51 +0000 (10:03 +0200)] 
Fix for the complaint observed when symbol reading due to unsupported .debug_names form

Following complaint is observed with the executable compiled with -gdwarf-5
and -gpubnames flags - "During symbol reading: Unsupported .debug_names form
DW_FORM_ref4".  This is the form corresponding to DW_IDX_die_offset attribute.
This patch fixes this complaint.  Tested with clang 10.0.0.  Test case used -

int main()
{
int sum,a,b;
sum = a + b;
return sum;
}

clang -gdwarf-5 -gpubnames test.c -o test.out

gdb -q test.out -ex "set complaints 1" -ex "start"

Reading symbols from test.out...
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 \
  [in module test.out]
Temporary breakpoint 1 at 0x400484
Starting program: test.out
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 \
  [in module test.out]
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 \
  [in module test.out]
During symbol reading: Unsupported .debug_names form DW_FORM_ref4 \
  [in module test.out]

gdb/dwarf2/ChangeLog:

2020-05-09  Nitika Achra  <Nitika.Achra@amd.com>

PR symtab/25952
* read.c (dw2_debug_names_iterator::next): Handle DW_FORM_ref*
and DW_IDX_die_offset.  If there is no compilation unit attribute in
the index entry, then there is a single CU.  Return the CU at O index
of compilation unit vector.

gdb/testsuite/ChangeLog:

2020-05-09  Tom de Vries  <tdevries@suse.de>

* gdb.dwarf2/clang-debug-names.exp: Remove PR25952 kfail.

3 years agoAutomatic date update in version.in
GDB Administrator [Sat, 9 May 2020 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

3 years agoDon't re-process a DIE in read_lexical_block_scope
Tom Tromey [Fri, 8 May 2020 20:26:11 +0000 (14:26 -0600)] 
Don't re-process a DIE in read_lexical_block_scope

A customer reported a crash in the DWARF reader.

Investigation showed that the crash occurred in an unusual scenario: a
function was lexically scoped within some other function -- but the
inner function inlined the outer function and referred to its DIE via
DW_AT_abstract_origin.  With the executable in question,
inherit_abstract_dies could eventually call read_lexical_block_scope,
which in turn could recurse into process_die, to process a DIE that
was already being read, triggering an assert.

This came up once before; see:

https://www.sourceware.org/ml/gdb-patches/2014-02/msg00652.html

However, in this case, I don't have an easy way to reproduce.  So,
there is no test case.

I did experiment with the failing executable.  This patch fixes the
bug and doesn't seem to cause other issues.  For example, I can still
set breakpoints on the relevant functions.

gdb/ChangeLog
2020-05-08  Tom Tromey  <tromey@adacore.com>

* dwarf2/read.c (read_lexical_block_scope): Don't process a DIE
already being processed.