Commit Graph

1203 Commits

Author SHA1 Message Date
Tom Tromey 2b4424c35b Add initial type alignment support
This adds some basic type alignment support to gdb.  It changes struct
type to store the alignment, and updates dwarf2read.c to handle
DW_AT_alignment.  It also adds a new gdbarch method and updates
i386-tdep.c.

None of this new functionality is used anywhere yet, so tests will
wait until the next patch.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* i386-tdep.c (i386_type_align): New function.
	(i386_gdbarch_init): Update.
	* gdbarch.sh (type_align): New method.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arch-utils.h (default_type_align): Declare.
	* arch-utils.c (default_type_align): New function.
	* gdbtypes.h (TYPE_ALIGN_BITS): New define.
	(struct type) <align_log2>: New field.
	<instance_flags>: Now a bitfield.
	(TYPE_RAW_ALIGN): New macro.
	(type_align, type_raw_align, set_type_align): Declare.
	* gdbtypes.c (type_align, type_raw_align, set_type_align): New
	functions.
	* dwarf2read.c (quirk_rust_enum): Set type alignment.
	(get_alignment, maybe_set_alignment): New functions.
	(read_structure_type, read_enumeration_type, read_array_type)
	(read_set_type, read_tag_pointer_type, read_tag_reference_type)
	(read_subrange_type, read_base_type): Set type alignment.
2018-04-30 11:25:30 -06:00
Simon Marchi d33bc52e51 Use bool in read_index_from_section
gdb/ChangeLog:

	* dwarf2read.c (read_index_from_section): Use bool.
2018-04-30 11:06:57 -04:00
Tom Tromey 632e107b32 Enable -Wsuggest-override
I noticed the existence of -Wsuggest-override and so this patch
enables it for gdb.  It found a few spots that could use "override".
Also I went ahead and removed all uses of the "OVERRIDE" macro.

Using override is beneficial because it makes it harder to change a
base class and then forget to change a derived class.

Tested by the buildbot.

ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* warning.m4 (AM_GDB_WARNINGS): Add -Wsuggest-override.
	* dwarf2loc.c (class dwarf_evaluate_loc_desc): Use "override", not
	"OVERRIDE".
	(class symbol_needs_eval_context): Likewise.
	* dwarf2read.c (mock_mapped_index::symbol_name_count)
	(mock_mapped_index::symbol_name_at): Use "override".  Remove
	"virtual".
	* dwarf2-frame.c (dwarf_expr_executor::get_addr_index): Use
	"override".
	(class dwarf_expr_executor): Use "override", not "OVERRIDE".
	* aarch64-tdep.c (instruction_reader::read): Use "override".
	(instruction_reader_test::read): Likewise.
	* arm-tdep.c (instruction_reader::read): Use "override".
	(instruction_reader_thumb::read): Likewise.

gdbserver/ChangeLog
2018-04-27  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
2018-04-27 12:53:14 -06:00
Tom Tromey bedda9aced Conditionally drop the discriminant field in quirk_rust_enum
While debugging the crash that Jan reported, I noticed that in some
situations we could end up with a situation where one branch of a Rust
enum type ended up with a field count of -1.

The fix is simple: only conditionally drop the discriminant field when
rewriting the enum variants.

I couldn't find a way to test this; I only noticed it while debugging
the DWARF reader.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (quirk_rust_enum): Conditionally drop the
	discriminant field.
2018-04-17 13:37:44 -06:00
Tom Tromey a037790ec5 Fix crash in quirk_rust_enum
I noticed that quirk_rust_enum can crash when presented with a union
whose fields are all scalar types.

This patch adds a new test case and fixes the bug.

Regression tested on Fedora 26 x86-64.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (quirk_rust_enum): Handle unions correctly.

2018-04-17  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.rs (Union): New type.
	(main): New local "u".
	* gdb.rust/simple.exp (test_one_slice): Add new test case.
2018-04-17 13:37:44 -06:00
Simon Marchi b2bdb8cf39 Make dwarf2_per_objfile::all_type_units an std::vector
Make all_type_units an std::vector, remove
n_type_units/n_allocated_type_units and some manual memory management.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <n_type_units>:
	Remove.
	<n_allocated_type_units>: Remove.
	<all_type_units>: Change to std::vector.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
	to std::vector change.
	(dwarf2_per_objfile::get_cutu): Likewise.
	(dwarf2_per_objfile::get_tu): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(create_signatured_type_table_from_debug_names): Likewise.
	(dw2_symtab_iter_next): Likewise.
	(dw2_print_stats): Likewise.
	(dw2_expand_all_symtabs): Likewise.
	(dw2_expand_marked_cus): Likewise.
	(dw2_debug_names_iterator::next): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(add_signatured_type_cu_to_table): Likewise.
	(create_all_type_units): Likewise.
	(add_type_unit): Likewise.
	(struct tu_abbrev_offset): Add constructor.
	(build_type_psymtabs_1): Adjust to std::vector change.
	(print_tu_stats): Likewise.
	* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
	(write_debug_names): Likewise.
