Commit Graph

29156 Commits

Author SHA1 Message Date
Tom Tromey a4a38eb437 Cache .gnu_debugdata BFD
While looking at the output of "maint info bfd" with multiple
inferiors, I noticed that there were duplicate entries for
.gnu_debugdata.

There is no reason to re-create this BFD each time it is needed.  This
patch arranges to share the data.

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

	* minidebug.c (gnu_debug_key): New global.
	(find_separate_debug_file_in_section): Use it.

Change-Id: If139f89f0f07db33f399afdbcfbf5aaeffe4de46
2020-02-14 14:16:24 -07:00
Simon Marchi e8217e61f5 gdb: make gdbarch_displaced_step_copy_insn return an std::unique_ptr
This callback dynamically allocates a specialized displaced_step_closure, and
gives the ownership of the object to its caller.  So I think it would make
sense for the callback to return an std::unique_ptr, this is what this patch
implements.

gdb/ChangeLog:

	* gdbarch.sh (displaced_step_copy_insn): Change return type to an
	std::unique_ptr.
	* gdbarch.c: Re-generate.
	* gdbarch.h: Re-generate.
	* infrun.c (displaced_step_prepare_throw): Adjust to std::unique_ptr
	change.
	* aarch64-tdep.c (aarch64_displaced_step_copy_insn): Change return
	type to std::unique_ptr.
	* aarch64-tdep.h (aarch64_displaced_step_copy_insn): Likewise.
	* amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise.
	* amd64-tdep.h (amd64_displaced_step_copy_insn): Likewise.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
	* i386-linux-tdep.c (i386_linux_displaced_step_copy_insn): Likewise.
	* i386-tdep.c (i386_displaced_step_copy_insn): Likewise.
	* i386-tdep.h (i386_displaced_step_copy_insn): Likewise.
	* rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise.
	* s390-tdep.c (s390_displaced_step_copy_insn): Likewise.
2020-02-14 15:29:08 -05:00
Simon Marchi d8d83535e6 gdb: cleanup of displaced_step_inferior_state::reset/displaced_step_clear
displaced_step_inferior_state::reset and displaced_step_clear appear to
have the same goal, but they don't do the same thing.
displaced_step_inferior_state::reset clears more things than
displaced_step_clear, but it misses free'ing the closure, which
displaced_step_clear does.

This patch replaces displaced_step_clear's implementation with just a call to
displaced_step_inferior_state::reset.  It then changes
displaced_step_inferior_state::step_closure to be a unique_ptr, to indicate the
fact that displaced_step_inferior_state owns the closure (and so that it is
automatically freed when the field is reset).

The test gdb.base/step-over-syscall.exp caught a problem when doing this, which
I consider to be a latent bug which my cleanup exposes.  In
handle_inferior_event, in the TARGET_WAITKIND_FORKED case, if we displaced-step
over a fork syscall, we make sure to restore the memory that we used as a
displaced-stepping buffer in the child.  We do so using the
displaced_step_inferior_state of the parent.  However, we do it after calling
displaced_step_fixup for the parent, which clears the information in the
parent's displaced_step_inferior_state.  It worked fine before, because
displaced_step_clear didn't completely clear the displaced_step_inferior_state
structure, so the required information (in this case the gdbarch) was
still available after clearing.

