Commit Graph

42424 Commits

Author SHA1 Message Date
John Baldwin 81a24d04df Note support for TLS variables on FreeBSD.
gdb/ChangeLog:

	* NEWS: Mention TLS support for FreeBSD.
2019-03-25 13:23:42 -07:00
Tom Tromey 79e7ae11c7 Clean up some comments in minsyms.c
Philippe pointed out that some comments in minsyms.c still referred to
obstack allocation.  This patch fixes these up.

In most cases here, my view is that the comments were more misleading
than helpful.  So, I've generally removed text.

gdb/ChangeLog
2019-03-25  Tom Tromey  <tromey@adacore.com>

	* minsyms.c (BUNCH_SIZE): Update comment.
	(~minimal_symbol_reader): Remove old comment.
	(compact_minimal_symbols): Update comment.
	(minimal_symbol_reader::install): Remove old comment.  Update
	other comments.
2019-03-25 13:45:57 -06:00
Alan Hayward d45963c2b2 Fix s390 build
Add missing include.

2019-03-25  Alan Hayward  <alan.hayward@arm.com>

        * s390-linux-nat.c: Add include.
2019-03-25 17:08:14 +00:00
Alan Hayward 0f83012ea0 Add linux_get_hwcap
Tidy up calls to read HWCAP (and HWCAP2) by adding common functions,
removing the PPC and AArch64 specific versions.

The only function difference is in aarch64_linux_core_read_description - if
the hwcap read fails it now return a valid description instead of nullptr.

gdb/ChangeLog:

2019-03-25  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
	Call linux_get_hwcap.
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description):
	Likewise.
	(aarch64_linux_get_hwcap): Remove function.
	* aarch64-linux-tdep.h (aarch64_linux_get_hwcap): Remove
	declaration.
	* arm-linux-nat.c (arm_linux_nat_target::read_description):Call
	linux_get_hwcap.
	* arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
	* linux-tdep.c (linux_get_hwcap): Add function.
	(linux_get_hwcap2): Likewise.
	* linux-tdep.h (linux_get_hwcap): Add declaration.
	(linux_get_hwcap2): Likewise.
	* ppc-linux-nat.c (ppc_linux_get_hwcap): Remove function.
	(ppc_linux_get_hwcap2): Likewise.
	(ppc_linux_nat_target::region_ok_for_hw_watchpoint): Call
	linux_get_hwcap.
	(ppc_linux_nat_target::insert_watchpoint): Likewise.
	(ppc_linux_nat_target::watchpoint_addr_within_range): Likewise.
	(ppc_linux_nat_target::read_description): Likewise.
	* ppc-linux-tdep.c (ppc_linux_core_read_description): Likewise.
	* s390-linux-nat.c: Likewise.
	* s390-linux-tdep.c (s390_core_read_description): Likewise.
2019-03-25 16:50:38 +00:00
Pedro Alves 9a93502fa8 Fix testsuite hangs when gdb_test_multiple body errors out
This commit fixes a regression in the testsuite itself, triggered by
errors being raised from within gdb_test_multiple, originally reported
by Pedro Franco de Carvalho's at
<https://sourceware.org/ml/gdb-patches/2019-03/msg00160.html>.  Parts
of the commit message are based on his report.

This started happening due to a commit that was introduced recently,
and it can cause the testsuite to hang.

The commit that triggers this is:

 fe1a5cad30
 [gdb/testsuite] Log wait status on process no longer exists error

That commit introduces a new "eof" block in gdb_test_multiple.  That
is not incorrect itself, but dejagnu's remote_expect is picking that
block as the "default" action when an error is raised from within the
commands inside a call to gdb_test_multiple:

  # remote_expect works basically the same as standard expect, but it
  # also takes care of getting the file descriptor from the specified
  # host and also calling the timeout/eof/default section if there is an
  # error on the expect call.
  #
  proc remote_expect { board timeout args } {

I find that "feature" surprising, and I don't really know why it
exists, but this means that the eof section that remote_expect picks
as the error block can be executed even when there was no actual eof
and the GDB process is still running, so the wait introduced in the
commit that tries to get the exit status of GDB hangs forever, while
GDB itself waits for input.

This only happens when there are internal testsuite errors (not
testcase failures).  This can be reproduced easily with a testcase
such as:

  gdb_start
  gdb_test_multiple "show version" "show version" {
    -re ".*" {
       error "forced error"
    }
  }

I think that working around this in GDB is useful so that the
testsuite doesn't hang in these cases.

Adding an empty "default" block at the end of the expect body in
gdb_test_multiple doesn't work, because dejagnu gives preference to
"eof" blocks:

	    if { $x eq "eof" } {
		set save_next 1
	    } elseif { $x eq "default" || $x eq "timeout" } {
		if { $error_sect eq "" } {
		    set save_next 1
		}
	    }

And we do have "eof" blocks.  So we need to make sure that the last
"eof" block is safe to use as the default error block.  It's also
pedantically incorrect to print

 "ERROR: Process no longer exists"

which is what we'd get if the last eof block we have was selected
(more below on this).

So this commit solves this by appending an "eof" with an empty
spawn_id list, so that it won't ever match.

Now, why is the first "eof" block selected today as the error block,
instead of the last one?

The reason is that remote_expect, while parsing the body to select the
default block to execute after an error, is affected by the comments
in the body (since they are also parsed).

If this comment in gdb_test_multiple

 # patterns below apply to any spawn id specified.

is changed to

 # The patterns below apply to any spawn id specified.

then the second eof block is selected and there is no hang.

Any comment at that same place with an even number of tokens also
works.

This is IMO a coincidence caused by how comments work in TCL.
Comments should only appear in places where a command can appear.  And
here, remote_expect is parsing a list of options, not commands, so
it's not unreasonable to not parse comments, similarly to how this:

  set a_list {
     an_element
     # another_element
  }

results in a list with three elements, not one element.

The fact that comments with an even number of tokens work is just a
coincidence of how remote_expect's little state machine is
implemented.

I thought we could solve this by stripping out comment lines in
gdb_expect, but I didn't find an easy way to do that.  Particularly, a
couple naive approaches I tried run into complications.  For example,
we have gdb_test calls with regular expressions that include sequences
like "\r\n#", and by the time we get to gdb_expect, the \r\n have
already been expanded to a real newline, so just splitting the whole
body at newline boundaries, looking for lines that start with #
results in incorrectly stripping out half of the gdb_text regexp.  I
think it's better (at least in this commit), to move the comments out
of the list, because it's much simpler and risk free.

gdb/testsuite/ChangeLog:
2019-03-25  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_test_multiple): Split appends to $code and
	move comments outside list.  Append '-i "" eof' section.
