Commit Graph

50 Commits

Author SHA1 Message Date
Simon Marchi 298e963730 gdb: dwarf2/read.c: remove unused objfile parameters/variables
This is a simple cleanup.  These functions used to use the objfile's
obstack for allocation in the hash tables, but they don't anymore.
Remove the unnecessary objfile parameters, which in turn allows removing
some local variables.

gdb/ChangeLog:

	* dwarf2/read.c (allocate_signatured_type_table,
	allocate_dwo_unit_table, allocate_type_unit_groups_table,
	allocate_dwo_file_hash_table, allocate_dwp_loaded_cutus_table):
	Remove objfile parameter, update all callers.
2020-02-19 16:04:53 -05:00
Simon Marchi 6740f0cc3b gdb: allow duplicate enumerators in flag enums
I have come across some uses cases where it would be desirable to treat
an enum that has duplicate values as a "flag enum".  For example, this
one here [1]:

    enum membarrier_cmd {
            MEMBARRIER_CMD_QUERY                                = 0,
            MEMBARRIER_CMD_GLOBAL                               = (1 << 0),
            MEMBARRIER_CMD_GLOBAL_EXPEDITED                     = (1 << 1),
            MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED            = (1 << 2),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED                    = (1 << 3),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED           = (1 << 4),
            MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE          = (1 << 5),
            MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE = (1 << 6),

            /* Alias for header backward compatibility. */
            MEMBARRIER_CMD_SHARED = MEMBARRIER_CMD_GLOBAL,
    };

The last enumerator is kept for backwards compatibility.  Without this
patch, this enumeration wouldn't be considered a flag enum, because two
enumerators collide.   With this patch, it would be considered a flag
enum, and the value 3 would be printed as:

  MEMBARRIER_CMD_GLOBAL | MEMBARRIER_CMD_GLOBAL_EXPEDITED

Although if people prefer, we could display both MEMBARRIER_CMD_GLOBAL
and MEMBARRIER_CMD_SHARED in the result.  It wouldn't be wrong, and
could perhaps be useful in case a bit may have multiple meanings
(depending on some other bit value).

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/membarrier.h?id=0bf999f9c5e74c7ecf9dafb527146601e5c848b9#n125

gdb/ChangeLog:

	* dwarf2/read.c (update_enumeration_type_from_children): Allow
	flag enums to contain duplicate enumerators.
	* valprint.c (generic_val_print_enum_1): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Add FE_TWO_LEGACY
	enumerator.
2020-02-18 17:32:57 -05:00
Simon Marchi edd45eb06b gdb: fix printing of flag enums with multi-bit enumerators
GDB has this feature where if an enum looks like it is meant to
represent binary flags, it will present the values of that type as a
bitwise OR of the flags that are set in the value.

The original motivation for this patch is to fix this behavior:

  enum hello { AAA = 0x1, BBB = 0xf0 };

  (gdb) p (enum hello) 0x11
  $1 = (AAA | BBB)

This is wrong because the bits set in BBB (0xf0) are not all set in the
value 0x11, but GDB presents it as if they all were.

I think that enumerations with enumerators that have more than one bit
set should simply not qualify as "flag enum", as far as this
heuristic is concerned.  I'm not sure what it means to have flags of
more than one bit.  So this is what this patch implements.

I have added an assert in generic_val_print_enum_1 to make sure the flag
enum types respect that, in case they are used by other debug info
readers, in the future.

I've enhanced the gdb.base/printcmds.exp test to cover this case.  I've
also added tests for printing flag enums with value 0, both when the
enumeration has and doesn't have an enumerator for value 0.

gdb/ChangeLog:

	* dwarf2/read.c: Include "count-one-bits.h".
	(update_enumeration_type_from_children): If an enumerator has
	multiple bits set, don't treat the enumeration as a "flag enum".
	* valprint.c (generic_val_print_enum_1): Assert that enumerators
	of flag enums have 0 or 1 bit set.

gdb/testsuite/ChangeLog:

	* gdb.base/printcmds.c (enum flag_enum): Prefix enumerators with
	FE_, add FE_NONE.
	(three): Update.
	(enum flag_enum_without_zero): New enum.
	(flag_enum_without_zero): New variable.
	(enum not_flag_enum): New enum.
	(three_not_flag): New variable.
	* gdb.base/printcmds.exp (test_artificial_arrays): Update.
	(test_print_enums): Add more tests for printing flag enums.
2020-02-18 17:28:23 -05:00
Tom Tromey 8084e579e1 Return unique_xmalloc_ptr from call_site_find_chain
call_site_find_chain returns a pointer that the caller must
deallocate.  It seemed better here to return a unique_xmalloc_ptr
instead.

gdb/ChangeLog
2020-02-14  Tom Tromey  <tromey@adacore.com>

	* dwarf2/frame-tailcall.c (dwarf2_tailcall_sniffer_first):
	Update.
	* dwarf2/loc.h (call_site_find_chain): Return unique_xmalloc_ptr.
	* dwarf2/loc.c (call_site_find_chain_1): Return
	unique_xmalloc_ptr.
	(call_site_find_chain): Likewise.
2020-02-14 12:38:04 -07:00
Richard Biener 258bf0ee37 [gdb] Speedup lnp_state_machine::handle_special_opcode
I see for some program at gdb startup:
...
Samples: 102K of event 'cycles:pu', Event count (approx.): 91710925103
Overhead  Command     Shared Object        Symbol
  15.21%  gdb         gdb                  [.]