I fixed it by making GDB restore the child's memory before calling the
displaced_step_fixup on the parent.  This way, the data in the
displaced_step_inferior_state structure is still valid when we use it for the
child.  This is the error you would get in
gdb.base/step-over-syscall.exp without this fix:

    /home/smarchi/src/binutils-gdb/gdb/gdbarch.c:3911: internal-error: ULONGEST gdbarch_max_insn_length(gdbarch*): Assertion `gdbarch != NULL' failed.

gdb/ChangeLog:

	* infrun.c (get_displaced_step_closure_by_addr): Adjust to
	std::unique_ptr.
	(displaced_step_clear): Rename to...
	(displaced_step_reset): ... this.  Just call displaced->reset ().
	(displaced_step_clear_cleanup): Rename to...
	(displaced_step_reset_cleanup): ... this.
	(displaced_step_prepare_throw): Adjust to std::unique_ptr.
	(displaced_step_fixup): Likewise.
	(resume_1): Likewise.
	(handle_inferior_event): Restore child's memory before calling
	displaced_step_fixup on the parent.
	* infrun.h (displaced_step_inferior_state) <reset>: Adjust
	to std::unique_ptr.
	<step_closure>: Change type to std::unique_ptr.
2020-02-14 15:11:58 -05:00
Simon Marchi 5f661e0397 gnulib: import count-one-bits module and use it
For a fix I intend to submit, I would need a function that counts the
number of set bits in a word.  There is  __builtin_popcount that is
supported by gcc and clang, but there is also a gnulib module that wraps
that and provides a fallback for other compilers, so I think it would be
good to use it.

I also noticed that there is a bitcount function in arch/arm.c, so I
thought that as a first step I would replace that one with the gnulib
count-one-bits module.  This is what this patch does.

The gnulib module provides multiple functions, with various parameter
length (unsigned int, unsigned long int, unsigned long long int), I
chose the one that made sense for each call site based on the argument
type.

gnulib/ChangeLog:

	* update-gnulib.sh (IMPORTED_GNULIB_MODULES): Import
	count-one-bits module.
	* configure: Re-generate.
	* aclocal.m4: Re-generate.
	* Makefile.in: Re-generate.
	* import/count-one-bits.c: New file.
	* import/count-one-bits.h: New file.
	* import/Makefile.am: Re-generate.
	* import/Makefile.in: Re-generate.
	* import/m4/gnulib-cache.m4: Re-generate.
	* import/m4/gnulib-comp.m4: Re-generate.
	* import/m4/count-one-bits.m4: New file.

gdb/ChangeLog:

	* arm-tdep.c: Include count-one-bits.h.
	(cleanup_block_store_pc): Use count_one_bits.
	(cleanup_block_load_pc): Use count_one_bits.
	(arm_copy_block_xfer): Use count_one_bits.
	(thumb2_copy_block_xfer): Use count_one_bits.
	(thumb_copy_pop_pc_16bit): Use count_one_bits.
	* arch/arm-get-next-pcs.c: Include count-one-bits.h.
	(thumb_get_next_pcs_raw): Use count_one_bits.
	(arm_get_next_pcs_raw): Use count_one_bits_l.
	* arch/arm.c (bitcount): Remove.
	* arch/arm.h (bitcount): Remove.
2020-02-14 14:41:07 -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
Alok Kumar Sharma f98a845896 Adding myself to gdb/MAINTAINERS
2020-02-13  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>

	* MAINTAINERS (Write After Approval): Adding myself.

Change-Id: I2e6095a63247902f5fe23d58c2df8f995e41cf58
2020-02-13 16:26:11 +05:30
Tom Tromey d1437c0ea6 Remove some dead code from event-loop.c
This removes some dead code from event-loop.c.

This patch is from my old series to merge the gdb and gdbserver event
loops; but since it is just removing dead code, it seemed simple to
commit it separately.

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

	* event-loop.c (event_data, gdb_event, event_handler_func):
	Remove.
2020-02-12 17:16:50 -07: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
Christian Biesinger 7559c21717 Change booleans to bool in ARM's gdbarch_tdep
gdb/ChangeLog:

2020-02-12  Christian Biesinger  <cbiesinger@google.com>

	* arm-tdep.c (arm_gdbarch_init): Update.
	* arm-tdep.h (struct gdbarch_tdep) <have_fpa_registers,
	have_wmmx_registers, have_vfp_pseudos, have_neon_pseudos,
	have_neon, is_m>: Change to bool.
2020-02-12 16:49:08 -06:00
Christian Biesinger aeefc73cb2 Print more information in arm_dump_tdep
I am keeping the (int) casts because a future patch will change the type
to bool.

gdb/ChangeLog:

2020-02-12  Christian Biesinger  <cbiesinger@google.com>

	* arm-tdep.c (arm_dump_tdep): Print more fields of tdep.
2020-02-12 16:28:48 -06: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
Hannes Domani cd5900f33b Cache the Thread Local Base pointer type in the gdbarch
gdb/ChangeLog:

2020-02-12  Hannes Domani  <ssbssa@yahoo.de>

	* windows-tdep.c (struct windows_gdbarch_data): Add tib_ptr_type.
	(windows_get_tlb_type): Use windows_gdbarch_data->tib_ptr_type.
2020-02-12 17:02:35 +01:00
Tom Tromey f056b22b92 Update a comment in psymtab.h
This updates a comment in psymtab.h to reflect the current reality.

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

	* psymtab.h: Update comment.

Change-Id: I438bb5929c3ebd1a4c6e9a902490f2ef63014ab3
2020-02-11 18:11:32 -07:00
Tom Tromey f92ff6b552 Don't allow copying of auto_obstack
Add DISABLE_COPY_AND_ASSIGN to struct auto_obstack, to prevent copying
it.  Copying an auto_obstack would be a bug.

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

	* gdb_obstack.h (struct auto_obstack): Use
	DISABLE_COPY_AND_ASSIGN.

Change-Id: Ic9e5ab20acfcfa61c241fed4d99bbb1caefba3cd
2020-02-11 17:57:46 -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
Christian Biesinger 69ed9b74b6 Remove use of deprecated_add_core_fns in cris_tdep.c
The non-deprecated equivalent is implementing the gdbarch function
iterate_over_regset_sections, this patch does that.

Tested by generating a core file on cris under qemu and comparing
the output of "info registers".

This also fixes this warning when loading cris core files:
  warning: Unexpected size of section `.reg/164' in core file.

gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* cris-tdep.c (cris_supply_gregset): Change signature to match
	what struct regset expects.
	(cris_regset): New struct.
	(fetch_core_registers): Remove.
	(cris_iterate_over_regset_sections): New function.
	(_initialize_cris_tdep): Don't call deprecated_add_core_fns.
	(cris_gdbarch_init): Call set_gdbarch_iterate_over_regset_sections.

Change-Id: Ieef895b5a2fdc797d1a913cd1c0c07563edfe8e7
2020-02-11 10:40:05 -06:00
Christian Biesinger bda874f6d1 Add a comment for the ARM_F{0..7}_REGNUM registers
These are for the obsolete FPA architecture.

gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* arch/arm.h (enum gdb_regnum): Add comment for the FP0..7
	registers.

Change-Id: I6920616318ee637493d4ca12b91fa2ebcd103d76
2020-02-11 10:24:04 -06:00
Christian Biesinger 754e156431 Add missing \n in fprintf
gdb/ChangeLog:

2020-02-11  Christian Biesinger  <cbiesinger@google.com>

	* arm-tdep.c (arm_dump_tdep): Add \n in fprintf.

Change-Id: I0175572436cc7dec29e852c96371f85ea763ba2a
2020-02-11 10:22:33 -06:00
Simon Marchi 898e7f6078 Re-generate gdb/gdbserver/gdbsupport configure scripts
In my previous commit, I did a last minute modification of warning.m4,
but forgot to re-generate the configure scripts, this commit fixes that.

gdb/ChangeLog:

	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdbsupport/ChangeLog:

	* configure: Re-generate.
2020-02-11 10:56:09 -05:00
Simon Marchi 8ddd8e0ed8 Add -Wstrict-null-sentinel to gdbsupport/warning.m4
Commit 85f0dd3ce ("[gdb] Fix -Wstrict-null-sentinel warnings") fixed
some violations of -Wstrict-null-sentinel.  If we want to enforce this
warning, I think we should enable it in our warning.m4 file.