2019-03-25 13:26:23 +00:00
Tom Tromey 6640a367bf Remove null_block_symbol
This removes null_block_symbol.  It seemed simpler to me to change
initializations and returns to use value initialization rather than
null_block_symbol.  This also fixes up a few spots where
initialization was done piecemeal.

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (standard_lookup): Simplify initialization.
	(ada_lookup_symbol_nonlocal): Simplify return.
	* solib-spu.c (spu_lookup_lib_symbol): Simplify return.
	* solib-darwin.c (darwin_lookup_lib_symbol): Simplify return.
	* solib-svr4.c (elf_lookup_lib_symbol): Simplify return.
	* rust-lang.c (rust_lookup_symbol_nonlocal): Simplify
	initialization.
	* solib.c (solib_global_lookup): Simplify.
	* symtab.c (null_block_symbol): Remove.
	(symbol_cache_lookup): Simplify returns.
	(lookup_language_this): Simplify returns.
	(lookup_symbol_aux): Simplify return.
	(lookup_local_symbol): Simplify returns.
	(lookup_global_symbol_from_objfile): Simplify return.
	(lookup_symbol_in_objfile_symtabs)
	(lookup_symbol_in_objfile_from_linkage_name): Simplify return.
	(lookup_symbol_via_quick_fns, lookup_symbol_in_static_block)
	(lookup_static_symbol, lookup_global_symbol): Simplify return.
	* cp-namespace.c (cp_lookup_bare_symbol)
	(cp_search_static_and_baseclasses, cp_lookup_symbol_via_imports)
	(cp_lookup_symbol_via_all_imports, cp_lookup_nested_symbol_1)
	(cp_lookup_nested_symbol): Don't use null_block_symbol.
	(cp_lookup_symbol_via_imports): Simplify initialization.
	(find_symbol_in_baseclass): Likewise.
	* symtab.h (null_block_symbol): Remove.
	* d-namespace.c (d_lookup_symbol): Don't use null_block_symbol.
	(d_lookup_nested_symbol, d_lookup_symbol_imports)
	(d_lookup_symbol_module): Likewise.
	(find_symbol_in_baseclass): Simplify initialization.
2019-03-24 23:32:09 -06:00
Tom Tromey a930ebcdf9 Don't include symtab.h from expression.h
expression.h includes symtab.h, but apparently only for the
declaration of struct block.  This patch changes it to foward-declare
the structure, and remove the include.

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* expression.h: Don't include symtab.h.
	(struct block): Forward declare.
2019-03-24 23:32:09 -06:00
Tom Tromey 582942f456 More block constification
I noticed that there are still many places referring to non-const
blocks.  This constifies all the remaining ones that I found that
could be constified.

In a few spots, this search found unused variables or fields.  I
removed these.  I've also removed some unnecessary casts to
"struct block *".

gdb/ChangeLog
2019-03-24  Tom Tromey  <tom@tromey.com>

	* c-exp.y (typebase): Remove casts.
	* gdbtypes.c (lookup_unsigned_typename, )
	(lookup_signed_typename): Remove cast.
	* eval.c (parse_to_comma_and_eval): Remove cast.
	* parse.c (write_dollar_variable): Remove cast.
	* block.h (struct block) <superblock>: Now const.
	* symfile-debug.c (debug_qf_map_matching_symbols): Update.
	* psymtab.c (psym_map_matching_symbols): Make "block" const.
	(map_block): Make "block" const.
	* symfile.h (struct quick_symbol_functions)
	<map_matching_symbols>: Constify block argument to "callback".
	* symtab.c (basic_lookup_transparent_type_quick): Make "block"
	const.
	(find_pc_sect_compunit_symtab): Make "b" const.
	(find_symbol_at_address): Likewise.
	(search_symbols): Likewise.
	* dwarf2read.c (dw2_lookup_symbol): Make "block" const.
	(dw2_debug_names_lookup_symbol): Likewise.
	(dw2_map_matching_symbols): Update.
	* p-valprint.c (pascal_val_print): Remove "block".
	* ada-lang.c (ada_add_global_exceptions): Make "b" const.
	(aux_add_nonlocal_symbols): Make "block" const.
	(resolve_subexp): Remove cast.
	* linespec.c (iterate_over_all_matching_symtabs): Make "block"
	const.
	(iterate_over_file_blocks): Likewise.
	* f-exp.y (%union) <bval>: Remove.
	* coffread.c (patch_opaque_types): Make "b" const.
	* spu-tdep.c (spu_catch_start): Make "block" const.
	* c-valprint.c (print_unpacked_pointer): Remove "block".
	* symmisc.c (dump_symtab_1): Make "b" const.
	(block_depth): Make "block" const.
	* d-exp.y (%union) <bval>: Remove.
	* cp-support.h (cp_lookup_rtti_type): Update.
	* cp-support.c (cp_lookup_rtti_type): Make "block" const.
	* psymtab.c (psym_lookup_symbol): Make "block" const.
	(maintenance_check_psymtabs): Make "b" const.
	* python/py-framefilter.c (extract_sym): Make "sym_block" const.
	(enumerate_locals, enumerate_args): Update.
	* python/py-symtab.c (stpy_global_block): Make "block" const.
	(stpy_static_block): Likewise.
	* inline-frame.c (block_starting_point_at): Make "new_block"
	const.
	* block.c (find_block_in_blockvector): Make return type const.
	(blockvector_for_pc_sect): Make "b" const.
	(find_block_in_blockvector): Make "b" const.