lnp_state_machine::handle_special
...
where the divisions are the places we stall.  The following
micro-optimizes things but it smells like m_line_header->line_range
is constant, likewise probably m_line_header->maximum_ops_per_instruction
so eventually the divisions could be avoided completely with some
lookup table.

Well.  Micro-optimizing with this patch improves things
(don't expect [load] CSE over the gdbarch_adjust_dwarf2_line call).

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-14  Richard Biener  <rguenther@suse.de>

	* dwarf2/read.c (lnp_state_machine::handle_special_opcode): Apply CSE
	on expression with division operators.
2020-02-14 08:32:53 +01:00
Tom Tromey 3d4560f707 Move the frame data to the BFD when possible
Now that comp_unit and the remaining frame data are all independent of
the objfile, it can all be stored on the BFD and shared across
inferiors.

As with other code doing this same thing, care must be taken to not
share the data when the objfile requires relocations.  So, two keys
are used: one for the BFD and one for the objfile, and
gdb_bfd_requires_relocations is used to differentiate between the two
cases.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (dwarf2_frame_bfd_data): New global.
	(dwarf2_frame_objfile_data): Add comment.
	(find_comp_unit, set_comp_unit): New functions.
	(dwarf2_frame_find_fde): Use find_comp_unit.
	(dwarf2_build_frame_info): Use set_comp_unit.
2020-02-12 15:51:58 -07:00
Tom Tromey 2198230456 Remove the objfile backlink from comp_unit
This removes the objfile backlink from comp_unit.  The only remaining
uses involved fetching the text offset from the objfile.  However,
this is already conveniently computed at all the sites that call
execute_cfa_program, and so it can simply be passed in.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (struct comp_unit) <objfile>: Remove.
	(comp_unit): Don't initialize objfile.
	(execute_cfa_program): Add text_offset parameter.
	(execute_cfa_program_test, dwarf2_fetch_cfa_info)
	(dwarf2_frame_cache): Update.
	(dwarf2_build_frame_info): Don't set "objfile" member.
2020-02-12 15:51:58 -07:00
Tom Tromey 4debb23796 Remove a use of the comp_unit backlink
The DWARF frame comp_unit object still has a backlink to the objfile.
In order to be truly objfile-independent, this must be removed.

This patch removes one such use, by passing the gdbarch to
decode_frame_entry directly.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (decode_frame_entry_1): Add gdbarch parameter.
	(decode_frame_entry): Likewise.
	(dwarf2_build_frame_info): Update.
2020-02-12 15:51:58 -07:00
Tom Tromey 0d404d447a Add per-unit obstack
This adds an auto_obstack to the DWARF frame comp_unit object, and
then changes the remaining code here to use the comp_unit obstack
rather than the objfile obstack.

At this point, all the storage for frame data is self-contained --
that is, it is independent of the objfile.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (struct comp_unit) <obstack>: New member.
	(decode_frame_entry_1): Use the comp_unit obstack.
2020-02-12 15:51:58 -07:00
Tom Tromey a7a3ae5c02 Store the comp_unit instead of the FDE table
This changes the DWARF frame code to store the comp_unit on the
objfile, rather than storing the FDE table.  It also changes the
comp_unit to be heap-allocated using "new".

This change makes it simpler for a later patch to add a field to the
comp_unit, and to have deallaction work properly.  This in turn is
important for making the frame data be independent of the objfile.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (struct comp_unit): Add initializers and
	constructor.
	(dwarf2_frame_objfile_data): Store a comp_unit.
	(dwarf2_frame_find_fde): Update.
	(dwarf2_build_frame_info): Use "new".
2020-02-12 15:51:58 -07:00
Tom Tromey a9d6541862 Change fde table to a vector
This removes struct dwarf2_fde_table, replacing it with a typedef of
std::vector.  This simplifies the code somewhat.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.c (struct dwarf2_fde_table): Remove.
	(dwarf2_fde_table): Typedef for std::vector.
	(dwarf2_frame_objfile_data): Remove the deleter.  Now static.
	(dwarf2_frame_find_fde, add_fde, decode_frame_entry_1)
	(decode_frame_entry): Update.
	(dwarf2_build_frame_info): Use "new".
2020-02-12 15:51:58 -07:00
Tom Tromey d27b8e5f14 Remove dwarf_expr_baton
The type dwarf_expr_baton is unused and can be removed.

gdb/ChangeLog
2020-02-12  Tom Tromey  <tom@tromey.com>

	* dwarf2/loc.c (struct dwarf_expr_baton): Remove.

Change-Id: Id8342da31398b9b4b08f31be7c3d612e9590bbbf
2020-02-12 14:41:33 -07:00
Tom Tromey 3fd6912bb1 Don't forward-declare struct objfile in dwarf2/frame.h
dwarf2/frame.h forward-declares struct objfile, but there's no need
for this.

gdb/ChangeLog
2020-02-11  Tom Tromey  <tom@tromey.com>

	* dwarf2/frame.h (struct objfile): Don't forward declare.

Change-Id: I4d54d46ac9422eeb64dc5f0b934792e77a875aa5
2020-02-11 17:57:46 -07:00
Tom de Vries 85f0dd3ce8 [gdb] Fix -Wstrict-null-sentinel warnings
When passed in CXXFLAGS, -Wstrict-null-sentinel triggers twice in a
gdb/gdbserver build.

Fix the two occurrences.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Cast concat NULL
	sentinel to char *.

gdbsupport/ChangeLog:

2020-02-10  Tom de Vries  <tdevries@suse.de>

	* environ.c (gdb_environ::set): Cast concat NULL sentinel to char *.
2020-02-10 15:13:42 +01:00
Tom de Vries 2e9276136b [gdb] Mention CU offset for <artifical> if verbose
Say we're debugging a test-case with CUs with name "<artificial>", meaning
not originating from a single file compilation, and use the verbose setting:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>... \
  and /tmp/trunk/gcc/attribs.c... \
  ...
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

From the "/tmp/trunk/gcc/attribs.c" message, it's clear which CU is loaded.  But
that's not the case for the "<artificial>" message.

The message uses the filename field of struct partial_symtab, which is
documented like this:
...
  /* Name of the source file which this partial_symtab defines,
     or if the psymtab is anonymous then a descriptive name for
     debugging purposes, or "".  It must not be NULL.  */
...

So, fix this by setting the filename field to a more descriptive name than
"<artificial>", by appending the CU offset.

This way, we print instead:
...
$ gdb -iex "set verbose on" -batch cc1
Reading symbols from cc1...
Reading in symbols for <artificial>@0x41146d9 \
  and /tmp/trunk/gcc/attribs.c... \
  ... \
  and /tmp/trunk/gcc/tree-ssa-reassoc.c... \
  done.
...

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

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

	* dwarf2read.c (process_psymtab_comp_unit_reader): Append CU offset to
	filename if it matches "<artificial>".
2020-02-09 13:32:26 +01:00
Tom Tromey 6751ebaea0 Remove "keep" parameter from cutu_reader constructor
cutu_reader has a "keep" parameter, which is used to decide what to do
with a new CU when the reader is destroyed.  Most code does not try to
preserve the CU, so this patch removes this parameter and instead adds
a new method that users can call to preserve the CU on the chain.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (class cutu_reader) <cutu_reader,
	init_tu_and_read_dwo_dies>: Remove "keep" parameter.
	<keep>: Declare method.
	<m_keep>: Remove member.
	<~cutu_reader>: Remove.
	(cutu_reader::init_tu_and_read_dwo_dies): Update.
	(cutu_reader::cutu_reader): Update.
	(cutu_reader::keep): Rename from ~cutu_reader.
	(process_psymtab_comp_unit, build_type_psymtabs_1)
	(process_skeletonless_type_unit, load_partial_comp_unit)
	(load_full_comp_unit, dwarf2_read_addr_index)
	(read_signatured_type): Update.

Change-Id: I859b1c64313569d76d46317c14e9b077ebc3a27b
2020-02-08 13:43:55 -07:00
Tom Tromey 135f543748 Simplify "want_partial_unit" handling
This changes the "want_partial_unit" parameters to have type bool, and
also removes the parameter from process_psymtab_comp_unit_reader.
This latter change seemed like an improvement, because it avoids a
pointless function call in the case where we are not planning to read
a partial unit.

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

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Remove
	"want_partial_unit" parameter.
	(process_psymtab_comp_unit): Change want_partial_unit to bool.
	Inline check for DW_TAG_partial_unit.
	(dwarf2_build_psymtabs_hard, scan_partial_symbols): Update.

Change-Id: I99e647f0c4faa3346e90a6e7bacc82af57eccff1
2020-02-08 13:43:24 -07:00
Tom Tromey 9f66ff1c8c Move two more functions to dwarf2/leb.h
This moves read_n_bytes and read_direct_string to be with the the
low-level value-reading code.

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

	* dwarf2/read.c (read_n_bytes, read_direct_string): Move to
	read.c.
	* dwarf2/leb.h (read_n_bytes, read_direct_string): Move from
	read.c.

Change-Id: Id07bfa13d93c0ac1f47a385749a8f01f4755b818
2020-02-08 13:43:24 -07:00
Tom Tromey c8a7a66fb7 Convert read_address to a method on comp_unit_head
This changes read_address to be a method on comp_unit_head.

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

	* dwarf2/read.c (read_address): Move to comp-unit.c.
	(dwarf2_rnglists_process, dwarf2_ranges_process)
	(read_attribute_value, dwarf_decode_lines_1)
	(var_decode_location, decode_locdesc): Update.
	* dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
	read.c.  Remove "cu" parameter.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
	method.

Change-Id: Ibd6c7235f2e4d5fd88c272cfd2c3d3328618cc56
2020-02-08 13:43:24 -07:00
Tom Tromey 8266302dc3 Convert read_offset to method on comp_unit_head
This changes one of the read_offset overloads to be a method on
comp_unit_head.

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

	* dwarf2/read.c (read_attribute_value, read_indirect_string)
	(read_indirect_line_string): Update.
	* dwarf2/comp-unit.c (read_offset): Remove.
	(read_comp_unit_head): Update.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_offset>: New
	method.
	(read_offset): Don't declare.

Change-Id: Ia595702a5748337b7c031352bc437956baab9990
2020-02-08 13:43:24 -07:00
Tom Tromey 4057dfde49 Create dwarf2/comp-unit.[ch]
This creates the new files dwarf2/comp-unit.[ch], moving
comp_unit_head and helpers to those files.  A couple of functions are
turned into methods, because it was convenient to do so now.

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

	* Makefile.in (COMMON_SFILES): Add dwarf2/comp-unit.c.
	* dwarf2/read.c (struct comp_unit_head): Move to
	dwarf2/comp-unit.h.
	(enum class rcuh_kind): Move to comp-unit.h.
	(get_cu_length, offset_in_cu_p): Now methods on comp_unit_head.
	(read_comp_unit_head, error_check_comp_unit_head)
	(read_and_check_comp_unit_head): Move to comp-unit.c.
	(read_offset, dwarf_unit_type_name): Likewise.
	(create_debug_type_hash_table, read_cutu_die_from_dwo)
	(cutu_reader::cutu_reader, read_call_site_scope)
	(find_partial_die, follow_die_offset): Update.
	* dwarf2/comp-unit.h: New file, from dwarf2read.c.

Change-Id: Id961b9674c0081ed061083c8152c38b27b27388a
2020-02-08 13:43:24 -07:00
Tom Tromey 24aa364d60 Move read_offset_1 to leb.c
This moves read_offset_1 to leb.c, as it is a low-level data-reading
function.  It is also renamed to remove the "_1", because gdb can use
overloading now, and this is clearer.

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

	* dwarf2/read.c (read_offset_1): Move to leb.c.
	(read_abbrev_offset, read_offset, dwarf_decode_line_header)
	(dwarf_decode_macro_bytes): Update.
	* dwarf2/leb.c (read_offset): Rename; move from read.c.
	* dwarf2/leb.h (read_offset): Declare.

Change-Id: I048140598acfa76eade2cc529ab7933d4b9ca0b3
2020-02-08 13:43:24 -07:00
Tom Tromey 2c7d5afccf Convert dwarf2_section_size to a method
This changes dwarf2_section_size to be a method on
dwarf2_section_info.

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

	* dwarf2/read.c (dwarf2_section_size): Remove.
	(error_check_comp_unit_head, dwarf2_symbol_mark_computed):
	Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_size>: New method.

Change-Id: I12928fee5c84350ce98883e329357b86888d639b
2020-02-08 13:43:24 -07:00
Tom Tromey 4075cb2668 Unify read_initial_length implementations
There are two implementations of read_initial_length in gdb.  This
merges them and moves the resulting function to leb.c.

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

	* dwarf2/read.c (read_initial_length): Move to leb.c.
	* dwarf2/leb.h (read_initial_length): Declare.
	* dwarf2/leb.c (read_initial_length): Move from read.c.  Add
	handle_nonstd parameter.
	* dwarf2/frame.c (read_initial_length): Remove.
	(decode_frame_entry_1): Update.

Change-Id: I34d37bad0f8a584bfa781432cba25e05e1bd5750
2020-02-08 13:43:24 -07:00
Tom Tromey 09ba997f32 Add some methods to dwarf2_per_cu_data
This changes a few helper functions to be methods on
dwarf2_per_cu_data.

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

	* dwarf2/loc.c (dwarf2_find_location_expression)
	(dwarf_evaluate_loc_desc::get_tls_address)
	(dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value)
	(rw_pieced_value, dwarf2_evaluate_loc_desc_full)
	(dwarf2_locexpr_baton_eval, dwarf2_evaluate_property)
	(dwarf2_compile_property_to_c)
	(dwarf2_loc_desc_get_symbol_read_needs)
	(dwarf2_compile_expr_to_ax, locexpr_describe_location)
	(locexpr_tracepoint_var_ref, locexpr_generate_c_location)
	(loclist_describe_location, loclist_tracepoint_var_ref)
	(loclist_generate_c_location): Update.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update.
	* dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size)
	(dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size)
	(dwarf2_per_cu_text_offset, dwarf2_version): Don't declare.
	* dwarf2/read.c (dwarf2_per_cu_data::objfile)
	(dwarf2_per_cu_data::addr_size)
	(dwarf2_per_cu_data::ref_addr_size)
	(dwarf2_per_cu_data::text_offset)
	(dwarf2_per_cu_data::addr_type): Now methods.
	(per_cu_header_read_in): Make per_cu "const".
	(dwarf2_version): Remove.
	(dwarf2_per_cu_data::int_type): Now a method.
	(dwarf2_per_cu_data::_addr_sized_int_type): Likewise.
	(set_die_type, read_array_type, read_subrange_index_type)
	(read_tag_string_type, read_subrange_type): Update.
	* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_size,
	offset_size, ref_addr_size, text_offset, addr_type, version,
	objfile, int_type, addr_sized_int_type>: Declare methods.