gdbsupport/ChangeLog:

	* warning.m4: Add -Wstrict-null-sentinel.
	* configure: Re-generate.

gdbserver/ChangeLog:

	* configure: Re-generate.

gdb/ChangeLog:

	* configure: Re-generate.
2020-02-11 10:51:49 -05:00
Simon Marchi 58df732b21 Move gdb/warning.m4 to gdbsupport
This file is used by gdbsupport, gdbserver and gdb, so I think it
belongs in gdbsupport.  Move it there and update the references the
various acinclude.m4 files.

gdbsupport/ChangeLog:

	* warning.m4: Move here, from gdb/warning.m4.
	* acinclude.m4: Update warning.m4 path.
	* Makefile.in: Re-generate.

gdbserver/ChangeLog:

	* acinclude.m4: Update warning.m4 path.

gdb/ChangeLog:

	* acinclude: Update warning.m4 path.
	* warning.m4: Move to gdbsupport.
2020-02-11 10:51:43 -05:00
Tom Tromey da5bd37ebc Remove some ui_file_* functions
This removes ui_file_isatty, ui_file_read, ui_file_write,
ui_file_write_async_safe, ui_file_flush, and ui_file_puts, replacing
them with calls to the appropriate method instead.

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

	* remote.c (remote_console_output): Update.
	* printcmd.c (printf_command): Update.
	* event-loop.c (gdb_wait_for_event): Update.
	* linux-nat.c (sigchld_handler): Update.
	* remote-sim.c (gdb_os_write_stdout): Update.
	(gdb_os_flush_stdout): Update.
	(gdb_os_flush_stderr): Update.
	(gdb_os_write_stderr): Update.
	* exceptions.c (print_exception): Update.
	* remote-fileio.c (remote_fileio_func_read): Update.
	(remote_fileio_func_write): Update.
	* tui/tui.c (tui_enable): Update.
	* tui/tui-interp.c (tui_interp::init): Update.
	* utils.c (init_page_info): Update.
	(putchar_unfiltered, fputc_unfiltered): Update.
	(gdb_flush): Update.
	(emit_style_escape): Update.
	(flush_wrap_buffer, fputs_maybe_filtered): Update.
	* ui-file.c (ui_file_isatty, ui_file_read, ui_file_write)
	(ui_file_write_async_safe, ui_file_flush, ui_file_puts): Remove.
	(stderr_file::write): Update.
	(stderr_file::puts): Update.
	* ui-file.h (ui_file_isatty, ui_file_write)
	(ui_file_write_async_safe, ui_file_read, ui_file_flush)
	(ui_file_puts): Don't declare.

Change-Id: I3ca9b36e9107f6adbc41e014f5078b41d6bcec4d
2020-02-11 07:05:28 -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
Hannes Domani 6bafc8451e Use enums for human-readable exception information.
Changes to $_siginfo type to this:

(gdb) pt $_siginfo
type = struct EXCEPTION_RECORD {
    enum ExceptionCode ExceptionCode;
    DWORD ExceptionFlags;
    struct EXCEPTION_RECORD *ExceptionRecord;
    PVOID ExceptionAddress;
    DWORD NumberParameters;
    union {
        ULONG_PTR ExceptionInformation[15];
        struct {...} AccessViolationInformation;
    };
}
(gdb) pt $_siginfo.ExceptionCode
type = enum ExceptionCode {FATAL_APP_EXIT = 1073741845,
    DBG_CONTROL_C = 1073807365, DBG_CONTROL_BREAK = 1073807368,
    DATATYPE_MISALIGNMENT = 2147483650, BREAKPOINT, SINGLE_STEP,
    ACCESS_VIOLATION = 3221225477, IN_PAGE_ERROR,
    ILLEGAL_INSTRUCTION = 3221225501, NONCONTINUABLE_EXCEPTION = 3221225509,
    INVALID_DISPOSITION, ARRAY_BOUNDS_EXCEEDED = 3221225612,
    FLOAT_DENORMAL_OPERAND, FLOAT_DIVIDE_BY_ZERO, FLOAT_INEXACT_RESULT,
    FLOAT_INVALID_OPERATION, FLOAT_OVERFLOW, FLOAT_STACK_CHECK,
    FLOAT_UNDERFLOW, INTEGER_DIVIDE_BY_ZERO, INTEGER_OVERFLOW,
    PRIV_INSTRUCTION, STACK_OVERFLOW = 3221225725, FAST_FAIL = 3221226505}