2019-03-24 23:32:08 -06:00
Philippe Waroquiers 5783e150b2 (re-)fix the regcache leaks when detaching from an executable.
Commit 799efbe8e0 was supposed to fix
the below leak.  However, for this fix to work, it is critical to
save the ptid before detach.

This commit (pushed as OBVIOUS, as the change was already reviewed/approved)
saves the ptid before the detach, as in the original reviewed patch
(see https://sourceware.org/ml/gdb-patches/2019-02/msg00263.html).

Re-tested on debian/amd64, natively and under valgrind.

==7426== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,872 of 3,020
==7426==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==7426==    by 0x5BD1E1: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==7426==    by 0x5BD39A: get_thread_regcache (regcache.c:366)
==7426==    by 0x5BD39A: get_current_regcache() (regcache.c:372)
==7426==    by 0x4B1EB4: get_current_frame() (frame.c:1588)
...
2019-03-24 13:56:46 +01:00
Tom Tromey 7ad417dd21 Have parser reset the innermost block tracker
I ran across a comment in symfile.c today:

  /* Clear globals which might have pointed into a removed objfile.
     FIXME: It's not clear which of these are supposed to persist
     between expressions and which ought to be reset each time.  */

It seems to me that this can be clarified: the parser entry points
ought to reset the innermost block tracker (and the expression context
block), and these should not be considered valid for code to use at
arbitrary times -- only immediately after an expression has been
parsed.

This patch implements this idea.  This could be further improved by
removing the parser globals and changing the parser functions to
return this information, but I have not done this.

Tested by the buildbot.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* varobj.c (varobj_create): Update.
	* symfile.c (clear_symtab_users): Don't reset innermost_block.
	* printcmd.c (display_command, do_one_display): Don't reset
	innermost_block.
	* parser-defs.h (enum innermost_block_tracker_type): Move to
	expression.h.
	(innermost_block): Update comment.
	* parse.c (parse_exp_1): Add tracker_types parameter.
	(parse_exp_in_context): Rename from parse_exp_in_context_1.  Add
	tracker_types parameter.  Reset innermost_block.
	(parse_exp_in_context): Remove.
	(parse_expression_for_completion): Update.
	* objfiles.c (~objfile): Don't reset expression_context_block or
	innermost_block.
	* expression.h (enum innermost_block_tracker_type): Move from
	parser-defs.h.
	(parse_exp_1): Add tracker_types parameter.
	* breakpoint.c (set_breakpoint_condition, watch_command_1): Don't
	reset innermost_block.
2019-03-23 10:59:10 -06:00
Tom Tromey b366c208ee Include bcache.h from objfiles.h
objfiles.h needs "struct bcache" to be complete, so it should include
bcache.h.  This patch implements this.

Tested by rebuilding.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* objfiles.h: Include bcache.h.
2019-03-23 10:50:27 -06:00
Tom Tromey 9bb9b2f9d6 Use scoped_restore_current_language in two places
I found a couple of spots that manually saved and restored the current
language.  This patch changes them to use
scoped_restore_current_language.

Tested by the buildbot.

gdb/ChangeLog
2019-03-23  Tom Tromey  <tom@tromey.com>

	* linespec.c (get_current_search_block): Use
	scoped_restore_current_language.
	* symmisc.c (dump_symtab): Use scoped_restore_current_language.
2019-03-23 10:18:15 -06:00
Alan Hayward 59c283728f AArch64: Read pauth section from core files
gdb/ChangeLog:

	* aarch64-linux-tdep.c
	(aarch64_linux_iterate_over_regset_sections): Check for pauth
	section.
	* aarch64-linux-tdep.h (AARCH64_LINUX_SIZEOF_PAUTH): New define.
2019-03-22 10:43:17 +00:00
Alan Hayward 17e116a7d1 AArch64: Prologue scan unwinder support for signed return addresses
Pauth address signing is enabled at binary compile time.  When enabled the
return addresses for functions may be mangled.  This patch adds functionality
to restore the original address for use in the prologue scan unwinder.

In the prologue analyzer, check for PACIASP/PACIBSP (enable address mangling)
and AUTIASP/AUTIBSP (disable address mangling).

When unwinding the PC from the prologue, unmask the register if required.

Add a test case to the prologue tests.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_analyze_prologue): Check for pauth
	instructions.
	(aarch64_analyze_prologue_test): Add PACIASP test.
	(aarch64_prologue_prev_register): Unmask PC value.