Change-Id: I07a42fa26e00795352389fa7a0cc1c12997d26f7
2020-02-08 13:43:24 -07:00
Tom Tromey 96c738c02f Move dwarf2_per_cu_data::imported_symtabs earlier
This moves dwarf2_per_cu_data::imported_symtabs earlier, near where
the other data members are located.

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

	* dwarf2/read.h (struct dwarf2_per_cu_data) <imported_symtabs>:
	Move earlier.

Change-Id: I314ddaa6f67c53a848e513b3f6d42913bd957833
2020-02-08 13:43:24 -07:00
Tom Tromey 8fdd972c30 Move DWARF line_header to new file
This moves the line_header class to a pair of new files, making
dwarf2/read.c somewhat smaller.

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

	* dwarf2/read.h (dwarf_line_debug): Declare.
	* Makefile.in (COMMON_SFILES): Add dwarf2/line-header.c.
	* dwarf2/read.c: Move line_header code to new files.
	(dwarf_line_debug): No longer static.
	* dwarf2/line-header.c: New file.
	* dwarf2/line-header.h: New file.

Change-Id: I8d9d8a2398b4e888e20cc5dd68d041c28b5a06e3
2020-02-08 13:43:24 -07:00
Tom Tromey 0307581275 Change line_table methods to return unique_xmalloc_ptr
This changes the two new line_table methods to return
unique_xmalloc_ptr.  This removes a bit of manual memory management.

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

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Return unique_xmalloc_ptr.
	(line_header::file_file_name): Update.
	(line_header::file_full_name): Update.
	(dw2_get_file_names_reader): Update.
	(macro_start_file): Update.