(gdb) pt $_siginfo.AccessViolationInformation
type = struct {
    enum ViolationType Type;
    PVOID Address;
}
(gdb) pt $_siginfo.AccessViolationInformation.Type
type = enum ViolationType {READ_ACCESS_VIOLATION, WRITE_ACCESS_VIOLATION,
    DATA_EXECUTION_PREVENTION_VIOLATION = 8}

Which makes it easier to understand the reason of the exception:

(gdb) p $_siginfo
$1 = {
  ExceptionCode = ACCESS_VIOLATION,
  ExceptionFlags = 0,
  ExceptionRecord = 0x0,
  ExceptionAddress = 0x401632 <main+18>,
  NumberParameters = 2,
  {
    ExceptionInformation = {1, 291, 0 <repeats 13 times>},
    AccessViolationInformation = {
      Type = WRITE_ACCESS_VIOLATION,
      Address = 0x123
    }
  }
}

gdb/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* windows-tdep.c (struct enum_value_name): New struct.
	(create_enum): New function.
	(windows_get_siginfo_type): Create and use enum types.
2020-02-09 12:15:50 +01:00
Hannes Domani 7928d571c5 Display ExceptionRecord for $_siginfo
Uses the $_siginfo convenience variable to show the last exception.

The type looks like this:

(gdb) pt $_siginfo
type = struct EXCEPTION_RECORD {
    DWORD ExceptionCode;
    DWORD ExceptionFlags;
    struct EXCEPTION_RECORD *ExceptionRecord;
    PVOID ExceptionAddress;
    DWORD NumberParameters;
    ULONG_PTR ExceptionInformation[15];
}

EXCEPTION_RECORD is documented at [1].

Example:

Program received signal SIGSEGV, Segmentation fault.
main () at crasher.c:4
4         *(int*)0x123 = 0;
(gdb) p $_siginfo
$1 = {
  ExceptionCode = 3221225477,
  ExceptionFlags = 0,
  ExceptionRecord = 0x0,
  ExceptionAddress = 0x401632 <main+18>,
  NumberParameters = 2,
  ExceptionInformation = {1, 291, 0 <repeats 13 times>}
}
(gdb) p/x $_siginfo.ExceptionCode
$2 = 0xc0000005
(gdb) p/x $_siginfo.ExceptionInformation[1]
$3 = 0x123

And 0xc0000005 is the value of EXCEPTION_ACCESS_VIOLATION.

[1] https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record

gdb/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* NEWS: Mention $_siginfo support for Windows.
	* windows-nat.c (handle_exception): Set siginfo_er.
	(windows_nat_target::mourn_inferior): Reset siginfo_er.
	(windows_xfer_siginfo): New function.
	(windows_nat_target::xfer_partial): Call windows_xfer_siginfo.
	* windows-tdep.c (struct windows_gdbarch_data): New struct.
	(init_windows_gdbarch_data): New function.
	(get_windows_gdbarch_data): New function.
	(windows_get_siginfo_type): New function.
	(windows_init_abi): Register windows_get_siginfo_type.
	(_initialize_windows_tdep): Register init_windows_gdbarch_data.

gdbserver/ChangeLog:

2020-02-09  Hannes Domani  <ssbssa@yahoo.de>

	* win32-low.c (win32_clear_inferiors): Reset siginfo_er.
	(handle_exception): Set siginfo_er.
	(win32_xfer_siginfo): New function.
2020-02-09 12:14:51 +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