2019-03-22 10:41:15 +00:00
Alan Hayward 11e1b75f06 AArch64: DWARF unwinder support for signed return addresses
Pauth address signing is enabled at binary compile time.  When enabled the
return addresses for functions may be mangled.  This patch adds functionality
to restore the original address for use in the DWARF unwinder.

DW_CFA_AARCH64_negate_ra_state in a binary indicates the toggling of address
signing between enabled and disabled.  Ensure the state is stored in the DWARF
register ra_state.

Ensure the pauth DWARF registers are initialised.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_frame_unmask_address): New function.
	(aarch64_dwarf2_prev_register): Unmask PC value.
	(aarch64_dwarf2_frame_init_reg): Init pauth registers.
	(aarch64_execute_dwarf_cfa_vendor_op): Check for
	DW_CFA_AARCH64_negate_ra_state.
	(aarch64_gdbarch_init): Add aarch64_execute_dwarf_cfa_vendor_op.
2019-03-22 10:39:11 +00:00
Alan Hayward 34dcc7cf95 AArch64: Add pauth DWARF registers
Map the pauth registers to DWARF.

Add a new pseudo register ra_state and also map this to DWARF.  This register
is hidden from the user - prevent it from being read or written to.  It will
be used for the unmangling of addresses.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_dwarf_reg_to_regnum): Check for pauth
	registers.
	(aarch64_pseudo_register_name): Likewise.
	(aarch64_pseudo_register_type): Likewise.
	(aarch64_pseudo_register_reggroup_p): Likewise.
	(aarch64_gdbarch_init): Add pauth registers.
	* aarch64-tdep.h (AARCH64_DWARF_PAUTH_RA_STATE): New define.
	(AARCH64_DWARF_PAUTH_DMASK): Likewise.
	(AARCH64_DWARF_PAUTH_CMASK): Likewise.
	(struct gdbarch_tdep): Add regnum for ra_state.
2019-03-22 10:37:46 +00:00
Alan Hayward 1ef53e6b83 AArch64: gdbserver: read pauth registers
Add the pauth registers to the regset lists.

Add a new regset type OPTIONAL_REGS which allows for the regset read to fail.
Once the read fails, it will not be checked again.  This allows targets with
optional features to keep a single static regset_info structure.

gdb/ChangeLog:

	* arch/aarch64.h (AARCH64_PAUTH_REGS_SIZE): New define.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (aarch64_store_pauthregset): New function.
	* linux-low.c (regsets_store_inferior_registers): Allow optional reads
	to fail.
	* linux-low.h (enum regset_type): Add OPTIONAL_REGS.
2019-03-22 10:34:09 +00:00
Alan Hayward 76bed0fd94 AArch64: Read pauth registers
Initialise the pauth registers when creating a target description, and store
the regnum of the first pauth register.

Use ptrace to read the registers in the pauth feature.

Do not allow the registers to be written.

gdb/ChangeLog:

	* aarch64-linux-nat.c (fetch_pauth_masks_from_thread): New
	function.
	(aarch64_linux_nat_target::fetch_registers): Read pauth registers.
	* aarch64-tdep.c (aarch64_cannot_store_register): New function.
	(aarch64_gdbarch_init): Add puth registers.
	* aarch64-tdep.h (struct gdbarch_tdep): Add pauth features.
	* arch/aarch64.h (AARCH64_PAUTH_DMASK_REGNUM): New define.
	(AARCH64_PAUTH_CMASK_REGNUM): Likewise.
2019-03-22 10:31:02 +00:00
Alan Hayward ee4fbcfa26 AArch64: Use HWCAP to detect pauth feature
Add aarch64_get_hwcap functions for reading the HWCAP.
From this extract the PACA value and use this to enable pauth.

gdb/ChangeLog:

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::read_description): Read PACA hwcap.
	* aarch64-linux-tdep.c
	(aarch64_linux_core_read_description): Likewise.
	(aarch64_linux_get_hwcap): New function.
	* aarch64-linux-tdep.h (AARCH64_HWCAP_PACA): New define.
	(aarch64_linux_get_hwcap): New declaration.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-low.c (AARCH64_HWCAP_PACA): New define.
	(aarch64_get_hwcap): New function.
	(aarch64_arch_setup): Read APIA hwcap.
2019-03-22 10:10:22 +00:00
Alan Hayward 6dc0ebde59 AArch64: Add pointer authentication feature
Pointer Authentication is a new feature in AArch64 v8.3-a. When enabled in
the compiler, function return addresses will be mangled by the kernel.

Add register description xml and wire up to aarch64_linux_read_description.
This description includes the two pauth user registers.

Nothing yet uses the feature - that is added in later patches.

gdb/ChangeLog:

	* aarch64-linux-nat.c
	(aarch64_linux_nat_target::read_description): Add pauth param.
	* aarch64-linux-tdep.c
	(aarch64_linux_core_read_description): Likewise.
	* aarch64-tdep.c (struct target_desc): Add in pauth.
	(aarch64_read_description): Add pauth param.
	(aarch64_gdbarch_init): Likewise.
	* aarch64-tdep.h (aarch64_read_description): Likewise.
	* arch/aarch64.c (aarch64_create_target_description): Likewise.
	* arch/aarch64.h (aarch64_create_target_description): Likewise.
	* features/Makefile: Add new files.
	* features/aarch64-pauth.c: New file.
	* features/aarch64-pauth.xml: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo: Describe pauth feature.