Change-Id: I9442dba43882fb26097d0770a291eea2b03913a4
2020-02-08 13:43:24 -07:00
Tom Tromey bb82240439 Change file_full_name and file_file_name methods
This changes file_full_name and file_file_name methods to be methods
on line_header.  This seems more clear to me.

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

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Declare methods.
	(dw2_get_file_names_reader): Update.
	(file_file_name): Now a method.
	(file_full_name): Likewise.
	(macro_start_file): Update.

Change-Id: I50d3e91665a9637c732e1e8d8e4263764c766d9c
2020-02-08 13:43:24 -07:00
Tom Tromey 009b64fc98 Move dwarf_always_disassemble to dwarf2/loc.c
dwarf_always_disassemble is only used in dwarf2/loc.c, so move the
definition and the command infrastructure to that file.

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

	* dwarf2/read.c (dwarf_always_disassemble)
	(show_dwarf_always_disassemble): Move to loc.c.
	(_initialize_dwarf2_read): Move "always-disassemble" registration
	to loc.c.
	* dwarf2/read.h (dwarf_always_disassemble): Don't declare.
	* dwarf2/loc.c (dwarf_always_disassemble): Move from read.c.  Now
	static.
	(show_dwarf_always_disassemble): Move from read.c.
	(_initialize_dwarf2loc): Move always-disassemble from read.c.