2018-04-07 13:53:44 -04:00
Simon Marchi b76e467de3 Make dwarf2_per_objfile::all_comp_units an std::vector
Make all_comp_units an std::vector, remove n_comp_units and some manual
memory management.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise.
	Make an std::vector.
	<n_comp_units>: Remove.
	* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust
	to std::vector change.
	(dwarf2_per_objfile::get_cutu): Likewise.
	(dwarf2_per_objfile::get_cu): Likewise.
	(create_cus_from_index): Likewise.
	(create_addrmap_from_index): Likewise.
	(create_addrmap_from_aranges): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_find_last_source_symtab): Likewise.
	(dw2_map_symtabs_matching_filename): Likewise.
	(dw2_symtab_iter_next): Likewise.
	(dw2_print_stats): Likewise.
	(dw2_expand_all_symtabs): Likewise.
	(dw2_expand_symtabs_with_fullname): Likewise.
	(dw2_expand_marked_cus): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(create_cus_from_debug_names): Likewise.
	(dwarf2_read_debug_names): Likewise.
	(dw2_debug_names_iterator::next): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(set_partial_user): Likewise.
	(dwarf2_build_psymtabs_hard): Likewise.
	(read_comp_units_from_section): Remove arguments, adjust to
	std::vector change.
	(create_all_comp_units): Adjust to std::vector and
	read_comp_units_from_section changes.
	(dwarf2_find_containing_comp_unit): Adjust to std::vector
	change.
	* dwarf-index-write.c (check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
2018-04-07 13:53:43 -04:00
Simon Marchi 12359b5e8f Remove some usages of get_dwarf2_per_objfile
This patch removes some usages of get_dwarf2_per_objfile, where we can
get hold of the dwarf2_per_objfile object in a simpler way.  For
example, it's simpler (and slightly less work) to pass
dwarf2_per_objfile and get the objfile from it than to pass the objfile
and call get_dwarf2_per_objfile.

Ideally, get_dwarf2_per_objfile should only be used in the entry points
of the dwarf2 code, where we receive an objfile.

gdb/ChangeLog:

	* dwarf2read.c (create_cus_from_index_list): Replace objfile arg
	with dwarf2_per_objfile.
	(create_cus_from_index): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(dwarf2_read_index): Likewise.
	(dwarf2_initialize_objfile): Likewise.
	(dwarf2_fetch_die_loc_sect_off):  Get dwarf2_per_objfile from
	per_cu rather than get_dwarf2_per_objfile.
2018-04-07 13:53:42 -04:00
Simon Marchi ff4c9fec84 Replace dw2_get_cu/dw2_get_cutu with methods of dwarf2_per_objfile
Those two functions look like good candidates to become methods of
dwarf2_per_objfile.  I did that, and added get_tu as well.  When
replacing usages of dw2_get_cutu, I changed some instances to get_cutu
and others to get_cu, when appropriate (when we know we want a CU and
not a TU).

gdb/ChangeLog:

	* dwarf2read.h (struct signatured_type): Forward declare.
	(struct dwarf2_per_objfile) <get_cutu, get_cu, get_tu>:
	New methods.
	* dwarf2read.c (dwarf2_per_objfile::get_cutu): Rename from...
	(dw2_get_cutu): ...this.
	(dwarf2_per_objfile::get_cu): Rename from...
	(dw2_get_cu): ...this.
	(dwarf2_per_objfile::get_tu): New.
	(create_addrmap_from_index): Adjust.
	(create_addrmap_from_aranges): Adjust.
	(dw2_find_last_source_symtab): Adjust.
	(dw2_map_symtabs_matching_filename): Adjust.
	(dw2_symtab_iter_next): Adjust.
	(dw2_print_stats): Adjust.
	(dw2_expand_all_symtabs): Adjust.
	(dw2_expand_symtabs_with_fullname): Adjust.
	(dw2_expand_marked_cus): Adjust.
	(dw_expand_symtabs_matching_file_matcher): Adjust.
	(dw2_map_symbol_filenames): Adjust.
	(dw2_debug_names_iterator::next): Adjust.
	(dwarf2_initialize_objfile): Adjust.
	(set_partial_user): Adjust.
	(dwarf2_build_psymtabs_hard): Adjust.
2018-04-07 13:53:41 -04:00
Simon Marchi 5ca3fcb669 Remove some unused variables in dwarf2read.c
Most of them are obvious.  The ones in dwarf2_record_block_ranges are
less obvious, because it is a bit suspicious to have that many
variables unused.  But after inspection, it seems like it dates from
commit 5f46c5a548 ("Code cleanup: Split dwarf2_ranges_read to a
callback"), where dwarf2_record_block_ranges was made to use
dwarf2_ranges_process, which contains the same functionality.

gdb/ChangeLog:

	* dwarf2read.c (create_signatured_type_table_from_debug_names):
	Remove unused variables.
	(dw2_map_symtabs_matching_filename): Likewise.
	(dwarf2_record_block_ranges): Likewise.
	(dwarf2_read_addr_index): Likewise.
	(follow_die_offset): Likewise.
2018-04-07 13:53:39 -04:00
Tom Tromey 22bc8444e6 Introduce a gdb_ref_ptr specialization for struct value
struct value is internally reference counted and so, while it also has
some ownership rules unique to it, it makes sense to use a gdb_ref_ptr
when managing it automatically.

This patch removes the existing unique_ptr specialization in favor of
a reference-counted pointer.  It also introduces two other
clarifications:

1. Rename value_free to value_decref, which I think is more in line
   with what the function actually does; and

2. Change release_value to return a gdb_ref_ptr.  This change allows
   us to remove the confusing release_value_or_incref function,
   primarily by making it much simpler to reason about the result of
   release_value.

gdb/ChangeLog
2018-04-06  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_clear_saved_item)
	(update_dynamic_varobj_children, install_new_value, ~varobj):
	Update.
	* value.h (value_incref): Move declaration earlier.
	(value_decref): Rename from value_free.
	(struct value_ref_policy): New.
	(value_ref_ptr): New typedef.
	(struct value_deleter): Remove.
	(gdb_value_up): Remove typedef.
	(release_value): Change return type.
	(release_value_or_incref): Remove.
	* value.c (set_value_parent): Update.
	(value_incref): Change return type.
	(value_decref): Rename from value_free.
	(value_free_to_mark, free_all_values, free_value_chain): Update.
	(release_value): Return value_ref_ptr.
	(release_value_or_incref): Remove.
	(record_latest_value, set_internalvar, clear_internalvar):
	Update.
	* stack.c (info_frame_command): Don't call value_free.
	* python/py-value.c (valpy_dealloc, valpy_new)
	(value_to_value_object): Update.
	* printcmd.c (do_examine): Update.
	* opencl-lang.c (lval_func_free_closure): Update.
	* mi/mi-main.c (register_changed_p): Don't call value_free.
	* mep-tdep.c (mep_frame_prev_register): Don't call value_free.
	* m88k-tdep.c (m88k_frame_prev_register): Don't call value_free.
	* m68hc11-tdep.c (m68hc11_frame_prev_register): Don't call
	value_free.
	* guile/scm-value.c (vlscm_free_value_smob)
	(vlscm_scm_from_value): Update.
	* frame.c (frame_register_unwind, frame_unwind_register_signed)
	(frame_unwind_register_unsigned, get_frame_register_bytes)
	(put_frame_register_bytes): Don't call value_free.
	* findvar.c (address_from_register): Don't call value_free.
	* dwarf2read.c (dwarf2_compute_name): Don't call value_free.
	* dwarf2loc.c (entry_data_value_free_closure)
	(value_of_dwarf_reg_entry, free_pieced_value_closure)
	(dwarf2_evaluate_loc_desc_full): Update.
	* breakpoint.c (update_watchpoint, breakpoint_init_inferior)
	(~bpstats, bpstats, bpstat_clear_actions, watchpoint_check)
	(~watchpoint, watch_command_1)
	(invalidate_bp_value_on_memory_change): Update.
	* alpha-tdep.c (alpha_register_to_value): Don't call value_free.
2018-04-06 15:44:46 -06:00
Tom Tromey 263db9a1f4 Remove free_dwo_file_cleanup
This removes free_dwo_file_cleanup, the last cleanup in dwarf2read.c.
This is replaced with a unique_ptr; which, despite the fact that a
dwo_file is obstack-allocated, seemed like the best fit.

gdb/ChangeLog
2018-03-30  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct free_dwo_file_cleanup_data): Remove.
	(struct dwo_file_deleter): New.
	(dwo_file_up): New typedef.
	(open_and_init_dwo_file): Use dwo_file_up.
	(free_dwo_file_cleanup): Remove.
2018-03-30 13:15:58 -06:00
Tom Tromey 5dafb3d176 Remove parameter from free_dwo_file
The objfile parameter to free_dwo_file is unused, so remove it.

gdb/ChangeLog
2018-03-30  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (free_dwo_file): Remove "objfile" parameter.
	(free_dwo_file_cleanup, free_dwo_file_from_slot): Update.
2018-03-30 13:15:57 -06:00
Tom Tromey 11ed8cada6 Remove free_cached_comp_units cleanups
This changes free_cached_comp_units from a cleanup function to an RAII
class.

gdb/ChangeLog
2018-03-30  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (class free_cached_comp_units): New class.
	(dw2_instantiate_symtab, dwarf2_build_psymtabs_hard): Use it.
	(free_cached_comp_units): Remove function.
2018-03-30 13:15:57 -06:00
Simon Marchi cd4fb1b2ff Move DWARF index-related things to a separate file
I want to add a DWARF index-related feature (automatically produce index
files when loading objfiles in GDB), but I don't want to add many
hundred lines to the already too big dwarf2read.c.  I thought it would
be a logical split to move everything related to the DWARF index to its
own file.

I first tried to move everything that reads and writes DWARF indices to
a separate file, but found that the "read" part is a little bit
entangled with the rest of dwarf2read.c, so the line is hard to draw
about where to split.  The write part is quite isolated though, so I
moved this part to a new file, dwarf-index-write.c.  Some things are
necessary to both reading and writing indices, so I placed them in
dwarf-index-common.{c,h}.  The idea would be to have a
dwarf-index-read.c eventually that would use it too (for now that code
is still in dwarf2read.c).

This required moving some things to a new dwarf2read.h header, so they
can be read by the code that writes the index.

The patch is big in number of lines, but it's all existing code being
moved around.  The only changes are that some functions are not static
anymore, a declaration is added in a .h file, and therefore the comment
is moved there.

I built-tested it with a little and big endian target.

This patch is also available on the users/simark/split-dwarf2read
branch.