gdb/gdbserver/ChangeLog:

	* linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
	(initialize_low_tracepoint): Likewise.
	* linux-aarch64-low.c (aarch64_arch_setup): Likewise.
	* linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
	* linux-aarch64-tdesc.c (struct target_desc): Likewise.
	(aarch64_linux_read_description): Likewise.
	* linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.
2019-03-22 09:58:42 +00:00
Alan Hayward 968aa7ae38 Testsuite: Ensure pie is disabled on some tests
Recent versions of Ubuntu and Debian default GCC to enable pie.

In dump.exp, pie will causes addresses to be out of range for IHEX.

In break-interp.exp, pie is explicitly set for some tests and assumed
to be disabled for the remainder.

Ensure pie is disabled for these tests when required.

In addition, add a pie option to gdb_compile to match the nopie option
and simplify use.

gdb/testsuite/ChangeLog:

	* README: Add pie options.
	* gdb.base/break-interp.exp: Ensure pie is disabled.
	* gdb.base/dump.exp: Likewise.
	* lib/gdb.exp (gdb_compile): Add pie option.
2019-03-22 09:43:35 +00:00
Tom Tromey 48869a5f9c Use @defvar to document gdb.pretty_printers
While referencing the manual, I noticed that gdb.pretty_printers
wasn't documented using @defvar.  This made it more difficult to find
in the info pages.  This patch adds the @defvar and also an
introductory paragraph in that node.

gdb/doc/ChangeLog
2019-03-20  Tom Tromey  <tromey@adacore.com>

	* python.texi (Selecting Pretty-Printers): Use @defvar for
	gdb.pretty_printers.
2019-03-20 11:28:44 -06:00
Tom Tromey 595915c1c1 Merge handle_inferior_event and handle_inferior_event_1
I noticed that handle_inferior_event is just a small wrapper that
frees the value chain.  This patch replaces it with a
scoped_value_mark, reducing the number of lines of code here.

Regression tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-20  Tom Tromey  <tromey@adacore.com>

	* infrun.c (handle_inferior_event): Rename from
	handle_inferior_event_1.  Create a scoped_value_mark.
	(handle_inferior_event): Remove.
2019-03-20 11:09:10 -06:00
Tom Tromey 4c7d57e72e Don't show "display"s twice in MI
If you run "gdb -i=mi2" and set a "display", then when "next"ing the
displays will be shown twice:

    ~"1: x = 23\n"
    ~"7\t  printf(\"%d\\n\", x);\n"
    ~"1: x = 23\n"
    *stopped,reason="end-stepping-range",frame={addr="0x0000000000400565",func="main",args=[],file="q.c",fullname="/tmp/q.c",line="7"},thread-id="1",stopped-threads="all",core="1"

The immediate cause of this is this code in mi_on_normal_stop_1:

      print_stop_event (mi_uiout);

      console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
      if (should_print_stop_to_console (console_interp, tp))
	print_stop_event (mi->cli_uiout);

... which obviously prints the stop twice.

However, I think the first call to print_stop_event is intended just
to emit the MI *stopped notification, which explains why the source
line does not show up two times.

This patch fixes the bug by changing print_stop_event to only call
do_displays for non-MI-like ui-outs.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-19  Tom Tromey  <tromey@adacore.com>

	* mi/mi-interp.c (mi_on_normal_stop_1): Only show displays once.
	* infrun.h (print_stop_event): Add "displays" parameter.
	* infrun.c (print_stop_event): Add "displays" parameter.

gdb/testsuite/ChangeLog
2019-03-19  Tom Tromey  <tromey@adacore.com>

	* gdb.mi/mi2-cli-display.c: New file.
	* gdb.mi/mi2-cli-display.exp: New file.
2019-03-19 12:16:48 -06:00
Pedro Alves cb24623460 Add comments describing tui_ui_out and its fields, cleanup a bit
This commit add comments describing tui_ui_out and its fields, and
cleans up the code a little bit.

Also switch to using in-class initialization so that the initial
values can be seen alongside the comments.

I see no reason for initializing m_line as -1 instead of 0, since all
the checks in the .c file are of the form "> 0".  AFAICS there's no
practical difference between -1 and 0.  So it seems simpler to
initialize it as 0.

There's a bit of redundancy in tui_ui_out::do_field_string, which is
fixed by this commit.

gdb/ChangeLog:
2019-03-19  Pedro Alves  <palves@redhat.com>

	* tui/tui-out.c (tui_ui_out::do_field_string): Simplify.
	(tui_ui_out::do_text): Add comments.  Reset M_LINE to 0 instead of
	to -1.  Fix TABs vs spaces.
	(tui_ui_out::tui_ui_out): Don't initialize fields here.
	* tui/tui-out.h (tui_ui_out) Add intro comments.
	<m_line, m_start_of_line>: In-class initialize, and add describing
	comment.
2019-03-19 18:08:27 +00:00
Alan Hayward 3a0e45b2f1 Fix Arm build error
The following commit broke the build for Arm:
d3a70e03cf
Change iterate_over_lwps to take a gdb::function_view

Correct the changes made to arm_linux_insert_hw_breakpoint1 and make
similar changes to arm_linux_remove_hw_breakpoint1.

2019-03-18  Alan Hayward  <alan.hayward@arm.com>

	* arm-linux-nat.c (arm_linux_insert_hw_breakpoint1): Fix
	variable names.
	(arm_linux_remove_hw_breakpoint1): Use a gdb::function_view.