Change-Id: I33fb88112e98e583c3f4919d20e4d100f2ea0124
2020-02-08 13:43:24 -07:00
Tom Tromey 5895093f4a Change dwarf2_per_objfile::quick_file_names_table to htab_up
This changes dwarf2_per_objfile::quick_file_names_table to be an
htab_up.  This just removes a bit of manual management.

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

	* dwarf2/read.c (~dwarf2_per_objfile): Update.
	(create_quick_file_names_table): Return htab_up.
	(dw2_get_file_names_reader, dw2_forget_cached_source_info):
	Update.
	* dwarf2/read.h (struct dwarf2_per_objfile)
	<quick_file_names_table>: Now htab_up.

Change-Id: I4ff2fce8b8af27f4bfe01a11b97a889edfd23151
2020-02-08 13:43:24 -07:00
Tom Tromey b3b3227982 Minor simplification in abbrev_table::read
abbrev_table::read increments cur_abbrev->num_attrs in the inner loop,
but there's no need to do this, as the information is already stored
in the temporary vector.

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

	* dwarf2/abbrev.c (abbrev_table::read): Simplify.

Change-Id: I765f12850ffa1c6066e884bb22c94468d1abdba4
2020-02-08 13:43:24 -07:00
Tom Tromey 1d33d811c7 Use htab_up in abbrev_table
This changes abbrev_table to use an htab_up rather than an ad hoc,
bucket-based hash table.

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

	* dwarf2/abbrev.c (abbrev_table): Move constructor from header.
	Rewrite.
	(abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite.
	* dwarf2/abbrev.h (struct abbrev_info) <next>: Remove.
	(abbrev_table::abbrev_table): No longer inline.
	(ABBREV_HASH_SIZE): Remove.
	(abbrev_table::m_abbrevs): Now an htab_up.

Change-Id: Icbaa8e49501f9c43218d6a81a7e8c4d3a77d65dc
2020-02-08 13:43:24 -07:00
Tom Tromey 86de1d91ac Minor cleanups in abbrev_table
This cleans up the DWARF abbrev_table API a bit, primarily by making
various methods and members private.

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

	* dwarf2/read.c (read_cutu_die_from_dwo): Update.
	(cutu_reader): Update.
	(build_type_psymtabs_1): Update.
	* dwarf2/abbrev.c (abbrev_table::read): Rename.
	(abbrev_table::alloc_abbrev): Update.
	* dwarf2/abbrev.h (abbrev_table_up): Move earlier.
	(abbrev_table::read): New static method, renamed from
	abbrev_table_read_table.
	(abbrev_table::alloc_abbrev)
	(abbrev_table::add_abbrev): Now private.
	(abbrev_table::abbrev_table): Now private.
	(abbrev_table::m_abbrev_obstack): Now private.  Rename.

Change-Id: I320dca83b799f672909ae66f73b7aca266adbaf9
2020-02-08 13:43:24 -07:00
Tom Tromey 0335378b4c Change dwarf2_per_objfile::die_type_hash to htab_up
This changes dwarf2_per_objfile::die_type_hash to be an htab_up,
moving its contents off the objfile obstack.

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

	* dwarf2/read.c (set_die_type, get_die_type_at_offset): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <die_type_hash>: Now
	htab_up.

Change-Id: Ic651f99ebf71bf7ad2dc2880192adacf7b60964a
2020-02-08 13:43:24 -07:00
Tom Tromey 48b490f28a Change dwp_file to use htab_up
This changes dwp_file to use htab_up for the loaded_cus and loaded_tus
members.  This lets us avoid allocating the contents of these hash
tables on the objfile obstack.

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

	* dwarf2/read.c (struct dwp_file) <loaded_cus, loaded_tus>: Now
	htab_up.
	(lookup_dwo_unit_in_dwp): Update.
	(allocate_dwp_loaded_cutus_table): Return htab_up.  Don't allocate
	on obstack.

Change-Id: Id61209bf5c6c6faa0c067195af31fbcf26813a3a
2020-02-08 13:43:24 -07:00
Tom Tromey bc68fb1930 Don't allocate DWO file hash on obstack
This changes allocate_dwo_file_hash_table so that it does not use the
objfile obstack to store the contents of the hash table.

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

	* dwarf2/read.c (allocate_dwo_file_hash_table): Don't allocate on
	obstack.

Change-Id: Ic20a618acc7277e56aa18580c68f75c793bef97b
2020-02-08 13:43:24 -07:00
Tom Tromey d15acc4252 Change dwarf2_per_objfile::line_header_hash to htab_up
This changes dwarf2_per_objfile::line_header_hash to be an htab_up,
and changes it to use heap allocation.

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

	* dwarf2/read.c (~dwarf2_per_objfile): Don't delete
	line_header_hash.
	(handle_DW_AT_stmt_list): Update.  Don't allocate on obstack.
	* dwarf2/read.h (struct dwarf2_per_objfile) <line_header_hash>:
	Change type to htab_up.

Change-Id: Icb148a270838c0f96f38fc4a28b5b77d067927b6
2020-02-08 13:43:24 -07:00
Tom Tromey eaa5fa8b29 Change dwarf2_per_objfile::type_unit_groups to htab_up
This changes dwarf2_per_objfile::type_unit_groups to be an htab_up,
again allowing us to move the memory used by the hash table from the
objfile obstack to the heap.

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

	* dwarf2/read.c (allocate_type_unit_groups_table): Return
	htab_up.  Don't allocate on obstack.
	(get_type_unit_group, dwarf2_build_psymtabs_hard): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <type_unit_groups>:
	Change type to htab_up.

Change-Id: Ia045df0ff3ec30aac813da5a9a2314a607ef7ec8
2020-02-08 13:43:24 -07:00
Tom Tromey b0b6a9878a Change dwarf2_per_objfile::signatured_types to be htab_up
This changes dwarf2_per_objfile::signatured_types to be an htab_up.
This in turn lets us change it not to use the objfile obstack for
allocation; obstack allocation for hash tables is a bad practice
because it leads to excess memory use if the table is ever resized.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_objfile) <signatured_types>:
	Change type to htab_up.
	* dwarf2/read.c (create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names)
	(create_all_type_units, add_type_unit)
	(lookup_dwo_signatured_type, lookup_signatured_type)
	(process_skeletonless_type_unit): Update.
	(create_debug_type_hash_table, create_debug_types_hash_table):
	Change type of types_htab.
	(allocate_signatured_type_table, allocate_dwo_unit_table): Return
	htab_up.  Don't allocate on obstack.
	(create_cus_hash_table): Change type of cus_htab parameter.
	(struct dwo_file) <cus, tus>: Now htab_up.
	(lookup_dwo_signatured_type, lookup_dwo_cutu)
	(process_dwo_file_for_skeletonless_type_units, lookup_dwo_cutu)
	(queue_and_load_all_dwo_tus): Update.
	* dwarf2/index-write.c (write_gdbindex): Update.
	(write_debug_names): Update.