gdb/ChangeLog:

	* Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and
	dwarf-index-write.c
	(HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h.
	* dwarf-index-common.c: New file.
	* dwarf-index-common.h: New file.
	* dwarf-index-write.c: New file.
	* dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h.
	(struct dwarf2_section_info): Move from here.
	(dwarf2_section_info_def): Likewise.
	(DEF_VEC_O (dwarf2_section_info_def)): Likewise.
	(offset_type): Likewise.
	(DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise.
	(DW2_GDB_INDEX_CU_SET_VALUE): Likewise.
	(byte_swap): Likewise.
	(MAYBE_SWAP): Likewise.
	(dwarf2_per_cu_ptr): Likewise.
	(DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise.
	(struct tu_stats): Likewise.
	(struct dwarf2_per_objfile): Likewise.
	(struct dwarf2_per_cu_data): Likewise.
	(struct signatured_type): Likewise.
	(sig_type_ptr): Likewise.
	(DEF_VEC_P (sig_type_ptr)): Likewise.
	(INDEX4_SUFFIX): Likewise.
	(INDEX5_SUFFIX): Likewise.
	(DEBUG_STR_SUFFIX): Likewise.
	(dwarf2_read_section): Make non-static.
	(mapped_index_string_hash): Move from here.
	(dwarf5_djb_hash): Likewise.
	(file_write): Likewise.
	(class data_buf): Likewise.
	(struct symtab_index_entry): Likewise.
	(struct mapped_symtab): Likewise.
	(find_slot): Likewise.
	(hash_expand): Likewise.
	(add_index_entry): Likewise.
	(uniquify_cu_indices): Likewise.
	(class c_str_view): Likewise.
	(class c_str_view_hasher): Likewise.
	(class vector_hasher): Likewise.
	(write_hash_table): Likewise.
	(psym_index_map): Likewise.
	(struct addrmap_index_data): Likewise.
	(add_address_entry): Likewise.
	(add_address_entry_worker): Likewise.
	(write_address_map): Likewise.
	(symbol_kind): Likewise.
	(write_psymbols): Likewise.
	(struct signatured_type_index_data): Likewise.
	(write_one_signatured_type): Likewise.
	(recursively_count_psymbols): Likewise.
	(recursively_write_psymbols): Likewise.
	(class debug_names): Likewise.
	(check_dwarf64_offsets): Likewise.
	(psyms_seen_size): Likewise.
	(write_gdbindex): Likewise.
	(write_debug_names): Likewise.
	(assert_file_size): Likewise.
	(write_psymtabs_to_index): Likewise.
	(save_gdb_index_command): Likewise.
	(_initialize_dwarf2_read): Don't register the "save gdb-index"
	command.
	* dwarf2read.h: New file.
2018-03-27 10:07:47 -04:00
Joel Brobecker 59cc4834e5 problem looking up some symbols when they have a linkage name
This patch fixes a known failure in gdb.ada/maint_with_ada.exp
(maintenance check-psymtabs). Another way to witness the same
issue is by considering the following Ada declarations...

   type Wrapper is record
      A : Integer;
   end record;
   u00045 : constant Wrapper := (A => 16#060287af#);
   pragma Export (C, u00045, "symada__cS");

... which declares a variable name "u00045" but with a linkage
name which is "symada__cS". This variable is a record with one
component, the Ada equivalent of a struct with one field in C.
Trying to print that variable's value currently yields:

    (gdb) p /x <symada__cS>
    'symada(char, signed)' has unknown type; cast it to its declared type

This indicates that GDB was only able to find the minimal symbol,
but not the full symbol. The expected output is:

    (gdb) print /x <symada__cS>
    $1 = (a => 0x60287af)

The error message gives a hint about what's happening: We processed
the symbol through gdb_demangle, which in the case of this particular
symbol name, ends up matching the C++ naming scheme. As a result,
the demangler transforms our symbol name into 'symada(char, signed)',
thus breaking Ada lookups.

This patch fixes the issue by first introducing a new language_defn
attribute called la_store_sym_names_in_linkage_form_p, which is a boolean
to be set to true for the few languages that do not want their symbols
to have their names stored in demangled form, and false otherwise.
We then use this language attribute to skip the call to gdb_demangle
for all languages whose la_store_sym_names_in_linkage_form_p is true.

In terms of the selection of languages for which the new attribute
is set to true, the selection errs on the side of preserving the
existing behavior, and only changes the behavior for the languages
where we are certain storing symbol names in demangling form is not
needed. It is conceivable that other languages might be in the same
situation, but I not knowing in detail the symbol name enconding
strategy, I decided to play it safe and let other language maintainers
potentially adjust their language if it makes sense to do so.

gdb/ChangeLog:

        PR gdb/22670
        * dwarf2read.c (dwarf2_physname): Do not return the demangled
        symbol name if the CU's language stores symbol names in linkage
        format.
        * language.h (struct language_defn)
        <la_store_sym_names_in_linkage_form_p>: New field.  Adjust
        all instances of this struct.

gdb/testsuite/ChangeLog:

        * gdb.ada/maint_with_ada.exp: Remove PR gdb/22670 setup_kfail.

        * gdb.ada/notcplusplus: New testcase.

        * gdb.base/c-linkage-name.c: New file.
        * gdb.base/c-linkage-name.exp: New testcase.

Tested on x86_64-linux.
This also passes AdaCore's internal GDB testsuite.
2018-03-27 09:57:16 -04:00
Simon Marchi 9f034d7573 Remove DEF_VEC_I(offset_type)
It is unused.

gdb/ChangeLog:

	* dwarf2read.c (DEF_VEC_I(offset_type)): Remove.
2018-03-26 15:46:21 -04:00
Keith Seitz b7fee5a326 Add psymbols for nested types
c++/22968 involves the inability of ptype to find a type definition for
a type defined inside another type.  I recently added some additional
support for nested type definitions, but I apparently overlooked psymbols.

The user reports that using -readnow fixes the problem:

$ gdb 22968 -ex "ptype Outer::Inner"
There is no field named Inner

$ gdb -readnow 22968 -ex "ptype Outer::Inner"
type = struct Outer::Inner {
  <no data field>
}

We clearly did not find a psymbol for Outer::Inner because it was located
in another CU.  This patch addresses this problem by scanning structs
for additional psymbols.  Rust is already doing this.

With this patch, the identical result to "-readnow" is given (without
using `-readnow', of course).

gdb/ChangeLog:

	PR c++/22968
	* dwarf2read.c (scan_partial_symbols): Scan structs/classes for
	nested type definitions for C++, too.

gdb/testsuite/ChangeLog:

	PR c++/22968
	* gdb.cp/subtypes.exp: New file.
	* gdb.cp/subtypes.h: New file.
	* gdb.cp/subtypes.cc: New file.
	* gdb.cp/subtypes-2.cc: New file.
2018-03-23 11:58:32 -07:00
Tom Tromey be2daae6b8 Use std::vector for field lists in dwarf2read.c
This changes dwarf2read.c to use std::vector rather than a linked list
when managing the fields and base classes to be added to a type.  This
removes some bookkeeping types and also allows the removal of some
cleanups.

gdb/ChangeLog
2018-03-11  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct nextfield): Add initializers.
	(struct nextfnfield): Remove.
	(struct fnfieldlist): Add initializers.  Remove "length" and
	"head", use std::vector.
	(struct decl_field_list): Remove.
	(struct field_info): Add initializers.
	<fields, baseclasses>: Now std::vector.
	<nbaseclasses, nfnfields, typedef_field_list_count,
	nested_types_list_count>: Remove.
	(dwarf2_add_field, dwarf2_add_type_defn)
	(dwarf2_attach_fields_to_type, dwarf2_add_member_fn)
	(dwarf2_attach_fn_fields_to_type, handle_struct_member_die)
	(process_structure_scope): Update.
2018-03-11 21:06:41 -06:00
Tom Tromey 484cf504af Remove cleanup from build_type_psymtabs_1
This removes a cleanup from build_type_psymtabs_1, by using
std::vector rather than manual memory management.

gdb/ChangeLog
2018-03-11  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (sort_tu_by_abbrev_offset): Change to be suitable
	for use by std::sort.
	(build_type_psymtabs_1): Use std::vector.
2018-03-11 21:06:41 -06:00
Tom Tromey c7b15a66dc Fix Rust enum test failures
Pedro pointed out that some Rust tests were failing after the recent
enum change.  I was able to reproduce this even with the most current
Rust compiler -- no test was failing, but rather the gdb internal
error was causing an "untested" result, which I didn't notice.

The internal error is caused by a bad assertion in
alloc_discriminant_info.  This happened because, in an earlier version
of the patch, the discriminant could only appear at index 0.  However,
it can now appear anywhere.  This patch fixes the assertion in the
obvious way, and adds a second assertion to ensure that the
discriminant is also correct.

Fixing this revealed a real failure, which was caused by using the
wrong base name when computing the name of a univariant enum's sole
member.  This is also fixed here.

Tested by running the gdb.rust tests with rustc 1.23 and
double-checking the summary:

    # of expected passes		276

Note that if you try this yourself, it is still possible to get an
"untested" result from traits.exp if your Rust compiler is old enough.

2018-03-01  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (alloc_discriminant_info): Fix default_index
	assertion.  Add assertion for discriminant_index.
	(quirk_rust_enum): Use correct base type name in univariant case.
2018-03-01 09:34:51 -07:00
Sergio Durigan Junior b4987c956d Create new common/pathstuff.[ch]
This commit moves the path manipulation routines found on utils.c to a
new common/pathstuff.c, and updates the Makefile.in's accordingly.
The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and
"gdb_abspath".

This will be needed because gdbserver will have to call "gdb_abspath"
on my next patch, which implements a way to expand the path of the
inferior provided by the user in order to allow specifying just the
binary name when starting gdbserver, like:

  $ gdbserver :1234 a.out

With the recent addition of the startup-with-shell feature on
gdbserver, this scenario doesn't work anymore if the user doesn't have
the current directory listed in the PATH variable.

I had to do a minor adjustment on "gdb_abspath" because we don't have
access to "tilde_expand" on gdbserver, so now the function is using
"gdb_tilde_expand" instead.  Otherwise, the code is the same.

Regression tested on the BuildBot, without regressions.

gdb/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (COMMON_SFILES): Add "common/pathstuff.c".
	(HFILES_NO_SRCDIR): Add "common/pathstuff.h".
	* auto-load.c: Include "common/pathstuff.h".
	* common/common-def.h (current_directory): Move here.
	* common/gdb_tilde_expand.c (gdb_tilde_expand_up): New
	function.
	* common/gdb_tilde_expand.h (gdb_tilde_expand_up): New
	prototype.
	* common/pathstuff.c: New file.
	* common/pathstuff.h: New file.
	* compile/compile.c: Include "common/pathstuff.h".
	* defs.h (current_directory): Move to "common/common-defs.h".
	* dwarf2read.c: Include "common/pathstuff.h".
	* exec.c: Likewise.
	* guile/scm-safe-call.c: Likewise.
	* linux-thread-db.c: Likewise.
	* main.c: Likewise.
	* nto-tdep.c: Likewise.
	* objfiles.c: Likewise.
	* source.c: Likewise.
	* symtab.c: Likewise.
	* utils.c: Include "common/pathstuff.h".
	(gdb_realpath): Move to "common/pathstuff.c".
	(gdb_realpath_keepfile): Likewise.
	(gdb_abspath): Likewise.
	* utils.h (gdb_realpath): Move to "common/pathstuff.h".
	(gdb_realpath_keepfile): Likewise.
	(gdb_abspath): Likewise.

gdb/gdbserver/ChangeLog:
2018-02-28  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c".
	(OBJS): Add "pathstuff.o".
	* server.c (current_directory): New global variable.
	(captured_main): Initialize "current_directory".
2018-02-28 11:34:39 -05:00
Tom Tromey 2ddeaf8a7d Handle DW_TAG_variant_part and DW_TAG_variant
This changes dwarf2read to understand DW_TAG_variant_part and
DW_TAG_variant.

Note that DW_AT_discr_list is not handled.  I did not need this for
Rust.  I imagine this should not be too hard to add later, should
someone need it.  Meanwhile I have gdb emit a complaint if it is seen.

There is a lurking issue concerning the placement of the discriminant
in the DWARF.  For Rust, I ended up following the letter of the
standard and having the discriminant be a child of the
DW_TAG_variant_part.  However, GCC's Ada support does not do this.
Pierre-Marie filed this with the DWARF committee:

    http://dwarfstd.org/ShowIssue.php?issue=180123.1

However as that is read-only, if you have comments you might consider
adding them to the GCC bug:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83935

Finally, there is a DWARF extension lurking in here.  In Rust, a
univariant enum will not have a discriminant.  However, in order to
unify the representation of all data-carrying enums, I've made LLVM
(and my forthcoming rustc patch) emit a univariant enum using a
DW_TAG_variant with a single variant part and without DW_AT_discr.
The lack of this DW_AT_discr is the extension.  I will submit an issue
on dwarfstd.org about this.

2018-02-26  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct variant_field): New.
	(struct nextfield) <variant>: New field.
	(dwarf2_add_field): Handle DW_TAG_variant_part.
	(dwarf2_attach_fields_to_type): Attach a discriminant_info to a
	discriminated union.
	(read_structure_type): Handle DW_TAG_variant_part.
	(handle_struct_member_die): New function, extracted from
	process_structure_scope.  Handle DW_TAG_variant.
	(process_structure_scope): Handle discriminated unions.  Call
	handle_struct_member_die.

2018-02-26  Tom Tromey  <tom@tromey.com>

	* gdb.dwarf2/variant.c: New file.
	* gdb.dwarf2/variant.exp: New file.
2018-02-26 09:21:08 -07:00
Tom Tromey c9317f214b Convert Rust to use discriminated unions
A Rust enum is, essentially, a discriminated union.  Currently the
Rust language support handles Rust enums locally, in rust-lang.c.
However, because I am changing the Rust compiler to use
DW_TAG_variant* to represent enums, it seemed better to have a single
internal representation for Rust enums in gdb.

This patch implements this idea by moving the current Rust enum
handling code to dwarf2read.  This allows the simplification of some
parts of rust-lang.c as well.

2018-02-26  Tom Tromey  <tom@tromey.com>

	* rust-lang.h (rust_last_path_segment): Declare.
	* rust-lang.c (rust_last_path_segment): Now public.  Change
	contract.
	(struct disr_info): Remove.
	(RUST_ENUM_PREFIX, RUST_ENCODED_ENUM_REAL)
	(RUST_ENCODED_ENUM_HIDDEN, rust_union_is_untagged)
	(rust_get_disr_info, rust_tuple_variant_type_p): Remove.
	(rust_enum_p, rust_enum_variant): New function.
	(rust_underscore_fields): Remove "offset" parameter.
	(rust_print_enum): New function.
	(rust_val_print) <TYPE_CODE_UNION>: Remove enum code.
	<TYPE_CODE_STRUCT>: Call rust_print_enum when appropriate.
	(rust_print_struct_def): Add "for_rust_enum" parameter.  Handle
	enums.
	(rust_internal_print_type): New function, from rust_print_type.
	Remove enum code.
	(rust_print_type): Call rust_internal_print_type.
	(rust_evaluate_subexp) <STRUCTOP_ANONYMOUS, STRUCTOP_STRUCT>:
	Update enum handling.
	* dwarf2read.c (struct dwarf2_cu) <rust_unions>: New field.
	(rust_fully_qualify, alloc_discriminant_info, quirk_rust_enum)
	(rust_union_quirks): New functions.
	(process_full_comp_unit, process_full_type_unit): Call
	rust_union_quirks.
	(process_structure_scope): Update rust_unions if necessary.

2018-02-26  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.exp: Accept more possible results in enum test.
2018-02-26 09:21:08 -07:00
Yao Qi 48fbe735fb Move read_partial_die to partial_die_info::read
gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (struct partial_die_info) <read>: New method.
	(read_partial_die): Remove the declaration.
	(load_partial_dies): Update.
	(partial_die_info::partial_die_info):
	(read_partial_die): Change it to partial_die_info::read.
2018-02-26 15:38:01 +00:00
Yao Qi 52356b79d7 Move fixup_partial_die to partial_die_info::fixup
fixup_partial_die can be a partial_die_info method fixup.

gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (struct partial_die_info) <fixup>: New method.
	(fixup_partial_die): Remove declaration.
	(scan_partial_symbols): Update.
	(partial_die_parent_scope): Likewise.
	(partial_die_full_name): Likewise.
	(fixup_partial_die): Change it to partial_die_info::fixup.
2018-02-26 15:38:01 +00:00
Yao Qi 35cc7ed70c Remove one argument abbrev_len in read_partial_die
gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (read_partial_die): Update the declaration.
	(load_partial_dies): Caller update.
	(read_partial_die): Remove one argument abbrev_len.
2018-02-26 15:38:01 +00:00
Yao Qi 6f06d47ba0 Class-fy partial_die_info
This patch is to class-fy partial_die_info.  Two things special here,

 - disable assignment operator, but keep copy ctor, which is used in
   load_partial_dies,
 - have a private ctor which is only used by dwarf2_cu::find_partial_die,
   I don't want other code use it, so make it private,

gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (struct partial_die_info): Add ctor, delete
	assignment operator.
	(load_partial_dies): Use ctor and copy ctor.
	(read_partial_die): Update.
	(dwarf2_cu::find_partial_die): Use ctor.
2018-02-26 15:38:01 +00:00
Yao Qi d590ff257c Change find_partial_die_in_comp_unit to dwarf2_cu::find_partial_die
This patch changes find_partial_die_in_comp_unit to a dwarf2_cu method
find_partial_die.

gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (struct dwarf2_cu) <find_partial_die>: New method.
	(find_partial_die_in_comp_unit): Change it to
	dwarf2_cu::find_partial_die.
	(find_partial_die): Update.
2018-02-26 15:38:01 +00:00
Yao Qi fd0a254f81 Don't check abbrev is NULL in read_partial_die
'abbrev' won't be NULL, so don't check it.

gdb:

2018-02-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (read_partial_die): Remove the code checking abbrev
	is NULL.
2018-02-26 15:38:00 +00:00
Yao Qi cd9983dd5f Re-write partial_die_info allocation in load_partial_dies
load_partial_dies has a "while (1)" loop to visit each die, and create
partial_die_info if needed in each iteration, like this,

  part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);

  while (1)
   {
      if (foo1) continue;

      if (foo2) continue;

      read_partial_die (, , part_die, ,);

      ....
      part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);
   };

the code was written in a way that spaces are allocated on necessary on
cu->comp_unit_obstack.  I want to class-fy partial_die_info, but
partial_die_info ctor can't follow XOBNEW immediately, so this patch
rewrite this loop to:

  while (1)
   {
      if (foo1) continue;

      if (foo2) continue;

      struct partial_die_info pdi;
      read_partial_die (, , &pdi, ,);

      part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info);
      memcpy (part_die, &pdi, sizeof (pdi));
   };

we create a local variable pdi, if we need it, call XOBNEW, and copy.
This also reduce one XOBNEW call.  I measured the number of XOBNEW call in
load_partial_dies when gdb reads dwarf2read.o, without this patch, it is
18827, and with this patch, it is 18826.

gdb:

2018-026-26  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (load_partial_dies): Move the location of XOBNEW.
2018-02-26 15:38:00 +00:00
Simon Marchi 9d8780f0d0 dwarf: Make sect_offset 64-bits
Does anybody have an opinion about this?  It would be nice to unbreak
the "default" build with clang (i.e. without passing special -Wno-error=
flags).

Here's a version rebased on today's master.

From 47d28075117fa2ddb93584ec50881e33777a85e5 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Sat, 30 Dec 2017 22:48:18 -0500
Subject: [PATCH] dwarf: Make sect_offset 64-bits

Compiling with Clang 6 shows these errors:

/home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:26610:43: error: result of comparison of constant 4294967296 with expression of type 'typename std::underlying_type<sect_offset>::type' (a
ka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:26618:43: error: result of comparison of constant 4294967296 with expression of type 'typename std::underlying_type<sect_offset>::type' (a
ka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code in question checks if there is any offset exceeding 32 bits,
and therefore if we need to use the 64-bit DWARF format when writing the
.debug_names section.  The type we use currently to represent section
offsets is an unsigned int (32-bits), which means a value of this type
will never exceed 32 bits, hence the errors above.

There are many signs that we want to support 64-bits DWARF (although I
haven't tested), such as:

 - We correctly read initial length fields (read_initial_length)
 - We take that into account when reading offsets (read_offset_1)
 - The check_dwarf64_offsets function

However, I don't see how it can work if sect_offset is a 32-bits type.
Every time we record a section offset, we risk truncating the value.
And if a file uses the 64-bit DWARF format, it's most likely because
there are such offset values that overflow 32 bits.

Because of this, I think the way forward is to change sect_offset to be
a uint64_t.  It will be able to represent any offset, regardless of the
bitness of the DWARF info.

This patch was regtested on the buildbot.

gdb/ChangeLog:

	* gdbtypes.h (sect_offset): Change type to uint64_t.
	(sect_offset_str): New function.
	* dwarf2read.c (create_addrmap_from_aranges): Use
	sect_offset_str.
	(error_check_comp_unit_head): Likewise.
	(create_debug_type_hash_table): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(init_cutu_and_read_dies): Likewise.
	(init_cutu_and_read_dies_no_follow): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(partial_die_parent_scope): Likewise.
	(peek_die_abbrev): Likewise.
	(process_queue): Likewise.
	(dwarf2_physname): Likewise.
	(read_namespace_alias): Likewise.
	(read_import_statement): Likewise.
	(create_dwo_cu_reader): Likewise.
	(create_cus_hash_table): Likewise.
	(lookup_dwo_cutu): Likewise.
	(inherit_abstract_dies): Likewise.
	(read_func_scope): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(read_common_block): Likewise.
	(read_module_type): Likewise.
	(read_typedef): Likewise.
	(read_subrange_type): Likewise.
	(load_partial_dies): Likewise.
	(read_partial_die): Likewise.
	(find_partial_die): Likewise.
	(read_str_index): Likewise.
	(dwarf2_string_attr): Likewise.
	(build_error_marker_type): Likewise.
	(lookup_die_type): Likewise.
	(dump_die_shallow): Likewise.
	(follow_die_ref): Likewise.
	(dwarf2_fetch_die_loc_sect_off): Likewise.
	(dwarf2_fetch_constant_bytes): Likewise.
	(follow_die_sig): Likewise.
	(get_signatured_type): Likewise.
	(get_DW_AT_signature_type): Likewise.
	(dwarf2_find_containing_comp_unit): Likewise.
	(set_die_type): Likewise.
2018-02-23 13:03:33 -05:00
Yao Qi fd90ace4c1 New class allocate_on_obstack
This patch adds a new class allocate_on_obstack, and let dwarf2_per_objfile
inherit it, so that dwarf2_per_objfile is automatically allocated on
obstack, and "delete dwarf2_per_objfile" doesn't de-allocate any space.

gdb:

2018-02-16  Yao Qi  <yao.qi@linaro.org>

	* block.c (block_namespace_info): Inherit allocate_on_obstack.
	(block_initialize_namespace): Use new.
	* dwarf2read.c (dwarf2_per_objfile): Inherit allocate_on_obstack.
	(dwarf2_free_objfile): Use delete.
	* gdbtypes.c (type_pair): Inherit allocate_on_obstack.
	(copy_type_recursive): Use new.
	* gdb_obstack.h (allocate_on_obstack): New.
2018-02-16 16:20:58 +00:00
Tom Tromey e0cc99a62f Change openp et al to use a unique_xmalloc_ptr
This changes openp, source_full_path_of, and find_and_open_source to
take a unique_xmalloc_ptr, rather than a char*, as an outgoing
argument type.  This simplifies the API, ownership-wise, and allows
for the removal of some cleanups.

gdb/ChangeLog
2018-02-14  Tom Tromey  <tom@tromey.com>

	* symfile.c (symfile_bfd_open): Update.
	* source.h (openp, source_full_path_of, find_and_open_source):
	Change argument type to unique_xmalloc_ptr.
	* source.c (openp): Take a unique_xmalloc_ptr.
	(source_full_path_of, find_and_open_source): Likewise.
	(open_source_file, symtab_to_fullname): Update.
	* solist.h (struct target_so_ops) <find_and_open_solib>: Take a
	unique_xmalloc_ptr.
	* solib.c (solib_find_1): Use unique_xmalloc_ptr.
	(exec_file_find): Update.
	* psymtab.c (psymtab_to_fullname): Update.
	* nto-tdep.h (nto_find_and_open_solib): Update.
	* nto-tdep.c (nto_find_and_open_solib): Change temp_path to a
	unique_xmalloc_ptr.
	* exec.c (exec_file_attach): Update.
	* dwarf2read.c (try_open_dwop_file): Use unique_xmalloc_ptr.
	* cli/cli-cmds.c (find_and_open_script): Use unique_xmalloc_ptr.
2018-02-14 08:09:53 -07:00
Simon Marchi 24b9144d4b Use enum flags for flags passed to openp
gdb/ChangeLog:

	* defs.h (enum openp_flags): New enum.
	(OPF_TRY_CWD_FIRST, OPF_SEARCH_IN_PATH, OPF_RETURN_REALPATH):
	Move to enum openp_flags.
	(openp_flags): New enum flags.
	(openp): Change parameter type to openp_flags.
	* source.c (openp): Change parameter type to openp_flags.
	* cli/cli-cmds.c (find_and_open_script): Use openp_flags.
	* dwarf2read.c (try_open_dwop_file): Use openp_flags.
2018-02-13 12:13:59 -05:00
Andrew Burgess b303c6f688 gdb: Remove cleanup from dw2_do_instantiate_symtab
When running the test gdb.dwarf2/dw2-bad-parameter-type.exp under
valgrind, I see the following issue reported (on x86-64 Fedora):

  (gdb) ptype f
  ==5203== Invalid read of size 1
  ==5203==    at 0x6931FE: process_die_scope::~process_die_scope() (dwarf2read.c:10642)
  ==5203==    by 0x66818F: process_die(die_info*, dwarf2_cu*) (dwarf2read.c:10664)
  ==5203==    by 0x66A01F: read_file_scope(die_info*, dwarf2_cu*) (dwarf2read.c:11650)
  ==5203==    by 0x667F2D: process_die(die_info*, dwarf2_cu*) (dwarf2read.c:10672)
  ==5203==    by 0x6677B6: process_full_comp_unit(dwarf2_per_cu_data*, language) (dwarf2read.c:10445)
  ==5203==    by 0x66657A: process_queue(dwarf2_per_objfile*) (dwarf2read.c:9945)
  ==5203==    by 0x6559B4: dw2_do_instantiate_symtab(dwarf2_per_cu_data*) (dwarf2read.c:3163)
  ==5203==    by 0x66683D: psymtab_to_symtab_1(partial_symtab*) (dwarf2read.c:10034)
  ==5203==    by 0x66622A: dwarf2_read_symtab(partial_symtab*, objfile*) (dwarf2read.c:9811)
  ==5203==    by 0x787984: psymtab_to_symtab(objfile*, partial_symtab*) (psymtab.c:792)
  ==5203==    by 0x786E3E: psym_lookup_symbol(objfile*, int, char const*, domain_enum_tag) (psymtab.c:522)
  ==5203==    by 0x804BD0: lookup_symbol_via_quick_fns(objfile*, int, char const*, domain_enum_tag) (symtab.c:2383)
  ==5203==  Address 0x147ed063 is 291 bytes inside a block of size 4,064 free'd
  ==5203==    at 0x4C2CD5A: free (vg_replace_malloc.c:530)
  ==5203==    by 0x444415: void xfree<void>(void*) (common-utils.h:60)
  ==5203==    by 0x9DA8C2: call_freefun (obstack.c:103)
  ==5203==    by 0x9DAD35: _obstack_free (obstack.c:280)
  ==5203==    by 0x44464C: auto_obstack::~auto_obstack() (gdb_obstack.h:73)
  ==5203==    by 0x68AFB0: dwarf2_cu::~dwarf2_cu() (dwarf2read.c:25080)
  ==5203==    by 0x68B204: free_one_cached_comp_unit(dwarf2_per_cu_data*) (dwarf2read.c:25174)
  ==5203==    by 0x66668C: dwarf2_release_queue(void*) (dwarf2read.c:9982)
  ==5203==    by 0x563A4C: do_my_cleanups(cleanup**, cleanup*) (cleanups.c:154)
  ==5203==    by 0x563AA7: do_cleanups(cleanup*) (cleanups.c:176)
  ==5203==    by 0x5646CE: throw_exception_cxx(gdb_exception) (common-exceptions.c:289)
  ==5203==    by 0x5647B7: throw_exception(gdb_exception) (common-exceptions.c:317)
  ==5203==  Block was alloc'd at
  ==5203==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
  ==5203==    by 0x564BE8: xmalloc (common-utils.c:44)
  ==5203==    by 0x9DA872: call_chunkfun (obstack.c:94)
  ==5203==    by 0x9DA935: _obstack_begin_worker (obstack.c:141)
  ==5203==    by 0x9DAA3C: _obstack_begin (obstack.c:164)
  ==5203==    by 0x4445E0: auto_obstack::auto_obstack() (gdb_obstack.h:70)
  ==5203==    by 0x68AE07: dwarf2_cu::dwarf2_cu(dwarf2_per_cu_data*) (dwarf2read.c:25073)
  ==5203==    by 0x661A8A: init_cutu_and_read_dies(dwarf2_per_cu_data*, abbrev_table*, int, int, void (*)(die_reader_specs const*, unsigned char const*, die_info*, int, void*), void*) (dwarf2read.c:7869)
  ==5203==    by 0x666A29: load_full_comp_unit(dwarf2_per_cu_data*, language) (dwarf2read.c:10108)
  ==5203==    by 0x655847: load_cu(dwarf2_per_cu_data*) (dwarf2read.c:3120)
  ==5203==    by 0x655928: dw2_do_instantiate_symtab(dwarf2_per_cu_data*) (dwarf2read.c:3148)
  ==5203==    by 0x66683D: psymtab_to_symtab_1(partial_symtab*) (dwarf2read.c:10034)

There's actually a series of three issues reported, but it turns out
they're all related, so we can consider on the first one.

The invalid read is triggered from a destructor which is being invoked
as part of a stack unwind after throwing an error.  At the time the
error is thrown, the stack looks like this:

    #0  0x00000000009f4ecd in __cxa_throw ()
    #1  0x0000000000564761 in throw_exception_cxx (exception=...) at ../../src/gdb/common/common-exceptions.c:303
    #2  0x00000000005647b8 in throw_exception (exception=...) at ../../src/gdb/common/common-exceptions.c:317
    #3  0x00000000005648ff in throw_it(return_reason, errors, const char *, typedef __va_list_tag __va_list_tag *) (reason=RETURN_ERROR,
        error=GENERIC_ERROR, fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]",
        ap=0x7fff387f2d68) at ../../src/gdb/common/common-exceptions.c:373
    #4  0x0000000000564929 in throw_verror (error=GENERIC_ERROR,
        fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]", ap=0x7fff387f2d68)
        at ../../src/gdb/common/common-exceptions.c:379
    #5  0x0000000000867be4 in verror (string=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]",
        args=0x7fff387f2d68) at ../../src/gdb/utils.c:251
    #6  0x000000000056879d in error (fmt=0xb33020 "Dwarf Error: Cannot find DIE at 0x%x referenced from DIE at 0x%x [in module %s]")
        at ../../src/gdb/common/errors.c:43
    #7  0x0000000000686875 in follow_die_ref (src_die=0x30bc8a0, attr=0x30bc8c8, ref_cu=0x7fff387f2ed0) at ../../src/gdb/dwarf2read.c:22969
    #8  0x00000000006844cd in lookup_die_type (die=0x30bc8a0, attr=0x30bc8c8, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:21976
    #9  0x0000000000683f27 in die_type (die=0x30bc8a0, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:21832
    #10 0x0000000000679b39 in read_subroutine_type (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:17343
    #11 0x00000000006845fb in read_type_die_1 (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:22035
    #12 0x0000000000684576 in read_type_die (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:22010
    #13 0x000000000067003f in read_func_scope (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:13822
    #14 0x0000000000667f5e in process_die (die=0x30bc830, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:10679
    #15 0x000000000066a020 in read_file_scope (die=0x30bc720, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:11650
    #16 0x0000000000667f2e in process_die (die=0x30bc720, cu=0x30bc5d0) at ../../src/gdb/dwarf2read.c:10672
    #17 0x00000000006677b7 in process_full_comp_unit (per_cu=0x3089b80, pretend_language=language_minimal)
        at ../../src/gdb/dwarf2read.c:10445
    #18 0x000000000066657b in process_queue (dwarf2_per_objfile=0x30897d0) at ../../src/gdb/dwarf2read.c:9945
    #19 0x00000000006559b5 in dw2_do_instantiate_symtab (per_cu=0x3089b80) at ../../src/gdb/dwarf2read.c:3163
    #20 0x000000000066683e in psymtab_to_symtab_1 (pst=0x3089bd0) at ../../src/gdb/dwarf2read.c:10034
    #21 0x000000000066622b in dwarf2_read_symtab (self=0x3089bd0, objfile=0x3073f40) at ../../src/gdb/dwarf2read.c:9811
    #22 0x0000000000787985 in psymtab_to_symtab (objfile=0x3073f40, pst=0x3089bd0) at ../../src/gdb/psymtab.c:792
    #23 0x0000000000786e3f in psym_lookup_symbol (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/psymtab.c:522
    #24 0x0000000000804bd1 in lookup_symbol_via_quick_fns (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/symtab.c:2383
    #25 0x0000000000804fe4 in lookup_symbol_in_objfile (objfile=0x3073f40, block_index=1, name=0x30b2e30 "f", domain=VAR_DOMAIN)
        at ../../src/gdb/symtab.c:2558
    #26 0x0000000000805125 in lookup_static_symbol (name=0x30b2e30 "f", domain=VAR_DOMAIN) at ../../src/gdb/symtab.c:2595
    #27 0x0000000000804357 in lookup_symbol_aux (name=0x30b2e30 "f", match_type=symbol_name_match_type::FULL, block=0x0,
        domain=VAR_DOMAIN, language=language_c, is_a_field_of_this=0x0) at ../../src/gdb/symtab.c:2105
    #28 0x0000000000803ad9 in lookup_symbol_in_language (name=0x30b2e30 "f", block=0x0, domain=VAR_DOMAIN, lang=language_c,
        is_a_field_of_this=0x0) at ../../src/gdb/symtab.c:1887
    #29 0x0000000000803b53 in lookup_symbol (name=0x30b2e30 "f", block=0x0, domain=VAR_DOMAIN, is_a_field_of_this=0x0)
        at ../../src/gdb/symtab.c:1899
    #30 0x000000000053b246 in classify_name (par_state=0x7fff387f6090, block=0x0, is_quoted_name=false, is_after_structop=false)
        at ../../src/gdb/c-exp.y:2879
    #31 0x000000000053b7e9 in c_yylex () at ../../src/gdb/c-exp.y:3083
    #32 0x000000000053414a in c_yyparse () at c-exp.c:1903
    #33 0x000000000053c2e7 in c_parse (par_state=0x7fff387f6090) at ../../src/gdb/c-exp.y:3255
    #34 0x0000000000774a02 in parse_exp_in_context_1 (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0, void_context_p=0, out_subexp=0x0)
        at ../../src/gdb/parse.c:1213
    #35 0x000000000077476a in parse_exp_in_context (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0, void_context_p=0, out_subexp=0x0)
        at ../../src/gdb/parse.c:1115
    #36 0x0000000000774714 in parse_exp_1 (stringptr=0x7fff387f61c0, pc=0, block=0x0, comma=0) at ../../src/gdb/parse.c:1106
    #37 0x0000000000774c53 in parse_expression (string=0x27ff996 "f") at ../../src/gdb/parse.c:1253
    #38 0x0000000000861dc4 in whatis_exp (exp=0x27ff996 "f", show=1) at ../../src/gdb/typeprint.c:472
    #39 0x00000000008620d8 in ptype_command (type_name=0x27ff996 "f", from_tty=1) at ../../src/gdb/typeprint.c:561
    #40 0x000000000047430b in do_const_cfunc (c=0x3012010, args=0x27ff996 "f", from_tty=1) at ../../src/gdb/cli/cli-decode.c:106
    #41 0x000000000047715e in cmd_func (cmd=0x3012010, args=0x27ff996 "f", from_tty=1) at ../../src/gdb/cli/cli-decode.c:1886
    #42 0x00000000008431bb in execute_command (p=0x27ff996 "f", from_tty=1) at ../../src/gdb/top.c:630
    #43 0x00000000006bf946 in command_handler (command=0x27ff990 "ptype f") at ../../src/gdb/event-top.c:583
    #44 0x00000000006bfd12 in command_line_handler (rl=0x30bb3a0 "\240\305\v\003") at ../../src/gdb/event-top.c:774

The problem is that in `process_die` (frames 14 and 16) we create a
`process_die_scope` object, that takes a copy of the `struct
dwarf2_cu *` passed into the frame.  The destructor of the
`process_die_scope` dereferences the stored pointer.  This wouldn't be
an issue, except...

... in dw2_do_instantiate_symtab (frame 19) a clean up was registered that
clears the dwarf2_queue in case of an error.  Part of this clean up
involves deleting the `struct dwarf2_cu`s referenced from the queue..

The problem then, is that cleanups are processed at the site of the
throw, while, class destructors are invoked as we unwind their frame.
The result is that we process the frame 19 cleanup (and delete the
struct dwarf2_cu) before we process the destructors in frames 14 and 16.
When we do get back to frames 14 and 16 the objects being references
have already been deleted.

The solution is to remove the cleanup from dw2_do_instantiate_symtab, and
instead use a destructor to release the dwarf2_queue instead.  With this
patch in place, the valgrind errors are now resolved.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_release_queue): Delete function, move body
	into...
	(class dwarf2_queue_guard): ...the destructor of this new class.
	(dw2_do_instantiate_symtab): Create instance of the new class
	dwarf2_queue_guard, remove cleanup.
2018-02-12 21:43:45 +00:00
Joel Brobecker 0eb876f52f Move comment in gdb/dwarf2read.c::dwarf2_physname
This commit just moves a comment right next to where it is actually
relevant. No actual code change.

gdb/ChangeLog:

        * dwarf2read.c (dwarf2_physname): Move commment.

Tested by rebuilding GDB.
2018-02-04 23:48:19 -05:00
Simon Marchi fc8e7e75c2 Remove dwarf2_per_objfile_free and use after free of dwarf2_per_objfile
I got some crashes while doing some work with dwarf2_per_objfile.  It
turns out that dwarf2_per_objfile_free is using the dwarf2_per_objfile
objects after their destructor has ran.

The easiest way to reproduce this is to run the inferior twice (do
"start" twice).  Currently, it goes unnoticed, but when I tried to
change all_comp_units and all_type_units to std::vectors, things started
crashing.

The dwarf2_per_objfile objects get destroyed here:

 #0  dwarf2_per_objfile::~dwarf2_per_objfile (this=0x35afe70, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:2422
 #1  0x0000000000833282 in dwarf2_free_objfile (objfile=0x356cff0) at /home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:25363
 #2  0x0000000000699255 in elf_symfile_finish (objfile=0x356cff0) at /home/emaisin/src/binutils-gdb/gdb/elfread.c:1309
 #3  0x0000000000911ed3 in objfile::~objfile (this=0x356cff0, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/objfiles.c:674

and just after that the dwarf2read per-objfile registry cleanup function
gets called:

 #0  dwarf2_per_objfile_free (objfile=0x356cff0, d=0x35afe70) at /home/emaisin/src/binutils-gdb/gdb/dwarf2read.c:25667
 ... registry boilerplate ...
 #4  0x00000000009103ea in objfile_free_data (container=0x356cff0) at /home/emaisin/src/binutils-gdb/gdb/objfiles.c:61
 #5  0x0000000000911ee2 in objfile::~objfile (this=0x356cff0, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/objfiles.c:678

In dwarf2_per_objfile_free, we access fields of the dwarf2_per_objfile
object, which is invalid since its destructor has been executed.

This patch moves the content of dwarf2_per_objfile_free to the
destructor of dwarf2_per_objfile.  The call to
register_objfile_data_with_cleanup in _initialize_dwarf2_read can be
changed to the simpler register_objfile_data.

gdb/ChangeLog:

	* dwarf2read.c (free_dwo_files): Add forward-declaration.
	(dwarf2_per_objfile::~dwarf2_per_objfile): Move content from
	dwarf2_per_objfile_free here.
	(dwarf2_per_objfile_free): Remove.
	(_initialize_dwarf2_read): Don't register
	dwarf2_per_objfile_free as a registry cleanup.
2018-01-28 12:07:30 -05:00
Joel Brobecker de4cb04a20 Ada/DWARF: Assume the Ada compiler produces descriptive type attributes
GCC was enhanced in 2011 to generate this attribute, so I think we can
now assume that it is available when using that compiler. Doing so
allows us to speed up what we call "parallel type" lookups when
processing certain types encoded using the GNAT encoding.

This patch changes need_gnat_info to always expect those attributes
to be generated when the language is Ada. This is an assumption
that on the surfcace looks like it might be a bit on the edge; but
in practice, it should be OK because this is only useful in the
context of handling GNAT-specific encodings. Other Ada compilers
would presumably produce debugging information using pure DWARF
constructs, so would not be impacted by this.

gdb/ChangeLog:

        * dwarf2read.c (need_gnat_info): Return nonzero if the cu's
        language is Ada.

Tested on x86_64-linux.
2018-01-21 23:23:34 -05:00
Yao Qi 4a17f7688f Make abbrev_table::abbrevs private
abbrev_table::abbrevs is only access within abbrev_table's methods, so
it can be private.  Add "m_" prefix.

gdb:

2018-01-18  Yao Qi  <yao.qi@linaro.org>

	* dwarf2read.c (abbrev_table) <abbrevs>: Rename it to
	m_abbrevs.
	(abbrev_table::add_abbrev): Update.
	(abbrev_table::lookup_abbrev): Update.
2018-01-18 15:29:31 +00:00
Tom Tromey 9e14690d06 Remove symbolp typedef
This removes the symbolp typedef from dwarf2read.c.  It is no longer
used.

2018-01-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (symbolp): Remove typedef.  Don't instantiate VEC.
2018-01-17 11:28:44 -07:00
Tom Tromey 50a820477b Remove objfile argument from add_dyn_prop
The objfile argument to add_dyn_prop is redundant, so this patch
removes it.

2018-01-17  Tom Tromey  <tom@tromey.com>

	* gdbtypes.h (add_dyn_prop): Remove objfile parameter.
	* gdbtypes.c (add_dyn_prop): Remove objfile parameter.
	(create_array_type_with_stride): Update.
	* dwarf2read.c (set_die_type): Update.
2018-01-17 11:28:44 -07:00
Tom Tromey c89b44cdc5 Change dwarf2_cu::method_info to be a std::vector
This changes the type of dwarf2_cu::method_info and fixes up the uses.
In order to remove cleanups from process_full_comp_unit and
process_full_type_unit, psymtab_include_file_name also had to be
changed to avoid leaving dangling cleanups.

2018-01-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (delayed_method_info): Remove typedef.
	(dwarf2_cu::method_info): Now a std::vector.
	(add_to_method_list): Update.
	(free_delayed_list): Remove.
	(compute_delayed_physnames): Update.
	(process_full_comp_unit, process_full_type_unit): Clear the method
	list.  Remove cleanups.
	(psymtab_include_file_name): Add name_holder parameter.  Use
	unique_xmalloc_ptr.
	(dwarf_decode_lines): Update.
2018-01-17 11:28:44 -07:00
Simon Marchi fcd3b13d80 Allocate dwarf2_cu with new
This changes dwarf2_cu to be allocated with new, and fixes up the
users.

2018-01-17  Tom Tromey  <tom@tromey.com>
	    Simon Marchi  <simon.marchi@ericsson.com>

	* dwarf2read.c (struct dwarf2_cu): Add constructor, destructor.
	(dwarf2_per_objfile::free_cached_comp_units)
	(init_tu_and_read_dwo_dies, init_cutu_and_read_dies)
	(init_cutu_and_read_dies_no_follow): Update.
	(dwarf2_cu::dwarf2_cu): Rename from init_one_comp_unit.
	(dwarf2_cu::~dwarf2_cu): New.
	(free_heap_comp_unit, free_stack_comp_unit): Remove.
	(age_cached_comp_units, free_one_cached_comp_unit): Update.
2018-01-17 11:28:44 -07:00
Tom Tromey 685af9cd22 Allocate abbrev_table with new
This changes dwarf2read.c to allocate abbrev tables using "new", and
then updates the users.

This version of the patch incorporates the changes that Simon
implemented.  These changes simplify the ownership rules for abbrev
tables.

2018-01-17  Tom Tromey  <tom@tromey.com>
	    Simon Marchi  <simon.marchi@ericsson.com>

	* dwarf2read.c (struct dwarf2_cu) <abbrev_table>: Remove.
	(struct die_reader_specs) <abbrev_table>: New member.
	(struct abbrev_table): Add constructor.
	<alloc_abbrev, add_abbrev, lookup_abbrev>: Declare.
	<abbrev_obstack>: Now an auto_obstack.
	(abbrev_table_up): New typedef.
	(init_cu_die_reader): Add abbrev_table parameter.
	(read_cutu_die_from_dwo): Remove abbrev_table_provided parameter.
	Add result_dwo_abbrev_table.
	(init_tu_and_read_dwo_dies, init_cutu_and_read_dies)
	(init_cutu_and_read_dies_no_follow, build_type_psymtabs_1):
	Update.
	(peek_die_abbrev): Take die_reader_specs, not dwarf_cu as
	parameter.
	(skip_children): Update.
	(abbrev_table::alloc_abbrev): Rename from
	abbrev_table_alloc_abbrev.
	(abbrev_table::add_abbrev): Rename from abbrev_table_add_abbrev.
	(abbrev_table::lookup_abbrev): Rename from
	abbrev_table_lookup_abbrev.
	(abbrev_table_read_table): Return abbrev_table_up.
	(abbrev_table_free, abbrev_table_free_cleanup)
	(dwarf2_read_abbrevs, dwarf2_free_abbrev_table): Remove.
	(load_partial_dies): Update.
2018-01-17 11:28:44 -07:00
Tom Tromey 5e2db402c8 Unify new_symbol and new_symbol_full
This patch unifies new_symbol with new_symbol_full, replacing a
wrapper function with a default parameter.

2018-01-17  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_compute_name): Update comment.
	(read_func_scope, read_variable): Update.
	(new_symbol): Remove.
	(new_symbol_full): Rename to new_symbol.
2018-01-17 11:28:44 -07:00
Pedro Alves 618daa933c language_get_symbol_name_matcher -> get_symbol_name_matcher
Rename language_get_symbol_name_matcher -> get_symbol_name_matcher,
since the function is no longer a straight "language method".

gdb/ChangeLog:
2018-01-10  Pedro Alves  <palves@redhat.com>

	* language.h (language_get_symbol_name_matcher): Rename ...
	(get_symbol_name_matcher): ... this.
	* language.c (language_get_symbol_name_matcher): Ditto.
	* dictionary.c, linespec.c, minsyms.c, psymtab.c, symtab.c: All
	callers adjusted.
2018-01-10 23:12:48 +00:00
Pedro Alves c63d3e8d12 Ada: make verbatim matcher override other language matchers (PR gdb/22670)
A previous patch fixed verbatim matching in the lookup at the minimal
symbol level, but we should also be finding that same symbol through
the partial/full symtab search.

For example, this is what happens if we use "print" instead of
"break":

    (gdb) p <MixedCaseFunc>
    $1 = {<text variable, no debug info>} 0x4024dc <MixedCaseFunc>

Before the C++ wildmatching series, GDB knows that MixedCaseFunc is a
function without parameters, and the expression above means calling
it.  If you try it before having started the inferior, you'd get the
following (expected) error:

    (gdb) print  <MixedCaseFunc>
    You can't do that without a process to debug.

The main idea behind making the name matcher be determined by the
symbol's language is so that C++ (etc.) wildmatching in linespecs
works even if the current language is not C++, as e.g., when you step
through C or assembly code.

Ada's verbatim matching syntax however ("<...>") isn't quite the same.
It is more a property of the current language than of a particular
symbol's language.  We want to support this syntax when debugging an
Ada program, but it's reason of existence is to find non-Ada symbols.
This suggests going back to enabling it depending on current language
instead of language of the symbol being matched.

I'm not entirely happy with the "current_language" reference (though I
think that it's harmless).  I think we could try storing the current
language in the lookup_name_info object, and then convert a bunch of
functions more to pass around lookup_name_info objects instead of
"const char *" names.  I.e., build the lookup_name_info higher up.
I'm not sure about that, I'll have to think more about it.  Maybe
something different will be better.  Meanwhile, this gets us going.

I've extended the testcase to also exercise a no-debug-info function,
for extra coverage of the minsyms-only paths.

gdb/ChangeLog:
2018-01-10  Pedro Alves  <palves@redhat.com>

	PR gdb/22670
	* dwarf2read.c
	(gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher):
	Adjust to use language_get_symbol_name_matcher instead of
	language_defn::la_get_symbol_name_matcher.
	* language.c (language_get_symbol_name_matcher): If in Ada mode
	and the lookup name is a verbatim match, return Ada's matcher.
	* language.h (language_get_symbol_name_matcher): Adjust comment.
	(ada_lookup_name_info::verbatim_p):: New method.

gdb/testsuite/ChangeLog:
2018-01-10  Pedro Alves  <palves@redhat.com>

	PR gdb/22670
	* gdb.ada/bp_c_mixed_case.exp: Add intro comment.  Test printing C
	functions too.  Test setting breakpoints and printing C functions
	with no debug info too.
	* gdb.ada/bp_c_mixed_case/qux.c: New file.
2018-01-10 20:47:37 +00:00
Xavier Roirand b1dc1806fa Fix breakpoint add on inlined function using function name.
Using this Ada example:

  package B is
    procedure Read_Small with Inline_Always;
  end B;

  package body B is
    Total : Natural := 0;
    procedure Read_Small is
    begin
      Total := Total + 1;
    end Read_Small;
  end B;

and

  with B;

  procedure M is
  begin
    B.Read_Small;
  end M;

% gnatmake -g -O0 -m m.adb -cargs -gnatn
% gdb m

Inserting a breakpoint on Read_Small inlined function does not work:

(gdb) b read_small
Breakpoint 1 at 0x40250e: file b.adb, line 5.
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000040250e in b.doit at b.adb:5
(gdb)

In this exemple we should have two breakpoints set, one in package B and
the other one in the inlined instance inside procedure M), like below:

(gdb) b read_small
Breakpoint 1 at 0x40250e: b.adb:5. (2 locations)
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>
1.1                         y     0x000000000040250e in b.doit at b.adb:5
1.2                         y     0x0000000000402540 in m at b.adb:5
(gdb)

Looking at the DWARF info for inlined instance of Read_Small:

<1><1526>: Abbrev Number: 2 (DW_TAG_subprogram)
    <1527>   DW_AT_name        : ([...], offset: 0x1e82): b__read_small
    <152b>   DW_AT_decl_file   : 2
    <152c>   DW_AT_decl_line   : 3
    <152d>   DW_AT_inline      : 3      (declared as inline and inlined)
[...]
 <2><1547>: Abbrev Number: 4 (DW_TAG_inlined_subroutine)
    <1548>   DW_AT_abstract_origin: <0x1526>
    <154c>   DW_AT_low_pc      : 0x402552
    <1554>   DW_AT_high_pc     : 0x2b
    <155c>   DW_AT_call_file   : 1
    <155d>   DW_AT_call_line   : 5
 <2><155e>: Abbrev Number: 0

During the parsing of DWARF info in order to produce partial DIE linked
list, the DW_TAG_inlined_subroutine were skipped thus not present in the
final partial dies.
Taking DW_TAG_inlined_subroutine in account during the parsing process
fixes the problem.

gdb/ChangeLog:

        * dwarf2read.c (scan_partial_symbols, add_partial_symbol)
        (add_partial_subprogram, load_partial_dies): Add
        DW_TAG_inlined_subroutine handling.

gdb/testsuite/ChangeLog:

        * gdb.ada/bp_inlined_func: New testcase.
2018-01-09 10:02:51 +01:00
Simon Marchi 518817b361 Remove dwarf2_cu::dwarf2_per_objfile
This patch removes the dwarf2_per_objfile field of dwarf2_cu.  It is
redundant, since we can access dwarf2_per_objfile through
dwarf2_per_objfile, which is guaranteed to be set.

gdb/ChangeLog:

	* dwarf2read.c (struct dwarf2_cu) <dwarf2_per_objfile>: Remove.
	(dw2_get_file_names_reader): Adjust.
	(lookup_dwo_signatured_type): Adjust.
	(lookup_dwp_signatured_type): Adjust.
	(lookup_signatured_type): Adjust.
	(create_type_unit_group): Adjust.
	(get_type_unit_group): Adjust.
	(process_psymtab_comp_unit_reader): Adjust.
	(build_type_psymtabs_reader): Adjust.
	(scan_partial_symbols): Adjust.
	(add_partial_symbol): Adjust.
	(add_partial_subprogram): Adjust.
	(peek_die_abbrev): Adjust.
	(fixup_go_packaging): Adjust.
	(process_imported_unit_die): Adjust.
	(dwarf2_compute_name): Adjust.
	(dwarf2_physname): Adjust.
	(read_import_statement): Adjust.
	(handle_DW_AT_stmt_list): Adjust.
	(read_file_scope): Adjust.
	(read_func_scope): Adjust.
	(read_lexical_block_scope): Adjust.
	(read_call_site_scope): Adjust.
	(read_variable): Adjust.
	(dwarf2_rnglists_process): Adjust.
	(dwarf2_ranges_process): Adjust.
	(dwarf2_ranges_read): Adjust.
	(dwarf2_get_pc_bounds): Adjust.
	(dwarf2_record_block_ranges): Adjust.
	(dwarf2_add_field): Adjust.
	(dwarf2_add_member_fn): Adjust.
	(read_structure_type): Adjust.
	(process_structure_scope): Adjust.
	(read_enumeration_type): Adjust.
	(read_array_type): Adjust.
	(mark_common_block_symbol_computed): Adjust.
	(read_common_block): Adjust.
	(read_namespace_type): Adjust.
	(read_namespace): Adjust.
	(read_module_type): Adjust.
	(read_tag_pointer_type): Adjust.
	(read_tag_ptr_to_member_type): Adjust.
	(read_tag_string_type): Adjust.
	(read_subroutine_type): Adjust.
	(read_typedef): Adjust.
	(read_base_type): Adjust.
	(attr_to_dynamic_prop): Adjust.
	(read_subrange_type): Adjust.
	(read_unspecified_type): Adjust.
	(dwarf2_read_abbrevs): Adjust.
	(load_partial_dies): Adjust.
	(read_partial_die): Adjust.
	(find_partial_die): Adjust.
	(guess_partial_die_structure_name): Adjust.
	(fixup_partial_die): Adjust.
	(read_attribute_value): Adjust.
	(read_addr_index): Adjust.
	(read_addr_index_from_leb128): Adjust.
	(read_str_index): Adjust.
	(dwarf2_string_attr): Adjust.
	(get_debug_line_section): Adjust.
	(dwarf_decode_line_header): Adjust.
	(lnp_state_machine::check_line_address): Adjust.
	(dwarf_decode_lines_1): Adjust.
	(dwarf_decode_lines): Adjust.
	(dwarf2_start_symtab): Adjust.
	(var_decode_location): Adjust.
	(new_symbol_full): Adjust.
	(dwarf2_const_value_data): Adjust.
	(dwarf2_const_value_attr): Adjust.
	(dwarf2_const_value): Adjust.
	(die_type): Adjust.
	(die_containing_type): Adjust.
	(build_error_marker_type): Adjust.
	(lookup_die_type): Adjust.
	(guess_full_die_structure_name): Adjust.
	(anonymous_struct_prefix): Adjust.
	(determine_prefix): Adjust.
	(dwarf2_name): Adjust.
	(follow_die_ref_or_sig): Adjust.
	(follow_die_offset): Adjust.
	(follow_die_ref): Adjust.
	(follow_die_sig_1): Adjust.
	(follow_die_sig): Adjust.
	(get_signatured_type): Adjust.
	(get_DW_AT_signature_type): Adjust.
	(decode_locdesc): Adjust.
	(dwarf_decode_macros): Adjust.
	(cu_debug_loc_section): Adjust.
	(fill_in_loclist_baton): Adjust.
	(dwarf2_symbol_mark_computed): Adjust.
	(init_one_comp_unit): Don't assign
	dwarf2_cu::dwarf2_per_objfile.
	(set_die_type): Adjust.
2018-01-07 11:22:46 -05:00