2019-03-19 09:59:55 +00:00
Pedro Alves 5371b8502a Fix first time you type UP or DOWN in TUI's command window
The first time you type UP or DOWN arrow in the command window, GDB
should scroll the source window, but instead it displays the line
number and the file name in the command window(?).

What happens there is that the first time we call
tui_ui_out::do_field_int, it doesn't initialize m_line, because
m_start_of_line is -1, as set by the constructor; and then the
following call to tui_ui_out::do_field_string falls back to
cli_ui_out::do_field_string because m_line is zero.

The problem is caused by a typo in the C++ification of tui_ui_out,
commit 112e8700a6, where m_line and m_start_of_line's initial values
were swapped from what they used to be:

 -struct ui_out *
 -tui_out_new (struct ui_file *stream)
 +tui_ui_out::tui_ui_out (ui_file *stream)
 +: cli_ui_out (stream, 0),
 +  m_line (0),
 +  m_start_of_line (-1)
  {
 -
 -  /* Initialize our fields.  */
 -  data->line = -1;
 -  data->start_of_line = 0;

This commit fixes it.

gdb/ChangeLog:
2019-03-18  Pedro Alves  <palves@redhat.com>
	    Eli Zaretskii <eliz@gnu.org>

	* tui/tui-out.c (tui_ui_out::tui_ui_out): Fix initialization of
	m_line and m_start_of_line.
2019-03-18 18:32:42 +00:00
Eli Zaretskii b17c4cd078 Fix gdb/TUI behavior in response to [Enter] keypress
gdb/ChangeLog:
2019-03-18  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-io.c (gdb_wgetch): Don't echo CR.
	(tui_getc): When gdb_wgetch returns a CR, behave the same as when
	it returns a newline.  This fixes a regression in TUI mode, whereby
	the next line is output on the same screen line as the user input.
2019-03-18 20:04:40 +02:00
Tom Tromey 4bd56d18cc Fix regression caused by minimal symbol changes
The earlier patch to change minimal symbol allocations to use xmalloc
erroneously left a call to obstack_blank in
minimal_symbol_reader::install.  Because obstack_blank does not finish
the object allocation on an obstack, this in turn could cause invalid
memory reads in some situations.

This patch fixes the problem by removing the call.  Tested on x86-64
Fedora 29; also verified with valgrind.

gdb/ChangeLog
2019-03-18  Tom Tromey  <tromey@adacore.com>

	* minsyms.c (minimal_symbol_reader::install): Remove call to
	obstack_blank.
2019-03-18 09:56:27 -06:00
Pedro Alves 55c10aca2e Improve/fix the TUI's current source line highlight
With styling enabled, I think the way we display the TUI's
highlighted/current line is very ugly and distracting.  The problem in
my view is that we reverse foreground/background in colored text as
well, leading to rainbow of background colors.

This patch changes that to something that I find much more sensible --
only reverse the default foreground/background colors, leave styled
text colors alone.  If the foreground color is not the default
(because the text was styled), leave the foreground color as is.  If
e.g., the terminal is fg=BLACK, and bg=WHITE, and the style wants to
print text in RED, reverse the background color (print in BLACK), but
still print the text in RED.

Note: The new ui_file_style::set_fg method isn't called set_foreground
instead, because set_foreground is a macro in /usr/lib/term.h (ncurses).

gdb/ChangeLog:
2019-03-18  Pedro Alves  <palves@redhat.com>

	* tui/tui-io.c (reverse_mode_p, reverse_save_bg, reverse_save_fg):
	New globals.
	(apply_style): New, factored out from ...
	(apply_ansi_escape): ... this.  Handle reverse video mode.
	(tui_set_reverse_mode): New function.
	* tui/tui-io.h (tui_set_reverse_mode): New declaration.
	* tui/tui-winsource.c (tui_show_source_line): Use
	tui_set_reverse_mode instead of setting A_STANDOUT.
	* ui-style.h (struct ui_file_style) <set_reverse, set_fg, set_bg>:
	New setter methods.
2019-03-18 14:26:00 +00:00
Hannes Domani 647bb750c2 Fix scrolling right in the TUI
This commit fixes two issues in scrolling right in the TUI:

#1 - Scrolling right with the arrow keys, the first keypress doesn't
do anything.  The problem is that copy_source_line() checks if
(column < first_col), and because of the ++column directly before, it
basically starts with 1 instead of 0.

#2 - Scrolling right handles TABS and escaped characters as single
characters, which just looks weird.  The problem is that there's a
spot that misses handling TABS.

gdb/ChangeLog:
2019-03-18  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-source.c (copy_source_line): Fix handling of 'column'.
	Handle tabs.
2019-03-18 14:25:59 +00:00
Tom Tromey bff8c71fd8 Fix Ada "ptype" bug with array types
Using ptype on an array type in Ada can sometimes show an incorrect
high bound.  This happens because ada_evaluate_subexp will create an
array with an incorrect upper bound in the EVAL_AVOID_SIDE_EFFECTS
case.

This patch fixes the problem by arranging to always create such an
array with valid bounds.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-03-18  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (empty_array): Add "high" parameter.
	(ada_evaluate_subexp): Update.

gdb/testsuite/ChangeLog
2019-03-18  Joel Brobecker  <brobecker@adacore.com>
	    Tom Tromey  <tromey@adacore.com>

	* gdb.ada/ptype_array/pck.adb: New file.
	* gdb.ada/ptype_array/pck.ads: New file.
	* gdb.ada/ptype_array/foo.adb: New file.
	* gdb.ada/ptype_array.exp: New file.
2019-03-18 06:45:16 -06:00
Sergei Trofimovich 58785d9888 gdb: unconditionally define _initialize_string_view_selftests
The build failure was noticed by Helmut Jarausch in
https://bugs.gentoo.org/680232:
    $ ./configure CXXFLAGS='-std=c++17 -Os'
    ...
      CXXLD  gdb
    ld: init.o: in function `initialize_all_files()':
    init.c:(.text+0x113): undefined reference to `_initialize_string_view_selftests()'

It happens because '_initialize_string_view_selftests()' is
conditionally defined based on C++ default.

The change defines '_initialize_string_view_selftests()'
unconditionally and leaves implementation a no-op on c++17
compilers.

gdb/ChangeLog:
2019-03-17  Sergei Trofimovich <siarheit@google.com>

	* unittests/string_view-selftests.c: Define
	_initialize_string_view_selftests unconditionally.
2019-03-18 00:01:13 -04:00
Владимир Мартьянов d4cbef22ba Remove unused variable from windows_make_so
There is unused variable text_vma in function windows_make_so. This
leads to build error on Windows using Cygwin.

gdb/ChangeLog:
2019-03-17  Vladimir Martyanov  <vilgeforce@gmail.com>

    PR gdb/24350
    * windows-nat.c (windows_make_so): Remove unused text_vma variable.
2019-03-17 14:48:59 -04:00
Владимир Мартьянов fce4c07161 Fix wrong format specification in display_selector()
There are a wrong format strings in function display_selector() in
file windows-nat.c. This leads to build error using Cygwin on Windows.
LDT_ENTRY.HighWord is a DWORD, which is unsigned long int, so the
format specification should be for long int, not simply int.

gdb/ChangeLog:
2019-03-17  Vladimir Martyanov  <vilgeforce@gmail.com>

    PR gdb/24351
    * windows-nat.c (display_selector): Format specifications fixed
2019-03-17 14:41:12 -04:00
Eli Zaretskii f7f0a12390 Fix redisplay of the current line in GDB TUI mode
Without this change, when the current line is longer than the source
window width, redisplaying that line overwrites the window frame and
also portions of the next line.

gdb/ChangeLog:
2019-03-17  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-winsource.c (tui_set_is_exec_point_at): Call
	tui_refill_source_window instead of tui_refresh_win, to update the
	current execution line.  This fixes redisplay of the current line
	when stepping through very long lines with "next" or "step".
2019-03-17 18:00:34 +02:00
Eli Zaretskii ab42892fb7 Fix vertical scrolling of TUI source window
gdb/ChangeLog:
2019-03-16  Eli Zaretskii  <eliz@gnu.org>

	* source-cache.c (source_cache::get_source_lines): Call
	find_source_lines to initialize s->nlines.  This fixes vertical
	scrolling of TUI source window when the DOWN arrow is pressed.
2019-03-16 19:53:46 +02:00
Philippe Waroquiers 8d8c087f34 OBVIOUS: fix several occurrences of 'This options has' to 'This option has' 2019-03-16 16:57:25 +01:00
Eli Zaretskii 798e1c302a Revert "Use wclrtoeol in tui_show_source_line"
gdb/ChangeLog:
2019-03-16  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-winsource.c (tui_show_source_line): Revert "Use
	wclrtoeol in tui_show_source_line".  This reverts changes made in
	commit 4a3045920b.
2019-03-16 14:13:43 +02:00
Tom Tromey eefba3da27 Change minimal_symbol inheritance
This changes struct minimal_symbol to inherit from general_symbol_info
and updates various macros to cope.

Because MSYMBOL_SET_LANGUAGE and MSYMBOL_SET_NAMES were only used from
a single spot, this patch removes them in favor of simply inlining
their definitions.  I consider this to be somewhat cleaner, not least
because the "phony polymorphism" provided by such macros is not useful
in practice.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* symtab.h (struct minimal_symbol): Derive from
	general_symbol_info.
	(MSYMBOL_VALUE, MSYMBOL_VALUE_RAW_ADDRESS)
	(MSYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_BYTES)
	(MSYMBOL_BLOCK_VALUE, MSYMBOL_VALUE_CHAIN, MSYMBOL_LANGUAGE)
	(MSYMBOL_SECTION, MSYMBOL_OBJ_SECTION, MSYMBOL_NATURAL_NAME)
	(MSYMBOL_LINKAGE_NAME, MSYMBOL_DEMANGLED_NAME)
	(MSYMBOL_SEARCH_NAME): Update.
	(MSYMBOL_SET_LANGUAGE, MSYMBOL_SET_NAMES): Remove.
	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Don't use memset.
	* minsyms.c (minimal_symbol_reader::record_full): Update.
2019-03-15 16:02:10 -06:00
Tom Tromey 0de2420c4b Use memcpy in minimal_symbol_reader::install
minimal_symbol_reader::install copies minsyms from the msym_bunch
objects into the allocated memory.  It seemed better to me to do this
via memcpy, as that is frequently optimized in libc.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* minsyms.c (minimal_symbol_reader::install): Use memcpy.
2019-03-15 16:02:10 -06:00
Tom Tromey 042d75e42c Allocate minimal symbols with malloc
Currently, minimal symbols are allocated on the per-BFD obstack.
However, it is also possible for multiple symbol readers to create
minimal symbols for a given objfile.  In this case, the minimal
symbols will be reallocated on the obstack, leading to some waste of
storage.

This is a memory leak, but I think it won't be caught by tools like
valgrind, because valgrind doesn't know about obstacks.

This patch fixes the problem by using malloc to allocate the storage
for minimal symbols.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile_per_bfd_storage) <msymbols>: Now a
	unique_xmalloc_ptr.
	(objfile::msymbols_range::begin, objfile::msymbols_range::end):
	Update.
	* minsyms.c (lookup_minimal_symbol_by_pc_section)
	(build_minimal_symbol_hash_tables)
	(minimal_symbol_reader::install): Update.