Change-Id: I290a209b96945fb5f415c82723b62830e9c4b467
2020-02-08 13:43:03 -07:00
Tom Tromey 39856def4f Remove DWARF queue-related globals
This removes some queue-related globals from the DWARF reader, in
favor of a new member on dwarf2_per_objfile.  Globals must be avoided
in this code, because they prevent multi-threading the reader.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_queue_item): Move from
	dwarf2/read.c.  Remove "next" member.  Add constructor ntad
	destructor.
	(struct dwarf2_per_objfile) <queue>: New member.
	* dwarf2/read.c (struct dwarf2_queue_item): Move to
	dwarf2/read.h.
	(dwarf2_queue, dwarf2_queue_tail): Remove.
	(class dwarf2_queue_guard): Add parameter to constructor.  Use
	DISABLE_COPY_AND_ASSIGN.
	<m_per_objfile>: New member.
	<~dwarf2_queue_guard>: Rewrite.
	(dw2_do_instantiate_symtab, queue_comp_unit, process_queue):
	Update.
	(~dwarf2_queue_item): New.

Change-Id: Ied1f6ff3691352a66c4709b0b2cba0588f49f79a
2020-02-08 13:41:00 -07:00
Tom Tromey 3e22507450 Introduce die_info::has_children
Many functions take a "has_children" parameter (either as an in- or
out-parameter).  However, it seems to me that it makes more sense to
have "has_children" be an attribute of a DIE.  Making this change
allows this parameter to be eliminated in many places.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct die_info) <has_children>: New member.
	(dw2_get_file_names_reader): Remove has_children.
	(dw2_get_file_names): Update.
	(read_cutu_die_from_dwo): Remove has_children.
	(cutu_reader::init_tu_and_read_dwo_dies)
	(cutu_reader::cutu_reader): Update.
	(process_psymtab_comp_unit_reader, build_type_psymtabs_reader):
	Remove has_children.
	(build_type_psymtabs_1, process_skeletonless_type_unit)
	(load_partial_comp_unit, load_full_comp_unit): Update.
	(create_dwo_cu_reader): Remove has_children.
	(create_cus_hash_table, read_die_and_children): Update.
	(read_full_die_1,read_full_die): Remove has_children.
	(read_signatured_type): Update.
	(class cutu_reader) <has_children>: Remove.

Change-Id: I0d3d51ae9379554a66032648d51124bba07f87b4
2020-02-08 13:40:59 -07:00
Tom Tromey 82ca895718 Move DWARF code to dwarf2/ subdirectory
This moves all the remaining DWARF code to the new dwarf2
subdirectory.  This is just a simple renaming, with updates to
includes as needed.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2/expr.c: Rename from dwarf2expr.c.
	* dwarf2/expr.h: Rename from dwarf2expr.h.
	* dwarf2/frame-tailcall.c: Rename from dwarf2-frame-tailcall.c.
	* dwarf2/frame-tailcall.h: Rename from dwarf2-frame-tailcall.h.
	* dwarf2/frame.c: Rename from dwarf2-frame.c.
	* dwarf2/frame.h: Rename from dwarf2-frame.h.
	* dwarf2/index-cache.c: Rename from dwarf-index-cache.c.
	* dwarf2/index-cache.h: Rename from dwarf-index-cache.h.
	* dwarf2/index-common.c: Rename from dwarf-index-common.c.
	* dwarf2/index-common.h: Rename from dwarf-index-common.h.
	* dwarf2/index-write.c: Rename from dwarf-index-write.c.
	* dwarf2/index-write.h: Rename from dwarf-index-write.h.
	* dwarf2/loc.c: Rename from dwarf2loc.c.
	* dwarf2/loc.h: Rename from dwarf2loc.h.
	* dwarf2/read.c: Rename from dwarf2read.c.
	* dwarf2/read.h: Rename from dwarf2read.h.
	* dwarf2/abbrev.c, aarch64-tdep.c, alpha-tdep.c,
	amd64-darwin-tdep.c, arc-tdep.c, arm-tdep.c, bfin-tdep.c,
	compile/compile-c-symbols.c, compile/compile-cplus-symbols.c,
	compile/compile-loc2c.c, cris-tdep.c, csky-tdep.c, findvar.c,
	gdbtypes.c, guile/scm-type.c, h8300-tdep.c, hppa-bsd-tdep.c,
	hppa-linux-tdep.c, i386-darwin-tdep.c, i386-linux-tdep.c,
	i386-tdep.c, iq2000-tdep.c, m32c-tdep.c, m68hc11-tdep.c,
	m68k-tdep.c, microblaze-tdep.c, mips-tdep.c, mn10300-tdep.c,
	msp430-tdep.c, nds32-tdep.c, nios2-tdep.c, or1k-tdep.c,
	riscv-tdep.c, rl78-tdep.c, rs6000-tdep.c, rx-tdep.c, s12z-tdep.c,
	s390-tdep.c, score-tdep.c, sh-tdep.c, sparc-linux-tdep.c,
	sparc-tdep.c, sparc64-linux-tdep.c, sparc64-tdep.c, tic6x-tdep.c,
	tilegx-tdep.c, v850-tdep.c, xstormy16-tdep.c, xtensa-tdep.c:
	Update.
	* Makefile.in (COMMON_SFILES): Update.
	(HFILES_NO_SRCDIR): Update.

Change-Id: Ied9ce1436cd27ac4a4cffef10ec92e396f181928
2020-02-08 13:40:59 -07:00
Tom Tromey 4fc6c0d534 Change attr_form_is_block to be a method
This changes attr_form_is_block to be a method.  This is done
separately because, unlike the other attribute functions,
attr_form_is_block had special handling for the case where the
argument was NULL.  This required auditing each call site; in most
cases, NULL was already ruled out, but in a few spots, an additional
check was needed.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_call_site_scope)
	(handle_data_member_location, dwarf2_add_member_fn)
	(mark_common_block_symbol_computed, read_common_block)
	(attr_to_dynamic_prop, partial_die_info::read)
	(var_decode_location, dwarf2_fetch_die_loc_sect_off)
	(dwarf2_symbol_mark_computed, set_die_type): Update.
	* dwarf2/attribute.h (struct attribute) <form_is_block>: Declare
	method.
	(attr_form_is_block): Don't declare.
	* dwarf2/attribute.c (attribute::form_is_block): Now a method.