2019-03-15 16:02:10 -06:00
Tom Tromey db92718b54 Use htab_up for demangled hash
This changes objfile_per_bfd_storage::demangled_names_hash to be an
htab_up.  This lets us remove some manual management code from the
objfile_per_bfd_storage destructor.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* symtab.c (create_demangled_names_hash): Update.
	(symbol_set_names): Update.
	* objfiles.h (struct objfile_per_bfd_storage)
	<demangled_names_hash>: Now an htab_up.
	* objfiles.c (objfile_per_bfd_storage): Simplify.
2019-03-15 16:02:09 -06:00
Tom Tromey d6797f465c Simplify per-BFD storage management
There's no reason that the objfile_per_bfd_storage must be allocated
via bfd_alloc.  This patch changes objfile_per_bfd_storage to be
managed more simply, via ordinary new and delete; and moves some code
into its (new) destructor.

While doing this I also noticed an extra initialization of
language_of_main, and removed it.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile_per_bfd_storage): Declare
	destructor.
	* objfiles.c (objfile_per_bfd_storage::~objfile_per_bfd_storage):
	New.
	(get_objfile_bfd_data): Use new.  Don't initialize
	language_of_main.
	(free_objfile_per_bfd_storage): Remove.
	(objfile_bfd_data_free, objfile::~objfile): Use delete.