Change-Id: Idfb290c61d738301ab991666f43e0b9cf577b2ae
2020-02-08 13:40:57 -07:00
Tom Tromey cd6c91b4f8 Change some attribute functions to be methods
This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_find_base_address, )
	(read_call_site_scope, rust_containing_type)
	(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
	(handle_data_member_location, dwarf2_add_member_fn)
	(get_alignment, read_structure_type, process_structure_scope)
	(mark_common_block_symbol_computed, read_common_block)
	(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
	(partial_die_info::read, read_attribute_value, new_symbol)
	(lookup_die_type, dwarf2_get_ref_die_offset)
	(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
	(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
	(dwarf2_symbol_mark_computed): Update.
	* dwarf2/attribute.h (struct attribute) <value_as_address,
	form_is_section_offset, form_is_constant, form_is_ref>: Declare
	methods.
	(value_as_address, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Don't declare.
	* dwarf2/attribute.c (attribute::value_as_address)
	(attribute::form_is_section_offset, attribute::form_is_constant)
	(attribute::form_is_ref): Now methods.

Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
2020-02-08 13:40:56 -07:00
Tom Tromey 162dce5526 Create dwarf2/attribute.[ch]
This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct attribute, DW_STRING)
	(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
	(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
	(attr_form_is_block, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Move.
	* dwarf2/attribute.h: New file.
	* dwarf2/attribute.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.

Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
2020-02-08 13:40:56 -07:00
Tom Tromey 3054dd5470 Create dwarf2/abbrev.[ch]
This moves the abbrev table code out of dwarf2read.c and into new
files dwarf2/abbrev.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (abbrev_table_up, struct abbrev_info)
	(struct attr_abbrev, ABBREV_HASH_SIZE, struct abbrev_table):
	Move.
	(read_cutu_die_from_dwo, build_type_psymtabs_1): Update.
	(abbrev_table::alloc_abbrev, abbrev_table::add_abbrev)
	(abbrev_table::lookup_abbrev, abbrev_table_read_table): Move to
	abbrev.c.
	* dwarf2/abbrev.h: New file.
	* dwarf2/abbrev.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/abbrev.c.

Change-Id: I87911bc5297de4407587ca849fef8e8d19136c30
2020-02-08 13:40:55 -07:00
Tom Tromey 96b792931f Change section functions to be methods of dwarf2_section_info
This changes various section-related functions to be methods on
dwarf2_section_info.  I think this clarifies the role of these
functions.  This also changes one such function to return bool.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_section_buffer_overflow_complaint)
	(dwarf2_section_size, dwarf2_get_section_info)
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges, read_debug_names_from_section)
	(get_gdb_index_contents_from_section, read_comp_unit_head)
	(error_check_comp_unit_head, read_abbrev_offset)
	(create_debug_type_hash_table, init_cu_die_reader)
	(read_cutu_die_from_dwo, dwarf2_build_psymtabs_hard)
	(read_comp_units_from_section, create_cus_hash_table)
	(create_dwp_hash_table, create_dwo_unit_in_dwp_v1)
	(create_dwp_v2_section, dwarf2_rnglists_process)
	(dwarf2_ranges_process, read_die_and_siblings, read_full_die)
	(abbrev_table_read_table, read_indirect_string_at_offset_from)
	(read_indirect_string_from_dwz, read_addr_index_1)
	(read_str_index, dwarf_decode_line_header, skip_form_bytes)
	(dwarf_decode_macro_bytes, dwarf_decode_macros)
	(fill_in_loclist_baton): Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_name,
	get_containing_section, get_bfd_owner, get_bfd_section,
	get_file_name, get_id, get_flags, empty, read>: Declare methods.
	(dwarf2_read_section, get_section_name, get_section_file_name)
	(get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name, get_section_file_name)
	(get_section_id, get_section_flags, dwarf2_section_empty_p): Don't
	declare.
	* dwarf2/section.c (dwarf2_section_info::get_containing_section)
	(dwarf2_section_info::get_bfd_owner)
	(dwarf2_section_info::get_bfd_section)
	(dwarf2_section_info::get_name)
	(dwarf2_section_info::get_file_name, dwarf2_section_info::get_id)
	(dwarf2_section_info::get_flags, dwarf2_section_info::empty)
	(dwarf2_section_info::read): Now methods.
	* dwarf-index-write.c (class debug_names): Update.

Change-Id: Ic849f182f57a18bad6b1c7c3b9368005d307758a
2020-02-08 13:40:55 -07:00
Tom Tromey 2c86cff96f Create dwarf2/section.[ch]
This moves some section-handling code from dwarf2read.c into new
files, dwarf2/section.[ch].

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct dwarf2_section_info, dwarf2_read_section):
	Move to dwarf2/section.h.
	* dwarf2read.c (get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name)
	(get_section_file_name, get_section_id, get_section_flags)
	(dwarf2_section_empty_p, dwarf2_read_section): Moe to
	dwarf2/section.c.
	* dwarf2/section.h: New file.
	* dwarf2/section.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/section.c.

Change-Id: I9f8498094cf99d9521e9481622ce8adbd453daf4
2020-02-08 13:40:54 -07:00
Tom Tromey f4382c45a4 Create dwarf2/leb.[ch]
This moves some scalar-unpacking code into a couple of new files,
dwarf2/leb.h and dwarf2/leb.c.

gdb/ChangeLog
2020-02-08  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (read_unsigned_leb128): Don't declare.
	* dwarf2read.c (read_1_byte, read_1_signed_byte, read_2_bytes)
	(read_2_signed_bytes, read_3_bytes, read_4_bytes)
	(read_4_signed_bytes, read_8_bytes): Move to dwarf2/leb.h.
	(read_unsigned_leb128, read_signed_leb128): Move to dwarf2/leb.c.
	* dwarf2/leb.h: New file, from dwarf2read.c.
	* dwarf2/leb.c: New file, from dwarf2read.c.
	* dwarf2-frame.c (read_1_byte, read_4_bytes, read_8_bytes):
	Remove.
	* Makefile.in (CONFIG_SRC_SUBDIR): Add dwarf2.
	(COMMON_SFILES): Add dwarf2/leb.c.

Change-Id: Idd19647686c8f959d226a95fdfca4db47c6e96d0
2020-02-08 13:40:54 -07:00