2019-03-15 16:02:09 -06:00
Tom Tromey 741d7538b7 Remove minsym termination
I was curious what used the terminating "null" minimal symbol; and
after looking I could not find anything.  This patch removes
terminate_minimal_symbol_table and the extra minimal symbol that is
allocated for it.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* symfile.c (reread_symbols): Update.
	* objfiles.c (objfile::objfile): Update.
	* minsyms.h (terminate_minimal_symbol_table): Don't declare.
	* minsyms.c (lookup_minimal_symbol_by_pc_section): Update
	comment.
	(minimal_symbol_reader::install): Update.
	(terminate_minimal_symbol_table): Remove.
	* jit.c (jit_object_close_impl): Update.
2019-03-15 16:02:08 -06:00
Tom Tromey 788c80d1af Remove some unneeded initializations in minimal_symbol_reader
minimal_symbol_reader::record_full does not need to initialize any
minsym fields to 0, because that was already done implicitly via the
use of XCNEW when allocating the msym_bunch.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* minsyms.c (minimal_symbol_reader::record_full): Remove some
	initializations.
2019-03-15 16:02:08 -06:00
Tom Tromey 1b7a07cba0 Use bitset for demangled_hash_languages
I noticed that objfile_per_bfd_storage::demangled_hash_languages is a
std::vector, which seemed quite large for something that,
fundamentally, can be represented as a bitset.  This patch
reimplements it as a std::bitset.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* objfiles.h (struct objfile_per_bfd_storage)
	<demangled_hash_languages>: Now a bitset.
	* minsyms.c (add_minsym_to_demangled_hash_table): Update.
	(lookup_minimal_symbol): Update.
2019-03-15 16:02:08 -06:00
Tom Tromey 3db066bcd5 Slightly simplify minsym creation
Only one caller of minimal_symbol_reader::record_with_info was using
the return value, so this patch simplifies this code by having it
return void and changing that caller to use record_full instead.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

	* minsyms.h (class minimal_symbol_reader) <record_with_info>:
	Don't return the symbol.
	* coffread.c (record_minimal_symbol): Use record_full.
2019-03-15 16:02:07 -06:00
Simon Marchi 5c85e20d5a Fix gdb.texinfo build
Commit b4be1b0648 ("Fix MI output for multi-location breakpoints")
broke the build of gdb.texinfo.  The problem is simply the use of "@end
@table", which should be "@end table".

The error was:

    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27870: warning: @table should not appear in @end
    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27870: table requires an argument: the formatter for @item
    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27870: no matching `@end table'
    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27870: bad argument to @end: @table
    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27867: warning: @table has text but no @item
    /home/smarchi/src/binutils-gdb/gdb/doc/gdb.texinfo:27879: @node seen before @end table

gdb/doc/ChangeLog:

	* gdb.texinfo (GDB/MI Development and Front Ends): Fix closing
	of table, "@end @table" -> "@end table".
2019-03-14 15:04:43 -04:00
Eli Zaretskii 3fff2c370c Fix colors in TUI mode in MS-Windows build with ncurses
The MS-Windows port of ncurses fails to switch to a color pair if
one or both of the colors are the implicit default colors.  This
change records the default colors when TUI is initialized, and
then specifies them explicitly when a color pair uses the default
colors.  This allows color styling in TUI mode on MS-Windows.

gdb/ChangeLog:
2019-03-14  Eli Zaretskii  <eliz@gnu.org>

	* tui/tui-io.c [__MINGW32__]: Include windows.h.  Declare
	ncurses_norm_attr.
	(tui_initialize_io) [__MINGW32__]: Record the default terminal
	colors in ncurses_norm_attr.
	(apply_ansi_escape) [__MINGW32__]: If a color in a color pair is
	"none", replace it with the default color recorded in
	ncurses_norm_attr.
2019-03-14 17:31:38 +02:00