Commit Graph

43437 Commits

Author SHA1 Message Date
Tom Tromey 3df505f60e TUI resize unification
The TUI currently has two different ways to resize a window: the
resize method, and the methods make_invisible_and_set_new_height and
make_visible_with_new_height.

There's no deep reason to have two different ways to resize a window,
so this patch unifies them, leaving just the "resize" method.

This also changes the locator to be handled more like an ordinary
window and less like an adjunct of the associated source window.

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

	* tui/tui-io.c (tui_puts_internal): Check TUI_CMD_WIN before
	calling update_cmdwin_start_line.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<do_make_visible_with_new_height, set_new_height>: Don't declare.
	<rerender>: Declare.
	* tui/tui-winsource.c (tui_source_window_base::update_tab_width):
	Call rerender.
	(tui_source_window_base::set_new_height): Remove.
	(tui_source_window_base::rerender): Rename from
	do_make_visible_with_new_height.
	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Use
	resize method.
	(tui_win_info::make_invisible_and_set_new_height)
	(tui_win_info::make_visible_with_new_height): Remove.
	* tui/tui-stack.h (struct tui_locator_window) <rerender>:
	Declare.
	* tui/tui-stack.c (tui_locator_window::rerender): New method.
	* tui/tui-regs.h (struct tui_data_window) <set_new_height,
	do_make_visible_with_new_height>: Don't declare.
	<rerender>: Declare.
	* tui/tui-regs.c (tui_data_window::rerender): Rename from
	set_new_height.
	(tui_data_window::do_make_visible_with_new_height): Remove.
	* tui/tui-layout.c (show_source_disasm_command, show_data): Don't
	call tui_show_locator_content.
	(tui_gen_win_info::resize): Call rerender.
	(show_source_or_disasm_and_command): Don't call
	tui_show_locator_content.
	* tui/tui-data.h (struct tui_gen_win_info) <rerender>: New
	method.
	(struct tui_win_info) <rerender>: Declare.
	<set_new_height, make_invisible_and_set_new_height,
	make_visible_with_new_height>: Don't declare.
	* tui/tui-data.c (tui_win_list::rerender): New method.
	* tui/tui-command.h (struct tui_cmd_window)
	<do_make_visible_with_new_height>: Don't declare.
	* tui/tui-command.c
	(tui_cmd_window::do_make_visible_with_new_height): Remove.

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

	* gdb.tui/empty.exp: Enable resizing tests.
2019-08-15 14:17:11 -06:00
Tom Tromey 272560b577 Fix bug with character enumeration literal
gnat encodes character enumeration literals using a few different
schemes.  The gnat compiler documented the "QU" and "QW" encodings,
but failed to document that a simpler encoding was used for certain
characters.

This patch updates gdb to handle this simple Q encoding.  Note that
wide character literals are still not handled.

gdb/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* ada-exp.y (convert_char_literal): Handle "Q%c" encoding.
	* ada-lang.c (ada_enum_name): Likewise.

gdb/testsuite/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/char_enum.exp: Add regression tests.
	* gdb.ada/char_enum/foo.adb (Char_Enum_Type): Use '_'
	and '0'.
	(Char, Gchar): Update.
	* gdb.ada/char_enum/pck.ads (Global_Enum_Type): Use '+'.
2019-08-15 13:42:31 -06:00
Christian Biesinger 08235187bc Rename internal Python functions to start with an underscore
I could not tell if GdbSetPythonDirectory is internal or not because
I could not find any references to it, so I left it as-is.

Tested by running the testsuite on gdb.python/*.exp; everything still
passes.

2019-08-15  Christian Biesinger  <cbiesinger@google.com>

	* python/lib/gdb/__init__.py (GdbOutputFile): Rename to have a
	leading underscore.
	(GdbOutputErrorFile): Likewise.
	(global scope): Adjust constructor calls to GdbOutput{,Error}File
	accordingly.
	(execute_unwinders): Rename to have a leading underscore.
	(auto_load_packages): Likewise.
	(global scope): Adjust call to auto_load_packages accordingly.
	(GdbSetPythonDirectory): Likewise.
	* python/py-unwind.c (pyuw_sniffer): Call _execute_unwinders
	instead of execute_unwinders.

gdb/testsuite/ChangeLog:

2019-08-15  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/python.exp: Expect a leading underscore on
	GdbOutput{,Error}File.
2019-08-15 14:21:57 -05:00
Tom Tromey db502012fc TUI window resize should not need invisibility
When resizing a window, the TUI currently first makes it invisible,
then changes the size, and then restores its visibility.

I think this is done because curses doesn't truly support resizing a
window -- there is a "wresize" extension, but the man page says it
isn't available in all versions of curses.

First, this is probably not a major problem any more.  I imagine most
of those old systems are gone now.

Second, I think it's a better API to have this detail hidden inside of
the resize method.

This patch changes the code to follow this idea, and changes the
ordinary resize method to use wresize when it is available.  The
special case for the command window is also moved to methods on the
command window.

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

	* tui/tui-layout.c (show_layout, show_source_disasm_command)
	(show_data): Don't change window visibility.
	(tui_gen_win_info::resize): Remove special case for command
	window.  Use wresize, when available.
	(show_source_or_disasm_and_command): Don't change window
	visibility.
	* tui/tui-command.h (struct tui_cmd_window) <resize>: Declare.
	<make_visible>: New method.
	* tui/tui-command.c (tui_cmd_window::resize): New method.
2019-08-15 12:29:28 -06:00
Tom Tromey 3891b65efe Change TUI source window iteration
Currently the TUI does separate bookkeeping to track which source
windows exist.  It seems better to me to just refer to the list of
windows for this, so this patch removes the special handling and
instead adds a new iterator.

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

	* tui/tui-winsource.h (struct tui_source_window_iterator): New.
	(struct tui_source_windows): New.
	* tui/tui-winsource.c (tui_display_main): Update.
	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights)
	(new_height_ok, parse_scrolling_args): Update.
	* tui/tui-layout.c (show_layout, show_data): Update.
	* tui/tui-data.h (tui_source_windows, tui_clear_source_windows)
	(tui_add_to_source_windows): Don't declare.
	* tui/tui-data.c (source_windows, tui_source_windows)
	(tui_clear_source_windows, tui_add_to_source_windows): Remove.
2019-08-15 12:29:28 -06:00
Tom Tromey ee556432c4 Rename the "reset" method to "resize"
tui_gen_win_info::reset really just resizes the window.  This patch
renames it to reflect this.

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

	* tui/tui-winsource.h (struct tui_source_window_base) <resize>:
	Rename from reset.
	* tui/tui-winsource.c (tui_source_window_base::resize): Rename.
	* tui/tui-layout.c (show_source_disasm_command, show_data):
	Update.
	(tui_gen_win_info::resize): Rename.
	(show_source_or_disasm_and_command): Update.
	* tui/tui-data.h (struct tui_gen_win_info) <resize>: Rename from
	reset.
2019-08-15 12:29:28 -06:00
Tom Tromey 46f438e3d5 Remove tui_initialize_static_data
tui_initialize_static_data is not needed, because locator moving and
resizing is already handled in the layout code.

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

	* tui/tui-stack.c (tui_initialize_static_data): Remove.
	* tui/tui-interp.c (tui_interp::init): Don't call
	tui_initialize_static_data.
	* tui/tui-data.h (tui_initialize_static_data): Don't declare.
2019-08-15 12:29:28 -06:00
Tom Tromey f4ce562c7f Minor simplification in tui_default_win_viewport_height
tui_default_win_viewport_height doesn't need to look at tui_win_list;
it can simply check the type directly.

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

	* tui/tui-layout.c (tui_default_win_viewport_height): Don't
	examine tui_win_list.
2019-08-15 12:29:28 -06:00
Tom Tromey c398c3d0b5 Remove tui_clear_source_content
tui_clear_source_content is not needed.  Instead, the callers can call
erase_source_content, which is also changed to clear the content
vector.

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

	* tui/tui-winsource.h (tui_clear_source_content): Don't declare.
	* tui/tui-winsource.c (tui_update_source_window_as_is): Don't call
	tui_clear_source_content.
	(tui_clear_source_content): Remove.
	(tui_source_window_base::do_erase_source_content): Hoist call to
	content.clear().
	* tui/tui-stack.c (tui_show_frame_info): Don't call
	tui_clear_source_content.
2019-08-15 12:29:28 -06:00
Tom Tromey e25d200487 Turn tui_erase_source_content into a method
This changes tui_erase_source_content into a method on
tui_source_window_base.  The bulk of the work is moved into a helper
method, so that the callers can each pass the string appropriate to
the particular window class.

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

	* tui/tui-winsource.h (struct tui_source_window_base)
	<do_erase_source_content>: New method.
	<erase_source_content>: New method.
	(tui_erase_source_content): Don't declare.
	* tui/tui-winsource.c (tui_clear_source_content): Update.
	(tui_source_window_base::do_erase_source_content): Rename from
	tui_erase_source_content.
	(tui_source_window_base::show_source_content): Update.
	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Update.
	* tui/tui-source.h (struct tui_source_window)
	<erase_source_content>: New method.
	* tui/tui-disasm.h (struct tui_disasm_window)
	<erase_source_content>: New method.
2019-08-15 12:29:28 -06:00
Tom Tromey 002f15c277 Remove tui_alloc_source_buffer
There is no longer any need for tui_alloc_source_buffer.  The two
callers of this function immediately change the contents of the
window, undoing the work done by this function.

This required adding a move constructor to tui_source_element -- a
mildly surprising find, but without this, resizing the vector will
cause crashes.  This issue was masked earlier because
tui_alloc_source_buffer handled this.

Note that a patch for this bug was submitted here:

    https://sourceware.org/ml/gdb-patches/2019-08/msg00094.html

That patch is better, IMO, but the author as yet hasn't responded to a
request for a ChangeLog entry.

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

	* tui/tui-winsource.h (tui_alloc_source_buffer): Don't declare.
	(struct tui_source_element): Add DISABLE_COPY_AND_ASSIGN, and move
	constructor.
	* tui/tui-winsource.c (tui_alloc_source_buffer): Remove.
	* tui/tui-source.c (tui_set_source_content): Update.
	* tui/tui-disasm.c (tui_set_disassem_content): Update.
2019-08-15 12:29:28 -06:00
Tom Tromey c9033fe839 Change tui_line_is_displayed to be a method
This changes tui_line_is_displayed to be a method on
tui_source_window, now that it is obvious that it can only be called
for this type.

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

	* tui/tui-winsource.h (tui_line_is_displayed): Don't declare.
	* tui/tui-winsource.c (tui_line_is_displayed): Move to
	tui-source.c.
	* tui/tui-source.h (struct tui_source_window) <line_is_displayed>:
	Declare.
	* tui/tui-source.c (tui_source_window::line_is_displayed): New
	method.
	(tui_source_window::maybe_update): Update.
2019-08-15 12:29:28 -06:00
Tom Tromey 088f37dd90 Change tui_addr_is_displayed into a method
This changes tui_addr_is_displayed to be a method on
tui_disasm_window, now that it is obvious that it can only be called
for this type.

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

	* tui/tui-winsource.h (tui_addr_is_displayed): Don't declare.
	* tui/tui-winsource.c (tui_addr_is_displayed): Move to
	tui-disasm.c.
	* tui/tui-disasm.h (struct tui_disasm_window) <addr_is_displayed>:
	Declare.
	* tui/tui-disasm.c (tui_disasm_window::addr_is_displayed): New
	method.
	(tui_disasm_window::maybe_update): Update.
2019-08-15 12:29:28 -06:00
Tom Tromey a54700c6c4 Move contents of tui_show_frame_info to new method
This moves much of the body of tui_show_frame_info to a new method on
tui_source_window_base.  This removes a check for the type of a
window.

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

	* tui/tui-winsource.h (struct tui_source_window_base)
	<maybe_update>: Declare.
	* tui/tui-stack.c (tui_show_frame_info): Call maybe_update
	method.
	* tui/tui-source.h (struct tui_source_window) <maybe_update>:
	Declare.
	* tui/tui-source.c (tui_source_window::maybe_update): New method.
	* tui/tui-disasm.h (struct tui_disasm_window) <maybe_update>:
	Declare.
	* tui/tui-disasm.c (tui_disasm_window::maybe_update): New method.
2019-08-15 12:29:28 -06:00
Tom Tromey e2a678a557 Avoid string_file in tui_make_status_line
tui_make_status_line uses string_file where a simple std::string
constructor would do.  This makes this change.

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

	* tui/tui-stack.c (tui_make_status_line): Use string constructor.
2019-08-15 12:29:28 -06:00
Tom Tromey f2dda47784 Move locator code to tui-stack.c
The locator is mostly implemented in tui-stack.c.  This moves the
remaining bits to tui-stack.c and tui-stack.h, as appropriate.

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

	* tui/tui-wingeneral.c: Include tui-stack.h.
	* tui/tui-stack.h (MAX_LOCATOR_ELEMENT_LEN)
	(struct tui_locator_window): Move from tui-data.h.
	* tui/tui-stack.c (_locator, tui_locator_win_info_ptr)
	(tui_initialize_static_data): Move from tui-data.c.
	* tui/tui-data.h (MAX_LOCATOR_ELEMENT_LEN)
	(struct tui_locator_window): Move to tui-stack.c.
	* tui/tui-data.c (_locator, tui_locator_win_info_ptr)
	(tui_initialize_static_data): Move to tui-stack.c.
2019-08-15 12:29:28 -06:00
Tom Tromey ed4a1084d7 Remove FIXMEs from tui-layout.c
An earlier patch added a couple of FIXME comments to tui-layout.c.
This removes them.  This is possible due to the previous patch that
changed how boxing works in the TUI -- now, no special case for the
command window is needed in box_win.

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

	* tui/tui-layout.c (show_source_disasm_command)
	(show_source_or_disasm_and_command): Use make_visible method, not
	tui_make_window.
	* tui/tui-command.h (struct tui_cmd_window) <make_visible>:
	Remove.
2019-08-15 12:29:28 -06:00
Tom Tromey 65962b20b6 Simplify TUI boxing
In the TUI, whether or not a window can be boxed is a property of the
window's type.  This adds a can_box method to the window classes, and
changes tui_make_window to defer to this, removing the "box_it"
paramter.  This also lets us remove "enum tui_box", as it is no longer
used.

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

	* tui/tui-wingeneral.h (tui_make_window): Update.
	* tui/tui-wingeneral.c (tui_make_window): Remove "box_it"
	parameter.
	(tui_gen_win_info::make_visible): Update.
	* tui/tui-regs.c (tui_data_window::display_registers_from):
	Update.
	* tui/tui-layout.c (show_source_disasm_command)
	(show_source_or_disasm_and_command): Update.
	* tui/tui-data.h (struct tui_gen_win_info) <can_box>: New method.
	(enum tui_box): Remove.
	(struct tui_win_info) <can_box>: New method.
	* tui/tui-command.h (struct tui_cmd_window) <can_box>: New
	method.
2019-08-15 12:29:28 -06:00
Sandra Loosemore 22a2ab04f5 Disable dw2-dir-file-name.exp on remote and/or Windows host.
This test has many hardwired assumptions that pathnames on build and
host are the same, and that POSIX pathname syntax is used.  This
results in dozens of failures on a remote Windows host.  Fixing these
assumptions would involve nontrivial rewrites; meanwhile, let's make
the test results reflect the reality that this testcase isn't supported
on remote host.

2019-08-15  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.dwarf2/dw2-dir-file-name.exp: Skip on remote or
	Windows host.
2019-08-15 10:41:58 -07:00
Sandra Loosemore 835b995b57 Skip batch-preserve-term-settings.exp tests that cannot work on Windows.
This group of tests assume that the gdb "shell" command launches a
POSIX-compliant shell supporting the PPID environment variable, which
is used to get gdb's pid for killing it from a remote_exec shell.  But
on Windows host "shell" launches cmd.exe, which doesn't have an
equivalent query.

2019-08-15  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.base/batch-preserve-term-settings.exp
	(test_terminal_settings_preserved_after_sigterm): Skip on Windows.
2019-08-15 10:41:58 -07:00
Tom Tromey d59b55f095 Use gdb::byte_vector in target_write_memory
Pedro pointed out that target_write_memory should use gdb::byte_vector
rather than std::vector<unsigned char>.

gdb/gdbserver/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* target.c (target_write_memory): Use gdb::byte_vector.
2019-08-15 11:24:22 -06:00
Christian Biesinger 97dd8e07d9 [testsuite] Make the testsuite work on mingw
Dejagnu produces an objdir like /c/, but GDB expects something like c:/.
So fix it up in lib/gdb.exp.

gdb/testsuite/ChangeLog:

2019-08-14  Christian Biesinger  <cbiesinger@google.com>

	* lib/gdb.exp: When running on a mingw target, replace
	/x/ with x:/.
2019-08-15 11:14:35 -05:00
Tom Tromey 4196ab2a6d Replace write_inferior_memory with target_write_memory
target_write_memory is just a simple wrapper for
write_inferior_memory.  Because target_write_memory is needed for
gdbsupport, and because gdb uses the name "target_write_memory"
everywhere, this patch renames write_inferior_memory and removes the
wrapper.  I think this brings gdb and gdbserver slightly more in sync.

gdb/gdbserver/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* tracepoint.c (write_inferior_data_pointer)
	(write_inferior_integer, write_inferior_int8)
	(write_inferior_uinteger, m_tracepoint_action_download)
	(r_tracepoint_action_download, x_tracepoint_action_download)
	(l_tracepoint_action_download, clear_inferior_trace_buffer)
	(download_agent_expr, download_tracepoint_1)
	(download_trace_state_variables, upload_fast_traceframes): Update.
	* server.c (gdb_write_memory): Update.
	* remote-utils.c (relocate_instruction): Update.
	* proc-service.c (ps_pdwrite): Update.
	* mem-break.c (remove_memory_breakpoint)
	(delete_fast_tracepoint_jump, set_fast_tracepoint_jump)
	(uninsert_fast_tracepoint_jumps_at)
	(reinsert_fast_tracepoint_jumps_at): Update.
	* linux-x86-low.c (append_insns)
	(i386_install_fast_tracepoint_jump_pad)
	(amd64_write_goto_address, i386_write_goto_address): Update.
	* linux-s390-low.c (append_insns, s390_write_goto_address):
	Update.
	* linux-ppc-low.c (ppc_relocate_instruction)
	(ppc_install_fast_tracepoint_jump_pad, emit_insns)
	(ppc_write_goto_address): Update.
	* linux-aarch64-low.c (append_insns): Update.
	* target.h (struct target_ops): Update.
	(write_inferior_memory): Don't declare.
	* target.c (target_write_memory): Rename from
	write_inferior_memory.  Remove old target_write_memory.
2019-08-15 07:42:21 -06:00
Tom Tromey c6778d00df Simplify write_inferior_memory
gdbserver's write_inferior_memory uses a static variable to avoid
memory leaks, and has a comment referring to the lack of cleanups.
This patch removes this comment and the code in favor of a
straightforward use of std::vector.

gdb/gdbserver/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* target.c (write_inferior_memory): Use std::vector.
2019-08-15 07:42:21 -06:00
Tom de Vries 2208ee9170 [gdb] Fix gdb build on mips64-linux
When compiling for mips64-linux, we get:
...
src/gdb/linux-nat-trad.c:139:12: error: ‘gdbarch_num_regs’ was not declared \
  in this scope
  139 |   regnum < gdbarch_num_regs (regcache->arch ());
...

Fix this by including gdbarch.h in linux-nat-trad.c, similar to commit
b1c896b365 "Fix gdb build on macOS".

Build on mips64-linux.

gdb/ChangeLog:

2019-08-15  Tom de Vries  <tdevries@suse.de>

	* linux-nat-trad.c: Include gdbarch.h.
2019-08-15 08:14:31 +02:00
Alan Hayward 75faf5c41d AArch64: Allow additional sizes in prologue
When saving registers to the stack at the start of a function, not all state
needs to be saved. For example, only the first 64bits of float registers need
saving.  However, a program may choose to store extra state if it wishes,
there is nothing preventing it doing so.

The aarch64_analyze_prologue will error if it detects extra state being
stored.  Relex this restriction.

Tested via aarch64-prologue test.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_analyze_prologue): Allow any valid
	register sizes.

gdb/testsuite/ChangeLog:

	* gdb.arch/aarch64-prologue.c: New test.
	* gdb.arch/aarch64-prologue.exp: New file.
2019-08-14 15:58:21 +01:00
Tom Tromey b1c896b365 Fix gdb build on macOS
Internal testing showed that the macOS port did not build.  The
breakage was caused by the patch to remove the gdbarch.h include from
defs.h.  This patch fixes the problem.

gdb/ChangeLog
2019-08-14  Tom Tromey  <tromey@adacore.com>

	* darwin-nat.c: Include gdbarch.h.
	* darwin-nat-info.c: Include gdbarch.h.
2019-08-14 08:40:18 -06:00
Tom Tromey 6405cd73c0 Remove tui_gen_win_info::last_visible_line
The last_visible_line field of tui_gen_win_info is not used, so remove
it.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (struct tui_gen_win_info) <last_visible_line>:
	Remove.
	* tui/tui-data.c (tui_initialize_static_data): Update.
2019-08-13 14:52:10 -06:00
Tom Tromey 5216580d7a Don't track the contents of the execution info window
The curses library keeps track of the contents of each window, and can
redraw the screen as needed.  This means that in most cases is no need
for the TUI windows to also keep track of their contents.  This patch
removes content tracking from the execution window, leaving that to
curses.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_exec_info_window)
	<~tui_exec_info_window, maybe_allocate_content, get_content,
	m_content>: Remove.
	(struct tui_source_window_base) <set_exec_info_content,
	show_exec_info_content>: Don't declare.
	* tui/tui-winsource.c
	(tui_exec_info_window::maybe_allocate_content): Remove.
	(tui_source_window_base::update_exec_info): Rename from
	set_exec_info_content.
	(tui_source_window_base::show_exec_info_content)
	(tui_source_window_base::update_exec_info): Remove.
2019-08-13 14:52:10 -06:00
Tom Tromey 93858ad34e Remove tui_clear_exec_info_content
After the previous patch, all calls to tui_clear_exec_info_content
come just after a call to tui_clear_source_content.  Because these two
windows are linked, I think it makes sense to have
tui_clear_source_content simply do the work.  So, this patch removes
tui_clear_exec_info_content.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_clear_exec_info_content): Don't
	declare.
	* tui/tui-winsource.c (tui_update_source_window_as_is)
	(tui_update_source_windows_with_addr, tui_erase_source_content):
	Update.
	(tui_clear_exec_info_content): Remove.
2019-08-13 14:52:10 -06:00
Tom Tromey e321e7ce75 Remove tui_erase_exec_info_content
One call to tui_erase_exec_info_content can be removed.  This call is
not needed because the function in question then immediately sets the
execution info window contents.

Once this is done, tui_clear_exec_info_content is just a wrapper for
the only call to tui_erase_exec_info_content, so
tui_erase_exec_info_content can be renamed and the wrapper function
removed.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_erase_exec_info_content): Don't
	declare.
	* tui/tui-winsource.c (tui_source_window_base::refresh_all): Don't
	call tui_erase_exec_info_content.
	(tui_clear_exec_info_content): Rename from
	tui_erase_exec_info_content.
	(tui_clear_exec_info_content): Delete.
2019-08-13 14:52:09 -06:00
Tom Tromey 8270ac6229 Turn tui_show_exec_info_content into a method
This changes tui_show_exec_info_content to be a method on
tui_source_window_base.  As it is only called by other methods on this
class, it can be private.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<show_exec_info_content>: Declare.
	(tui_show_exec_info_content): Don't declare.
	* tui/tui-winsource.c
	(tui_source_window_base::show_exec_info_content): Rename from
	tui_show_exec_info_content.
	(tui_source_window_base::update_exec_info): Update.
2019-08-13 14:52:09 -06:00
Tom Tromey 7b56485db5 Move code to tui-winsource.h
This moves code related to the execution info window from tui-data.h
to tui-winsource.h.  It fits better here because the execution info is
conceptually part of the source and disassembly windows, and
tui-winsource.h is where this common class lives.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (enum tui_bp_flag, tui_bp_flags, struct tui_source_element)
	(TUI_BP_HIT_POS, TUI_BP_BREAK_POS, TUI_EXEC_POS)
	(TUI_EXECINFO_SIZE, tui_exec_info_content): Move ...
	* tui/tui-winsource.h (enum tui_bp_flag, tui_bp_flags, struct
	tui_source_element, TUI_BP_HIT_POS, TUI_BP_BREAK_POS)
	(TUI_EXEC_POS, TUI_EXECINFO_SIZE, tui_exec_info_content):
	... here.
2019-08-13 14:52:09 -06:00
Tom Tromey 7ba913dcdf Change tui_update_exec_info to be a method
This changes tui_update_exec_info to be a method on
tui_source_window_base.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<update_exec_info>: Declare.
	(tui_update_exec_info): Don't declare.
	* tui/tui-winsource.c (tui_update_source_window_as_is)
	(tui_source_window_base::refresh_all)
	(tui_update_all_breakpoint_info): Update.
	(tui_source_window_base::update_exec_info): Rename from
	tui_update_exec_info.
	* tui/tui-stack.c (tui_show_frame_info): Update.
2019-08-13 14:52:09 -06:00
Tom Tromey 37a4a13104 Change tui_set_exec_info_content to be a method
This changes tui_set_exec_info_content to bea method on
tui_source_window_base.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<set_exec_info_content>: Declare.
	(tui_set_exec_info_content): Don't declare.
	* tui/tui-winsource.c
	(tui_source_window_base::set_exec_info_content): Rename from
	tui_set_exec_info_content.
	(tui_update_exec_info): Update.
2019-08-13 14:52:09 -06:00
Tom Tromey 0bd27e079a Change tui_show_source_content to be a method
This changes tui_show_source_content to be a method on
tui_source_window_base.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<show_source_content>: Declare.
	(tui_show_source_content): Don't declare.
	* tui/tui-winsource.c (tui_update_source_window_as_is): Update.
	(tui_source_window_base::show_source_content): Rename from
	tui_show_source_content.
	(tui_source_window_base::refresh_all): Update.
	* tui/tui-layout.c (show_source_disasm_command)
	(show_source_or_disasm_and_command): Update.
2019-08-13 14:52:09 -06:00
Tom Tromey b4ef5aeb3a Change tui_check_and_display_highlight_if_needed to be a method
This changes tui_check_and_display_highlight_if_needed to be a method
on tui_win_info.  This makes it clear that the NULL check in that
function is not needed, so it is removed here.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_erase_source_content)
	(tui_show_source_content, tui_source_window_base::refresh_all):
	Update.
	* tui/tui-wingeneral.h
	(tui_check_and_display_highlight_if_needed): Don't declare.
	* tui/tui-wingeneral.c
	(tui_win_info::check_and_display_highlight_if_needed): Rename from
	check_and_display_highlight_if_needed.
	* tui/tui-win.c (tui_rehighlight_all)
	(tui_win_info::make_visible_with_new_height): Update.
	* tui/tui-regs.c (tui_data_window::display_registers_from_line)
	(tui_data_window::erase_data_content)
	(tui_data_window::display_all_data): Update.
	* tui/tui-data.h (struct tui_win_info)
	<check_and_display_highlight_if_needed>: Declare.
2019-08-13 14:52:09 -06:00
Tom Tromey fede52738f Delete invisible TUI windows
This changes the TUI so that when the layout changes, any windows that
are invisible are now deleted.  This makes it simpler to understand
window lifetimes.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_resize_all): Call
	tui_delete_invisible_windows.
	* tui/tui-layout.c (show_layout): Call
	tui_delete_invisible_windows.
	* tui/tui-data.h (tui_delete_invisible_windows): Declare.
	* tui/tui-data.c (tui_delete_invisible_windows): New function.
2019-08-13 14:52:09 -06:00
Tom Tromey 22c3f4909a Simplify tui_show_disassem
tui_show_disassem does not need to call tui_add_win_to_layout, because
the callers that could change the layout have already ensured that it
exists.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-disasm.c (tui_show_disassem): Add assertion.  Don't call
	tui_add_win_to_layout.
2019-08-13 14:52:09 -06:00
Tom Tromey 16cb7910b9 Make tui_default_win_height static
tui_default_win_height is only used in tui-layout.c, so make it static.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.h (tui_default_win_height): Don't declare.
	* tui/tui-layout.c (tui_default_win_height): Now static.
2019-08-13 14:52:09 -06:00
Tom Tromey cc0c3ffbc9 Two simplifications in tui-layout.c
This patch simplifies some code in tui-layout.c.

In show_layout, all the layout settings can be handled by a single
switch statement.  In show_source_disasm_command and
show_source_or_disasm_and_command, there is no need to check the
current layout, as the caller has already done so.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_layout): Unify all layout cases into a
	single switch.
	(show_source_disasm_command, show_source_or_disasm_and_command):
	Don't check current layout.
2019-08-13 14:52:09 -06:00
Tom Tromey 3f3ffe54e2 Simplify tui_make_all_invisible
This simplifies the implementation of tui_make_all_invisible.  Also,
because show_data is only called by show_layout, this hoists the call
to tui_make_all_invisible and removes the call from show_data.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.c (make_all_visible): Remove.
	(tui_make_all_invisible): Simplify.
	* tui/tui-layout.c (tui_make_all_invisible): Move from
	tui-wingeneral.c; simplify.
	(show_layout): Hoist call to tui_make_all_invisible.
	(show_data): Don't call tui_make_all_invisible.
2019-08-13 14:52:09 -06:00
Tom Tromey 6925809176 Remove tui_make_all_visible
The function tui_make_all_visible is not used, so remove it.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.h (tui_make_all_visible): Don't declare.
	* tui/tui-wingeneral.c (tui_make_all_visible): Remove.
2019-08-13 14:52:09 -06:00
Tom Tromey 62cf57fee7 Move current_layout to tui-layout.c
This moves the current_layout global to tui-layout.c.  This allows for
the removal of an accessor function; but also it just seems clearer to
have it here.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (current_layout, tui_current_layout): Move from
	tui-data.c.
	(show_source_disasm_command, show_data)
	(show_source_or_disasm_and_command): Don't use
	tui_set_current_layout_to.
	* tui/tui-data.h (tui_set_current_layout_to): Don't declare.
	* tui/tui-data.c (current_layout, tui_current_layout): Move to
	tui-layout.c.
	(tui_set_current_layout_to): Remove.
2019-08-13 14:52:09 -06:00
Tom Tromey 2afade5dbe Remove struct tui_layout_def
"layout_def" isn't actually used in the TUI, so remove it.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (tui_set_layout): Update.
	* tui/tui-data.h (struct tui_layout_def): Remove.
	(tui_layout_def): Don't declare.
	* tui/tui-data.c (layout_def): Remove.
	(tui_layout_def): Remove.
2019-08-13 14:52:09 -06:00
Tom Tromey a3504e9654 clear_detail can only be called on TUI source windows
The clear_detail method can only be called on source windows, so
remove definitions from the base of the class hierarchy, leaving only
a single non-virtual method.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<clear_detail>: No longer "override".
	* tui/tui-regs.h (struct tui_data_window) <clear_detail>: Remove.
	* tui/tui-regs.c (tui_data_window::clear_detail): Remove.
	* tui/tui-data.h (struct tui_win_info) <clear_detail>: Remove.
	* tui/tui-command.h (struct tui_cmd_window) <clear_detail>:
	Remove.
	* tui/tui-command.c (tui_cmd_window::clear_detail): Remove.
2019-08-13 14:52:09 -06:00
Tom Tromey 29c9291108 Don't include readline headers from tracepoint.c
I was curious why updating readline caused so much to be to rebuilt,
so I look at all the uses of the readline headers.  Most are included
for valid reasons (either readline directory or for tilde_expand); but
the includes in tracepoint.c didn't seem to be used.

This patch removes them.  Tested by rebuilding.

gdb/ChangeLog
2019-08-13  Tom Tromey  <tromey@adacore.com>

	* tracepoint.c: Don't include readline.h or history.h.
2019-08-13 12:28:38 -06:00
Tom de Vries abc6c00fb6 [gdb/testsuite] Fix gdb.gdb/selftest.exp regexp
With gdb.gdb/selftest.exp, we get:
...
(xgdb) PASS: gdb.gdb/selftest.exp: send SIGINT signal to child process
^M
Thread 1 "xgdb" received signal SIGINT, Interrupt.^M
0x00007ffff5bf01db in poll () from /lib64/libc.so.6^M
(gdb) FAIL: gdb.gdb/selftest.exp: send ^C to child process again
...

The failure is due to gdb printing 'Thread 1 "xgdb" received signal SIGINT',
but the regexp in the test-case expecting 'Program received signal SIGINT'.

Fix this by updating the regexp, similar to how that is done earlier in the
test-case.

gdb/testsuite/ChangeLog:

2019-08-13  Tom de Vries  <tdevries@suse.de>

	* gdb.gdb/selftest.exp (send ^C to child process again): Accept also
	Thread.
2019-08-13 18:57:50 +02:00
Sandra Loosemore 74c2c1f45f Fixes for gdb.python tests on remote Windows host.
This patch fixes several test ERRORs and FAILs seen from running
gdb.python tests on a remote Windows host.  The problems fixed
generally fall into these categories:
- Failure to copy the .py script to the host.
- Confusion between build and host pathnames.
- Assuming pathnames printed on the host include "/" as a directory
  separator.
- Tests that need to be conditionally disabled due to missing features
  on the host, etc.

2019-08-13  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.python/py-completion.exp: Download the .py file to the host
	and use its host pathname.  Conditionalize tests that use
	tab completion and manipulate files on the build machine.
	* gdb.python/py-events.exp: Download the .py file to the host
	and use its host pathname.
	* gdb.python/py-evsignal.exp: Likewise.
	* gdb.python/py-evthreads.exp: Likewise.
	* gdb.python/py-framefilter-invalidarg.exp: Match Windows
	pathname syntax.
	* gdb.python/py-framefilter.exp: Download the .py file to the right
	place on the host.  Match Windows pathname syntax.
	* gdb.python/py-mi-var-info-path-expression.exp: Download the
	.py file to the host and use its host pathname.
	* gdb.python/py-objfile-script.exp: Match Windows pathname syntax.
	* gdb.python/py-objfile.exp: Expect a host pathname, not a
	build pathname.  Skip symlink test on Windows host.  Add missing
	newline at end of file.
	* gdb.python/py-pp-maint.exp: Download the .py file to the host
	and use its host pathname.
	* gdb.python/py-pp-registration.exp: Match Windows pathname syntax.
	* gdb.python/py-section-script.exp: Use host location of binfile
	on safe-path.  Use correct path separator on Windows host.
	Reorder alternatives in gdb_test_multiple to prevent matching
	the wrong alternative on success.
	* gdb.python/py-symtab.exp: Match Windows pathname syntax.
2019-08-13 09:09:30 -07:00
Tom Tromey 86c6b807f5 Require readline 7 or newer
This changes gdb to require readline 7 or newer at build time.

gdb/ChangeLog
2019-08-12  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Check for readline 7.
	* NEWS: Mention readline 7 requirement.
	* README: Update.

gdb/doc/ChangeLog
2019-08-12  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Configure Options): Document minimum version of
	readline.
2019-08-12 10:57:56 -06:00
Tom Tromey 5db2718ce4 Remove readline hack from gdb_select
As discussed on gdb-patches, this removes the readline hack from the
mingw-hdep.c version of gdb_select.  It's believed that this is not
needed any more.  See:

    https://sourceware.org/ml/gdb-patches/2019-03/msg00465.html

gdb/ChangeLog
2019-08-12  Tom Tromey  <tom@tromey.com>

	* mingw-hdep.c (gdb_select): Remove readline hack.
2019-08-12 10:57:56 -06:00
Patrick Palka ca2589f3bb Fix gdb's selftest.exp after readline import
After the sync there is one testsuite regression, the test
"signal SIGINT" in gdb.gdb/selftest.exp which now FAILs.  Previously,
the readline 6.2 SIGINT handler would temporarily reinstall the
underlying application's SIGINT handler and immediately re-raise SIGINT
so that the orginal handler gets invoked.  But now (since readline 6.3)
its SIGINT handler does not re-raise SIGINT or directly invoke the
original handler; it now sets a flag marking that SIGINT was raised, and
waits until readline explicitly has control to call the application's
SIGINT handler.  Anyway, because SIGINT is no longer re-raised from
within readline's SIGINT handler, doing "signal SIGINT" with a stopped
inferior gdb process will no longer resume and then immediately stop the
process (since there is no 2nd SIGINT to immediately catch).  Instead,
the inferior gdb process will now just print "Quit" and continue to run.
So with this commit, this particular test case is adjusted to reflect
this change in behavior (we now have to send a 2nd SIGINT manually to
stop it).

gdb/testsuite/ChangeLog
2019-08-12  Patrick Palka  <patrick@parcs.ath.cx>

	* gdb.gdb/selftest.exp (test_with_self): Update test to now
	expect the GDB inferior to no longer immediately stop after
	being resumed with "signal SIGINT".
2019-08-12 10:57:56 -06:00
Sandra Loosemore 020a839d52 Match Windows pathnames in gdb.linespec/break-ask.exp.
2019-08-09  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.linespec/break-ask.exp: Generalize regexps to match
	Windows pathnames too.
2019-08-09 13:45:44 -07:00
Pedro Franco de Carvalho dac36daf78 Fix access to uninitialized variable in fill_in_stop_func
This patch changes find_pc_partial_function so that *block is set to
nullptr when it fails, so that fill_in_stop_func won't access an
uninitialized variable.

gdb/ChangeLog:
2019-08-09  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* blockframe.c (find_pc_partial_function): Set *block to nullptr
	when the function fails.
2019-08-09 16:49:46 -03:00
Andreas Arnez 1022c627db s390: Implement 'type_align' gdbarch method
The align.exp test case yields many FAILs on s390x, since GDB's _Alignoff
doesn't always agree with the compiler's.  On s390x, the maximum alignment
is 8, but GDB returns an alignment of 16 for 16-byte data types such as
"long double".

This is fixed by implementing the type_align gdbarch method.  The new
method returns an alignment of 8 for all integer, floating-point, and
vector types larger than 8 bytes.  With this change, all align.exp tests
pass.

gdb/ChangeLog:

	* s390-tdep.c (s390_type_align): New function.
	(s390_gdbarch_init): Set it as type_align gdbarch method.
2019-08-09 20:27:03 +02:00
Alan Hayward 1ba7cdcd93 doc: fix PAC typo
gdb/doc/ChangeLog:

	* gdb.texinfo (AArch64 Pointer Authentication): Fix typo.
2019-08-09 10:32:24 +01:00
Tom de Vries eba4caf231 [gdb] Fix gdb.dwarf2/varval.exp with -fPIE/-pie
With target board unix/-fPIE/-pie, we get:
...
FAIL: gdb.dwarf2/varval.exp: print varval2
...

This is due comparing a get_frame_pc result (which includes the for PIE
non-zero relocation offset) with pc_high and pc_low obtained using
get_scope_pc_bounds (which do not include the relocation offset).

Fix this by adjusting pc_high and pc_low with the relocation offset.

Tested on x86_64-linux with target board unix/-fPIE/-pie.

gdb/ChangeLog:

2019-08-09  Tom de Vries  <tdevries@suse.de>

	PR gdb/24591
	* dwarf2read.c (dwarf2_fetch_die_loc_sect_off): Adjust pc_high and
	pc_low with relocation offset.
2019-08-09 06:49:04 +02:00
Tom de Vries 128d650981 [gdb/testsuite] Fix gdb.tui/basic.exp with check-read1
With gdb.tui/basic.exp and check-read1, we run into (using -v for
verbose log):
...
^[[0+++ _csi_0 <<<>>>
ERROR: (DejaGnu) proc "_csi_0" does not exist.
...

In contrast, without check-read1, we have:
...
^[[0;10m<SNIP>+++ _csi_m <<<0;10>>>
...

The problem is that this regexp in _accept:
...
           -re "^\x1b\\\[(\[0-9;\]*)(\[0-9a-zA-Z@\])" {
...
while matching the longer sequence '^[' '[' '0' ';' '1' '0' 'm', also matches
the shorter sequence '^[' '[' '0'.

The regexp attempts to match a CSI (Control Sequence Introducer) sequence, and
the final byte of such a sequence cannot be a digit.

Fix the regexp accordingly:
...
-           -re "^\x1b\\\[(\[0-9;\]*)(\[0-9a-zA-Z@\])" {
+           -re "^\x1b\\\[(\[0-9;\]*)(\[a-zA-Z@\])" {
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-08  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24862
	* lib/tuiterm.exp (_accept): Fix CSI regexp.
2019-08-08 22:26:28 +02:00
Tom Tromey 123cd85148 Make struct frame_arg self-managing
This changes struct frame_arg to be self-managing and then fixes the
various users.

Tested by the buildbot.

gdb/ChangeLog
2019-08-07  Tom Tromey  <tromey@adacore.com>

	* stack.c (print_frame_arg, read_frame_local, read_frame_arg)
	(print_frame_args): Update.
	* python/py-framefilter.c (py_print_single_arg, enumerate_args):
	Update.
	* mi/mi-cmd-stack.c (list_arg_or_local): Update.
	* frame.h (struct frame_arg): Add initializers.
	<error>: Now a unique_xmalloc_ptr.
2019-08-07 06:37:21 -06:00
Alan Hayward 3d31bc39e6 AArch64 pauth: Indicate unmasked addresses in backtrace
Armv8.3-a Pointer Authentication causes the function return address to be
obfuscated on entry to some functions. GDB must unmask the link register in
order to produce a backtrace.

The following patch adds markers of [PAC] to the bracktrace, to indicate
which addresses needed unmasking.  This includes the backtrace when using MI.

For example, consider the following backtrace:

(gdb) bt
0  0x0000000000400490 in puts@plt ()
1  0x00000000004005dc in foo ("hello") at cbreak-lib.c:6
2  0x0000000000400604 [PAC] in bar () at cbreak-lib.c:12
3  0x0000000000400620 [PAC] in main2 () at cbreak.c:17
4  0x00000000004005b4 in main () at cbreak-3.c:10

The functions in cbreak-lib use pointer auth, which masks the return address
to the previous function, causing the addresses of bar (in the library) and main2
(in the main binary) to require unmasking in order to unwind the backtrace.

An extra bool is added alongside the prev_pc in the frame structure.  At the
point at which the link register is unmasked, the AArch64 port calls into frame
to sets the bool.  This is the most efficient way of doing it.

The marker is also added to the python frame printer, which is always printed if
set.  The marker is not explicitly exposed to the python code.

I expect this will potentially cause issues with some tests in the testsuite
when Armv8.3 pointer authentication is used.  This should be fixed up in the
the future once real hardware is available for full testsuite testing.

gdb/ChangeLog:

        * NEWS: Expand the Pointer Authentication entry.
        * aarch64-tdep.c (aarch64_frame_unmask_address): Rename from this.
        (aarch64_frame_unmask_lr): ... to this.
        (aarch64_prologue_prev_register, aarch64_dwarf2_prev_register):
        Call aarch64_frame_unmask_lr.
        * frame.c (struct frame_info): Add "masked" variable.
        (frame_set_previous_pc_masked) (frame_get_pc_masked): New functions.
        (fprint_frame): Check for masked pc.
        * frame.h (frame_set_previous_pc_masked) (frame_get_pc_masked): New
        declarations.
	* python/py-framefilter.c (py_print_frame): Check for masked pc.
        * stack.c (print_frame): Check for masked pc.

gdb/doc/ChangeLog:

        * gdb.texinfo (AArch64 Pointer Authentication): New subsection.
2019-08-07 13:34:12 +01:00
Tom Tromey 0cf9feb996 Introduce obstack_strndup
This introduces obstack_strndup and changes gdb to use it.

Note that obstack_strndup works like savestring, and not exactly like
xstrndup.  The difference is that obstack_strndup uses the passed-in
length, while xstrndup uses strnlen to choose the length.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* stabsread.c (patch_block_stabs, read_one_struct_field)
	(read_enum_type): Use obstack_strndup.
	* rust-exp.y (rust_parser::copy_name): Use obstack_strndup.
	* gdb_obstack.h (obstack_strndup): Use obstack_strndup.
	* dwarf2read.c (guess_full_die_structure_name)
	(anonymous_struct_prefix): Use obstack_strndup.
	* dbxread.c (cp_set_block_scope): Use obstack_strndup.
	* c-exp.y (yylex): Use obstack_strndup.
	* ada-exp.y (write_object_renaming, write_ambiguous_var)
	(write_var_or_type): Use obstack_strndup.
2019-08-06 20:08:48 -06:00
Tom Tromey efba19b06a Add obstack_strdup overload taking a std::string
This adds an obstack_strdup overload that takes a std::string, and
changes a few spots in gdb to use it.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* symfile.c (reread_symbols): Use obstack_strdup.
	* stabsread.c (read_type): Use obstack_strdup.
	* gdb_obstack.h (obstack_strdup): New overload.
	* dwarf2read.c (dwarf2_compute_name, create_dwo_unit_in_dwp_v1)
	(create_dwo_unit_in_dwp_v2, build_error_marker_type)
	(dwarf2_canonicalize_name): Use obstack_strdup.
	* dbxread.c (read_dbx_symtab): Use obstack_strdup.
	* cp-support.c (inspect_type, replace_typedefs_qualified_name):
	Use obstack_strdup.
2019-08-06 20:08:48 -06:00
Tom Tromey f25102f7b1 Make obstack_strdup inline
This changes obstack_strdup to be an inline function.  This seems
better to me, considering how small it is; but also it follows what
the code did before the previous patch.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* gdb_obstack.h (obstack_strdup): Define.
	* gdb_obstack.c (obstack_strdup): Don't define.
2019-08-06 20:08:48 -06:00
Tom Tromey 021887d88a Use obstack_strdup more
This changes gdb to use obstack_strdup when appropriate, rather than
the wordier obstack_copy0.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (SYMNAME_ALLOC, process_xcoff_symbol): Use
	obstack_strdup.
	* typeprint.c (typedef_hash_table::find_global_typedef): Use
	obstack_strdup.
	* symfile.c (allocate_compunit_symtab): Use obstack_strdup.
	* stabsread.c (common_block_start): Use obstack_strdup.
	* objfiles.c (set_objfile_main_name, objfile): Use
	obstack_strdup.
	* namespace.c (add_using_directive): Use obstack_strdup.
	* mdebugread.c (parse_symbol, parse_type): Use obstack_strdup.
	* jit.c (finalize_symtab): Use obstack_strdup.
	* dwarf2read.c (fixup_go_packaging, dwarf2_physname)
	(guess_partial_die_structure_name, partial_die_info::fixup)
	(dwarf2_name): Use obstack_strdup.
	* coffread.c (coff_read_struct_type, coff_read_enum_type): Use
	obstack_strdup.
	* c-exp.y (scan_macro_expansion): Use obstack_strdup.
	* buildsym.c (buildsym_compunit::end_symtab_with_blockvector): Use
	obstack_strdup.
	* ada-lang.c (ada_decode_symbol): Use obstack_strdup.
2019-08-06 20:08:48 -06:00
Philippe Waroquiers d2834edcb6 Add a selftest that checks documentation invariants.
Several approaches were discussed (mail or irc) to verify the invariants of
the GDB help documentation : checking with apropos ., modifying add_cmd
to do the check and output a warning, implement maintenance check-doc.

A selftest was finally chosen as:
  * this can be run on demand, including by users if they want
    to check user defined commands.
  * it does not interact with the normal behaviour of apropos, define,
    python, ...
    (such as output warnings when a user defines a command help that
     does not respect the doc).
  * when the selftest runs, it checks the user defined and python
    defined commands currently defined.

gdb/ChangeLog
	* unittests/help-doc-selftests.c: New file.
	* Makefile.in: Add the new file.
2019-08-07 00:05:34 +02:00
Philippe Waroquiers 590042fc45 Make first and last lines of 'command help documentation' consistent.
With this patch, the help docs now respect 2 invariants:
  * The first line of a command help is terminated by a '.' character.
  * The last character of a command help is not a newline character.

Note that the changes for the last invariant were done by Tom, as part of :
 [PATCH] Remove trailing newlines from help text
 https://sourceware.org/ml/gdb-patches/2019-06/msg00050.html
but some occurrences have been re-introduced since then.

Some help docs had to be rephrased/restructured to respect the above
invariants.

Before this patch, print_doc_line was printing the first line
of a command help documentation, but stopping at the first '.'
or ',' character.

This was giving inconsistent results :
  * The first line of command helps was sometimes '.' terminated,
    sometimes not.
  * The first line of command helps was not always designed to be
    readable/understandable/unambiguous when stopping at the first
    '.' or ',' character.

This e.g. created the following inconsistencies/problems:
< catch exception -- Catch Ada exceptions
< catch handlers -- Catch Ada exceptions
< catch syscall -- Catch system calls by their names
< down-silently -- Same as the `down' command
while the new help is:
> catch exception -- Catch Ada exceptions, when raised.
> catch handlers -- Catch Ada exceptions, when handled.
> catch syscall -- Catch system calls by their names, groups and/or numbers.
> down-silently -- Same as the `down' command, but does not print anything.

Also, the command help doc should not be terminated by a newline
character, but this was not respected by all commands.
The cli-option -OPT framework re-introduced some occurences.
So, the -OPT build help framework was changed to not output newlines at the
end of %OPTIONS% replacement.

This patch changes the help documentations to ensure the 2 invariants
given above.

It implied to slightly rephrase or restructure some help docs.

Based on the above invariants, print_doc_line (called by
'apropos' and 'help' commands to print the first line of a command
help) now outputs the full first line of a command help.

This all results in a lot of small changes in the produced help docs.
There are less code changes than changes in the help docs, as a lot
of docs are produced by some code (e.g. the remote packet usage settings).

gdb/ChangeLog
2019-08-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.h (print_doc_line): Add for_value_prefix argument.
	* cli/cli-decode.c (print_doc_line): Likewise.  It now prints
	the full first line, except when FOR_VALUE_PREFIX.  In this case,
	the trailing '.' is not output, and the first character is uppercased.
	(print_help_for_command): Update call to print_doc_line.
	(print_doc_of_command): Likewise.
	* cli/cli-setshow.c (deprecated_show_value_hack): Likewise.
	* cli/cli-option.c (append_indented_doc): Do not append newline.
	(build_help_option): Append newline after first appended_indented_doc
	only if a second call is done.
	(build_help): Append 2 new lines before each option, except the first
	one.
	* compile/compile.c (_initialize_compile): Add new lines after
	%OPTIONS%, when not at the end of the help.
	Change help doc or code
	producing the help doc to respect the invariants.
	* maint-test-options.c (_initialize_maint_test_options): Likewise.
	Also removed the new line after 'Options:', as all other commands
	do not put an empty line between 'Options:' and the first option.
	* printcmd.c (_initialize_printcmd): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* interps.c (interpreter_exec_cmd): Fix "Usage:" line that was
	incorrectly telling COMMAND is optional.
	* ada-lang.c (_initialize_ada_language): Change help doc or code
	producing the help doc to respect the invariants.
	* ada-tasks.c (_initialize_ada_tasks): Likewise.
	* breakpoint.c (_initialize_breakpoint): Likewise.
	* cli/cli-cmds.c (_initialize_cli_cmds): Likewise.
	* cli/cli-logging.c (_initialize_cli_logging): Likewise.
	* cli/cli-setshow.c (_initialize_cli_setshow): Likewise.
	* cli/cli-style.c (cli_style_option::add_setshow_commands,
	_initialize_cli_style): Likewise.
	* corelow.c (core_target_info): Likewise.
	* dwarf-index-cache.c (_initialize_index_cache): Likewise.
	* dwarf2read.c (_initialize_dwarf2_read): Likewise.
	* filesystem.c (_initialize_filesystem): Likewise.
	* frame.c (_initialize_frame): Likewise.
	* gnu-nat.c (add_task_commands): Likewise.
	* infcall.c (_initialize_infcall): Likewise.
	* infcmd.c (_initialize_infcmd): Likewise.
	* interps.c (_initialize_interpreter): Likewise.
	* language.c (_initialize_language): Likewise.
	* linux-fork.c (_initialize_linux_fork): Likewise.
	* maint-test-settings.c (_initialize_maint_test_settings): Likewise.
	* maint.c (_initialize_maint_cmds): Likewise.
	* memattr.c (_initialize_mem): Likewise.
	* printcmd.c (_initialize_printcmd): Likewise.
	* python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq,
	_RegEx): Likewise.
	* ravenscar-thread.c (_initialize_ravenscar): Likewise.
	* record-btrace.c (_initialize_record_btrace): Likewise.
	* record-full.c (_initialize_record_full): Likewise.
	* record.c (_initialize_record): Likewise.
	* regcache-dump.c (_initialize_regcache_dump): Likewise.
	* regcache.c (_initialize_regcache): Likewise.
	* remote.c (add_packet_config_cmd, init_remote_threadtests,
	_initialize_remote): Likewise.
	* ser-tcp.c (_initialize_ser_tcp): Likewise.
	* serial.c (_initialize_serial): Likewise.
	* skip.c (_initialize_step_skip): Likewise.
	* source.c (_initialize_source): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* symfile.c (_initialize_symfile): Likewise.
	* symtab.c (_initialize_symtab): Likewise.
	* target-descriptions.c (_initialize_target_descriptions): Likewise.
	* top.c (init_main): Likewise.
	* tracefile-tfile.c (tfile_target_info): Likewise.
	* tracepoint.c (_initialize_tracepoint): Likewise.
	* tui/tui-win.c (_initialize_tui_win): Likewise.
	* utils.c (add_internal_problem_command): Likewise.
	* valprint.c (value_print_option_defs): Likewise.

gdb/testsuite/ChangeLog
2019-08-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/style.exp: Update tests for help doc new invariants.
	* gdb.base/help.exp: Likewise.
2019-08-07 00:04:33 +02:00
Frank Ch. Eigler 404f29021a [PR build/24886] disable glibc mcheck support
This patch drops gdb's configury support for glibc's mcheck function.
It has been observed to cause false abort()s, because it is
thread-unsafe yet interposes every malloc/free operation.  So if any
library transitively used by gdb also uses threads, then these
functions can easily corrupt their own checking data.  These days, gcc
ASAN and valgrind provide high quality checking, and mcheck is
apparently itself being slowly deprecated.

So, let's stop linking to it.  Attached patch drops the
autoconf/Makefile machinery for both gdb and gdbserver.  No
testsuite-visible impact.  IMHO not worth mentioning in NEWS.

See also: https://sourceware.org/bugzilla/show_bug.cgi?id=9939

gdb/ChangeLog

        PR build/24886
        * configure.ac: Drop enable-libmcheck support.
        * configure, config.in: Rebuild.
        * libmcheck.m4: Remove.
        * acinclude.m4: Don't include it.
        * Makefile.in: Don't distribute it.
        * top.c (print_gdb_configuration): Don't mention it.

gdb/gdbserver/ChangeLog

        PR build/24886
        * configure.ac: Drop enable-libmcheck support.
        * configure, config.in: Rebuild.
        * acinclude.m4: Don't include it.
2019-08-06 15:09:53 -04:00
Tom Tromey 046bebe1c0 Add more styling to "disassemble"
This adds more styling to the disassemble command.  In particular,
addresses and function names in the disassembly are now styled.

This required fixing a small latent bug in set_output_style.  This
function always passed NULL to emit_style_escape; but when writing to
a file other than gdb_stdout, it should emit the style escape
directly.  (FWIW this is another argument for better integrating the
pager with ui_file and getting rid of this entire layer.)

gdb/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* utils.c (set_output_style): Sometimes pass stream to
	emit_style_escape.
	* ui-out.h (class ui_out) <can_emit_style_escape>: Declare.
	* record-btrace.c (btrace_insn_history): Update.
	* mi/mi-out.h (class mi_ui_out) <can_emit_style_escape>: New
	method.
	* disasm.h (gdb_pretty_print_disassembler): Add uiout parameter.
	Update initializers.
	<m_uiout>: New field.
	<m_di>: Move lower.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Remove "uiout" parameter.
	(dump_insns): Update.
	* cli-out.h (class cli_ui_out) <can_emit_style_escape>: Declare.
	* cli-out.c (cli_ui_out::can_emit_style_escape): New method.

gdb/testsuite/ChangeLog
2019-08-06  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Add disassemble test.
	* gdb.base/style.c (some_called_function): New function.
	(main): Use it.
2019-08-06 11:37:51 -06:00
Christian Biesinger ddbcedf5de Replace int with enum block_enum where appropriate.
For better readability and type safety.

gdb/ChangeLog:

2019-08-06  Christian Biesinger  <cbiesinger@google.com>

	* symtab.c (symbol_cache_lookup): Change int to enum block_enum.
	(error_in_psymtab_expansion): Likewise.
	(lookup_symbol_via_quick_fns): Likewise.
	(basic_lookup_transparent_type_quick): Likewise.
	(basic_lookup_transparent_type_1): Likewise.
2019-08-06 11:50:52 -05:00
Tom Tromey b08b16c839 Clean up source file error reporting
print_source_lines_base reopens the source file every time that a
source line is to be printed.  However, there's no need to do this so
frequently -- it's enough to do it when switching source files, and
otherwise rely on the cache.

The code seems to try to avoid these multiple opens; at a guess I'd
say something just got confused along the way.

This patch fixes the problem by reorganizing the code both to make it
more clear, and to ensure that reopens only occur when the "last
source visited" changes.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

	* source.c (last_source_error): Now bool.
	(print_source_lines_base): Make "noprint" bool.  Only open
	source file when last_source_visited changes.
2019-08-06 08:04:33 -06:00
Tom Tromey cb44333d99 Add file offsets to the source cache
Currently, gdb stores the number of lines and an array of file offsets
for the start of each line in struct symtab.  This patch moves this
information to the source cache.  This has two benefits.

First, it allows gdb to read a source file less frequently.
Currently, a source file may be read multiple times: once when
computing the file offsets, once when highlighting, and then pieces
may be read again while printing source lines.  With this change, the
file is read once for its source text and file offsets; and then
perhaps read again if it is evicted from the cache.

Second, if multiple symtabs cover the same source file, then this will
share the file offsets between them.  I'm not sure whether this
happens in practice.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

	* annotate.c (annotate_source_line): Use g_source_cache.
	* source-cache.c (source_cache::get_plain_source_lines): Change
	parameters.  Populate m_offset_cache.
	(source_cache::ensure): New method.
	(source_cache::get_line_charpos): New method.
	(extract_lines): Move lower.  Change parameters.
	(source_cache::get_source_lines): Move lower.
	* source-cache.h (class source_cache): Update comment.
	<get_line_charpos>: New method.
	<get_source_lines>: Update comment.
	<clear>: Clear m_offset_cache.
	<get_plain_source_lines>: Change parameters.
	<ensure>: New method
	<m_offset_cache>: New member.
	* source.c (forget_cached_source_info_for_objfile): Update.
	(info_source_command): Use g_source_cache.
	(find_source_lines, open_source_file_with_line_charpos): Remove.
	(print_source_lines_base, search_command_helper): Use g_source_cache.
	* source.h (open_source_file_with_line_charpos): Don't declare.
	* symtab.h (struct symtab) <nlines, line_charpos>: Remove.
	* tui/tui-source.c (tui_source_window::do_scroll_vertical):
	Use g_source_cache.
2019-08-06 08:04:33 -06:00
Tom Tromey 872dceaaff Save plain text in the source cache
Currently the source cache will only store highlighted text.  However,
there's no reason it could not also store plain text, when styling is
turned off.

This patch makes this change.  This also simplifies the source cache
code somewhat.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

	* source-cache.c (source_cache::get_plain_source_lines):
	Remove "first_line" and "last_line" parameters.
	(source_cache::get_source_lines): Cache plain text.
	* source-cache.h (class source_cache)
	<get_plain_source_lines>: Update.
2019-08-06 08:04:33 -06:00
Tom Tromey 269249d940 Fix latent bug in source cache
The source cache was not returning the final \n of the requested range
of lines.  This caused regressions with later patches in this series,
so this patch pre-emptively fixes the bug.

This adds a self-test of "extract_lines" to the source cache code.  To
make it simpler to test, I changed extract_lines to be a static
function, and changed it's API a bit.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

	* source-cache.c (extract_lines): No longer a method.
	Changed type of parameter.  Include final newline.
	(selftests::extract_lines_test): New function.
	(_initialize_source_cache): Likewise.
	* source-cache.h (class source_cache)
	<extract_lines>: Don't declare.
2019-08-06 08:04:33 -06:00
Tom Tromey c0e8dcd871 Change breakpoint::filter to be a unique_xmalloc_ptr
This changes breakpoint::filter to be a unique_xmalloc_ptr, removing
an explicit xfree, as well as a use of a "release" method.

gdb/ChangeLog
2019-08-06  Tom Tromey  <tromey@adacore.com>

	* breakpoint.c (init_breakpoint_sal): Update.
	(breakpoint): Update.
	* breakpoint.h (struct breakpoint) <filter>: Now a
	unique_xmalloc_ptr.
2019-08-06 08:01:21 -06:00
Christian Biesinger 0b27c27d0d Add block['var'] accessor
Currently we support iteration on blocks; this patch extends that to make
subscript access work as well.

gdb/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* NEWS: Mention dictionary access on blocks.
	* python/py-block.c (blpy_getitem): New function.
	(block_object_as_mapping): New struct.
	(block_object_type): Use new struct for tp_as_mapping field.

gdb/doc/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* python.texi (Blocks In Python): Document dictionary access on blocks.

gdb/testsuite/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/py-block.exp: Test dictionary access on blocks.
2019-08-05 13:06:18 -05:00
Christian Biesinger 4ee94178af Add a comment briefly explaining partial symbols
Based on an explanation by tromey on IRC.

gdb/ChangeLog:

2019-08-05  Christian Biesinger  <cbiesinger@google.com>

	* objfiles.h (objfile): Add a comment describing partial symbols.
2019-08-05 10:35:35 -05:00
Simon Marchi 580f1034d1 Increase timeout in gdb.mi/list-thread-groups-available.exp
Running

    make check-read1 TESTS="gdb.mi/list-thread-groups-available.exp"

on my machine results in timeout failures.  Running it while having
`tail -F testsuite/gdb.log` on the side shows that the test is never
really blocked, it is just slow at consuming the large output generated
by `-list-thread-groups --available` (which lists all the processes on
the system).

If I increase the timeout to a large value, the test passes in ~30
seconds (compared to under 1 second normally).

Increase the timeout for the particular mi_gdb_test that is long to
execute under read1.  The new timeout value is a bit arbitrary.  The
default timeout is 10 seconds, so I set the new timeout to be
"old-timeout * 10", so 100 seconds in the typical case.

gdb/testsuite/ChangeLog:

	PR gdb/24863
	* gdb.mi/list-thread-groups-available.exp: Increase timeout for
	-list-thread-groups --available test when running under
	check-read1.
2019-08-05 10:21:48 -04:00
Tom de Vries d86bd7cba1 [gdb/testsuite] Run read1 timeout tests with with_read1_timeout_factor
When running tests with check-read1, we run into some timeouts where the tests
are not easy to rewrite using gdb_test_sequence:
...
FAIL: gdb.base/help.exp: help data (timeout)
FAIL: gdb.base/help.exp: help files (timeout)
FAIL: gdb.base/help.exp: help internals (timeout)
FAIL: gdb.base/help.exp: help user-defined (timeout)
FAIL: gdb.base/help.exp: help breakpoint "b" abbreviation (timeout)
FAIL: gdb.base/help.exp: help breakpoint "br" abbreviation (timeout)
FAIL: gdb.base/help.exp: help breakpoint "bre" abbreviation (timeout)
FAIL: gdb.base/info-macros.exp: info macros 2 (timeout)
FAIL: gdb.base/info-macros.exp: next (timeout)
FAIL: gdb.base/info-macros.exp: info macros 3 (timeout)
FAIL: gdb.base/info-macros.exp: next (timeout)
FAIL: gdb.base/info-macros.exp: next (timeout)
FAIL: gdb.base/info-macros.exp: info macros (timeout)
FAIL: gdb.base/info-macros.exp: next (timeout)
FAIL: gdb.base/info-macros.exp: next (timeout)
FAIL: gdb.base/info-macros.exp: info macros 7 (timeout)
FAIL: gdb.cp/nested-types.exp: ptype S10 (limit = -1) // parse failed (timeout)
FAIL: gdb.cp/nested-types.exp: set print type nested-type-limit 1 (timeout)
...

Fix these by increasing the timeout by a factor 10.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-05  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24863
	* lib/gdb.exp (with_read1_timeout_factor): New proc.
	* gdb.base/help.exp: Use with_read1_timeout_factor.
	* gdb.base/info-macros.exp: Same.
	* gdb.cp/nested-types.exp: Same.
2019-08-05 15:41:04 +02:00
Tom Tromey 8abfcabcb4 Use _() in calls to build_help
Currently some code in gdb uses build_help with N_(), like:

  static const std::string compile_print_help
    = gdb::option::build_help (N_("\

I believe this is incorrect.  The N_ macro is used to mark text that
should end up in the message catalog, but which will be translated by
a later call to gettext.

However, in this case, there is no later call to gettext, so (if gdb
had translations), this text would remain untranslated.

Instead, I think using the ordinary _() macro is correct here.
Translators will have to know to preserve "%OPTIONS%" in the text --
but that seems both unavoidable and fine.

Tested by rebuilding as there's not much else to do.

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

	* compile/compile.c (_initialize_compile): Use _(), not N_().
	* thread.c (_initialize_thread): Use _(), not N_().
	* stack.c (_initialize_stack): Use _(), not N_().
	* printcmd.c (_initialize_printcmd): Use _(), not N_().
2019-08-05 07:36:28 -06:00
Tom de Vries a80cf5d88e [gdb/testsuite] Fail in gdb_compile if pie results in non-PIE executable
When running gdb.base/break-idempotent.exp with
--target_board=unix/-fno-PIE/-no-pie, we get:
...
nr of expected passes            140
...

The test-case is compiled once with nopie and once with pie, but in both cases
we end up with a non-PIE executable.  The "-fno-PIE -no-pie" options specified
using the target_board are interpreted by dejagnu as multilib_flags, and end up
overriding the pie flags.

Fix this by checking in gdb_compile if the resulting exec is non-PIE despite of
a pie setting, and if so return an error:
...
Running gdb/testsuite/gdb.base/break-idempotent.exp ...
gdb compile failed, pie failed to generate PIE executable

                === gdb Summary ===

nr of expected passes            70
nr of untested testcases         1
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-05  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (version_at_least): Factor out of ...
	(tcl_version_at_least): ... here.
	(gdb_compile): Fail if pie results in non-PIE executable.
	(readelf_version, readelf_prints_pie): New proc.
	(exec_is_pie): Return -1 if unknown.
2019-08-05 12:51:58 +02:00
Tom de Vries d096283854 [gdb/testsuite] Fix typo in tcl_version_at_least
In tcl_version_at_least we compare a minor against a major version number:
...
    } elseif { $tcl_version_major == $major \
                  && $tcl_version_major >= $minor } {
...

Fix this by using $tcl_version_minor in the comparison instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-05  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (tcl_version_at_least): Fix typo.
2019-08-05 12:51:58 +02:00
Simon Marchi 2b79f3761c Remove some variables in favor of using gdb::optional
While reading that code, I noticed that some variables essentially meant
whether to consider some other variable or not.  I think using
gdb::optional (which was not available when this code was written) is
clearer, as it embeds the used/not used predicate directly in the type
of the variable, making it harder to miss.

gdb/ChangeLog:

	* dwarf2read.c (struct dw2_symtab_iterator):
	<want_specific_block>: Remove.
	<block_index>: Change type to gdb::optional.
	(dw2_symtab_iter_init): Remove WANT_SPECIFIC_BLOCK parameter,
	change type of BLOCK_INDEX parameter to gdb::optional.
	(dw2_symtab_iter_next): Re-write in function of gdb::optional.
	(dw2_lookup_symbol): Don't pass argument for
	WANT_SPECIFIC_BLOCK.
	(dw2_expand_symtabs_for_function): Don't pass argument for
	WANT_SPECIFIC_BLOCK, pass empty optional for BLOCK_INDEX.
	(class dw2_debug_names_iterator)
	<dw2_debug_names_iterator>: Remove WANT_SPECIFIC_BLOCK
	parameter, change BLOCK_INDEX type to gdb::optional.
	<m_want_specific_block>: Remove.
	<m_block_index>: Change type to gdb::optional.
	(dw2_debug_names_iterator::next): Change type of IS_STATIC to
	gdb::optional.  Re-write in function of gdb::optional.
	(dw2_debug_names_lookup_symbol): Don't pass argument for
	WANT_SPECIFIC_BLOCK.
	(dw2_debug_names_expand_symtabs_for_function): Don't pass
	argument for WANT_SPECIFIC_BLOCK, pass empty optional for
	BLOCK_INDEX.
2019-08-04 22:44:05 -04:00
Sandra Loosemore 2252ff3d90 Skip GDB test reconnect-ctrl-c.exp if nointerrupts is set.
2019-08-04  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* gdb.server/reconnect-ctrl-c.exp: Skip if nointerrupts.
2019-08-04 14:34:31 -07:00
Sandra Loosemore 26655f5306 Add check for readline support to more GDB tab-completion tests.
2019-08-04  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/testsuite/
	* lib/completion-support.exp (test_gdb_complete_none): Skip
	tab completion tests if no readline support.
	(test_gdb_complete_unique_re): Likewise.
	(test_gdb_complete_multiple): Likewise.
2019-08-04 14:26:39 -07:00
Philippe Waroquiers ae60f04e08 NEWS and documentation for info sources [-dirname | -basename] [--] [REGEXP].
gdb/ChangeLog
2019-08-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

        * NEWS: Mention changes to "info sources" command.

gdb/doc/ChangeLog
2019-08-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

        * gdb.texinfo (Symbols): Document new args -dirname and -basename
        of "info sources" command.
2019-08-03 21:27:51 +02:00
Philippe Waroquiers db4dc13eeb New test for 'info sources [-dirname | -basename] [--] [REGEXP]'.
This patch introduces a test for the 'info sources' command
and its new arguments [-dirname | -basename] [--] [REGEXP].

gdb/testsuite/ChangeLog

2019-08-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/info_sources.exp: New file.
	* gdb.base/info_sources.c: New file.
	* gdb.base/info_sources_base.c: New file.
2019-08-03 21:27:06 +02:00
Philippe Waroquiers 28cd9371e8 New "info sources" args [-dirname | -basename] [--] [REGEXP]
gdb/ChangeLog

2019-08-03  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* symtab.c (filename_partial_match_opts): New struct type.
	(struct output_source_filename_data): New members
	regexp, c_regexp, partial_match.
	(output_source_filename): Use new members to decide to print file.
	(info_sources_option_defs): New variable.
	(make_info_sources_options_def_group, print_info_sources_header,
	info_sources_command_completer):
	New functions.
	(info_sources_command): Read new optional arguments.
	(_initialize_symtab): Update info sources help.
2019-08-03 21:26:37 +02:00
Alexandre Oliva ca683e3a86 support Ada EH ABI v1
A new pair of hooks used by Ada exception handlers, for correct
release of reraised exception occurrences, involves the introduction
of new v1 symbols that GDB should use when available.  The older, v0
ABI remains available in newer runtimes for bootstrapping purposes
only.


for  gdb/ChangeLog

	* ada-lang.c (exception_support_info_v0): Renamed from...
	(default_exception_support_info): ... this.  Create new
	definition for v1.
	(ada_has_this_exception_support): Look up catch_handlers_sym.
	(ada_exception_support_info_sniffer): Try v0 after default.
2019-08-02 15:40:32 -03:00
Pedro Franco de Carvalho 0eba165a74 Remove directory names from gdb.base/batch-exit-status.exp
Adjust gdb.base/batch-exit-status.exp so that test prefixes don't show
directory names for the source scripts passed with -x, to make test
results from different build directories comparable.

gdb/testsuite/ChangeLog:
2019-08-01  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* gdb.base/batch-exit-status.exp: Call test_exit_status with
	prefix argument.
	(test_exit_status): Add prefix argument.
2019-08-01 16:51:44 -03:00
Tom Tromey f126416240 Fix the ia64 libunwind build
This fixes the ia64 libunwind build.

gdb/ChangeLog
2019-08-01  Tom Tromey  <tromey@adacore.com>

	* ia64-libunwind-tdep.h (struct libunwind_descr): Include
	gdbarch.h.
2019-08-01 12:14:07 -06:00
Christian Biesinger 0a7b24850e Include s12z-opc.h using ../opcodes.
This file exists in binutils-gdb/opcodes, and nothing in Makefile.in adds this
to the include path.  Default builds work because in-tree readline adds
binutils-gdb/ to the include path (!). However, this is broken when compiling
with system readline.

Other files already use this way to include files in opcodes:
./gdb/lm32-tdep.c:#include "../opcodes/lm32-desc.h"
./gdb/or1k-tdep.h:#include "../opcodes/or1k-desc.h"
./gdb/mep-tdep.c:#include "../opcodes/mep-desc.h"

etc.

gdb/ChangeLog:

2019-08-01  Christian Biesinger  <cbiesinger@google.com>

	* s12z-tdep.c: Fix include path for s12z-opc.h.
2019-08-01 12:40:49 -05:00
Alan Hayward c6bdbeb7c4 Require GNU make 3.82
Gdbserver has failed to build with GNU make 3.81 since commit 08f10e02be.

Update the NEWS file to state that versions earlier than 3.82 are not
supported.

3.82 was released in 2010, 3.81 was released 2006. A quick investigation
of the default GNU make version provided across various distros found the
earliest provided version to be 3.82:
*RHEL 7, Centos 6 - make 3.82
*Fedora 27 - make 4.2.1
*OpenSuse 42.2, SLES11 - make 4.2.1
*Ubuntu 16.04/18.04 - make 4.1
*Debian Jessie - make 4.0

Note that Glibc requires at least 4.0, whereas GCC still allows 3.81.

gdb/ChangeLog:

	* NEWS: Require GNU make 3.82.
2019-08-01 17:07:43 +01:00
Tom de Vries 59bd512b9c [gdb/testsuite] Fix gdb.threads/fork-plus-threads.exp timeout with check-run1
With gdb.threads/fork-plus-threads.exp and check-run1 we get:
...
FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: \
  inferior 1 exited (timeout)
...

Fix this by calling exp_continue for new thread and thread exited messages.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-01  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24863
	* gdb.threads/fork-plus-threads.exp: Fix check-run1 timeout by
	calling exp_continue for new thread and thread exited messages.
2019-08-01 10:48:11 +02:00
Tom de Vries 2a3ad588e0 [gdb/testsuite] Fix gdb.base/structs.exp timeout with check-read1
With gdb.base/structs.exp and check-read1 we get:
...
FAIL: gdb.base/structs.exp: p chartest (timeout)
...

Fix this by using gdb_test_sequence.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-01  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24863
	* gdb.base/structs.exp: Fix check-read1 timeout using
	gdb_test_sequence.
	* lib/gdb.exp (tcl_version_at_least, lrepeat): New proc.
2019-08-01 10:48:11 +02:00
Tom de Vries 117eb59422 [gdb/testsuite] Fix gdb.base/break-interp.exp timeout with check-read1
With gdb.base/break-interp.exp and check-read1, we run get:
...
FAIL: gdb.base/break-interp.exp: LDprelinkNOdebugNO: \
  BINprelinkNOdebugNOpieNO: symbol-less: info files (timeout)
FAIL: gdb.base/break-interp.exp: LDprelinkNOdebugNO: \
  BINprelinkNOdebugNOpieYES: symbol-less: info files (timeout)
FAIL: gdb.base/break-interp.exp: LDprelinkNOdebugIN: \
  BINprelinkNOdebugNOpieNO: symbol-less: info files (timeout)
FAIL: gdb.base/break-interp.exp: LDprelinkNOdebugIN: \
  BINprelinkNOdebugNOpieYES: symbol-less: info files (timeout)
...

Fix this by calling exp_continue after each "info files" line.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-01  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24863
	* gdb.base/break-interp.exp: Use exp_continue after each "info files"
	line.
2019-08-01 10:48:11 +02:00
Tom de Vries ed5913402b [gdb/testsuite] Fix gdb.base/signals.exp timeout with check-read1
With gdb.base/signals.exp and check-read1 we get:
...
FAIL: gdb.base/signals.exp: info signals (timeout)
...

Fix this by using gdb_test_sequence.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-08-01  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24863
	* gdb.base/signals.exp: Fix check-read1 timeout using gdb_test_sequence.
2019-08-01 10:48:11 +02:00
Tom Tromey a2bd7b82ee Don't declare tui_copy_win or tui_box_win
tui_copy_win and tui_box_win are not implemented, so don't declare
them.

gdb/ChangeLog
2019-07-16  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.h (tui_copy_win, tui_box_win): Don't
	declare.
2019-07-30 16:19:59 -06:00
Tom Tromey aa3b653351 Allow nested function displays
In Ada, it's possible to have nested functions.  However,
block.c:contained_in does not recognize this.  Normally, this is no
problem, but if gdb is stopped inside a nested function, then you can
end up in the unexpected situation that "print" of an expression will
work, whereas "display" of the same expression will not -- because
contained_in returns 0.

This patch simply removes the BLOCK_FUNCTION check from contained_in.
The rationale here is that in languages without nested functions, this
will not cause any issues.

gdb/ChangeLog
2019-07-30  Tom Tromey  <tromey@adacore.com>

	* block.c (contained_in): Remove BLOCK_FUNCTION check.

gdb/testsuite/ChangeLog
2019-07-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/display_nested.exp: New file.
	* gdb.ada/display_nested/foo.adb: New file.
	* gdb.ada/display_nested/pack.adb: New file.
	* gdb.ada/display_nested/pack.ads: New file.
2019-07-30 12:34:51 -06:00
Kevin Buettner a1530dc731 Allow display of negative offsets in print_address_symbolic()
When examining addresses associated with blocks with non-contiguous
address ranges, it's not uncommon to see large positive offsets which,
for some address width, actually represent a smaller negative offset.
Here's an example taken from the test case (using the
dw2-ranges-func-lo-cold executable):

    (gdb) x/5i foo_cold
       0x40110d <foo+4294967277>:	push   %rbp
       0x40110e <foo+4294967278>:	mov    %rsp,%rbp
       0x401111 <foo+4294967281>:	callq  0x401106 <baz>
       0x401116 <foo+4294967286>:	nop
       0x401117 <foo+4294967287>:	pop    %rbp

This commit, in conjuction with an earlier patch from this series, causes
cases like the above to be displayed like this (below) instead:

(gdb) x/5i foo_cold
   0x40110d <foo_cold>:	push   %rbp
   0x40110e <foo-18>:	mov    %rsp,%rbp
   0x401111 <foo-15>:	callq  0x401106 <baz>
   0x401116 <foo-10>:	nop
   0x401117 <foo-9>:	pop    %rbp

Note that the address of foo_cold is now (due to another patch) being
displayed as <foo_cold> instead of <foo+BigOffset>.  The subsequent
lines are shown as negative offsets from foo.

Disassembly using the "disassemble" command is somewhat affected by
these changes:

Before:

(gdb) disassemble foo_cold
Dump of assembler code for function foo:
Address range 0x401120 to 0x40113b:
   0x0000000000401120 <+0>:	push   %rbp
   0x0000000000401121 <+1>:	mov    %rsp,%rbp
   0x0000000000401124 <+4>:	callq  0x401119 <bar>
   0x0000000000401129 <+9>:	mov    0x2ef1(%rip),%eax        # 0x404020 <e>
   0x000000000040112f <+15>:	test   %eax,%eax
   0x0000000000401131 <+17>:	je     0x401138 <foo+24>
   0x0000000000401133 <+19>:	callq  0x40110d <foo+4294967277>
   0x0000000000401138 <+24>:	nop
   0x0000000000401139 <+25>:	pop    %rbp
   0x000000000040113a <+26>:	retq
Address range 0x40110d to 0x401119:
   0x000000000040110d <+-19>:	push   %rbp
   0x000000000040110e <+-18>:	mov    %rsp,%rbp
   0x0000000000401111 <+-15>:	callq  0x401106 <baz>
   0x0000000000401116 <+-10>:	nop
   0x0000000000401117 <+-9>:	pop    %rbp
   0x0000000000401118 <+-8>:	retq
End of assembler dump.

After:

(gdb) disassemble foo_cold
Dump of assembler code for function foo:
Address range 0x401120 to 0x40113b:
   0x0000000000401120 <+0>:	push   %rbp
   0x0000000000401121 <+1>:	mov    %rsp,%rbp
   0x0000000000401124 <+4>:	callq  0x401119 <bar>
   0x0000000000401129 <+9>:	mov    0x2ef1(%rip),%eax        # 0x404020 <e>
   0x000000000040112f <+15>:	test   %eax,%eax
   0x0000000000401131 <+17>:	je     0x401138 <foo+24>
   0x0000000000401133 <+19>:	callq  0x40110d <foo_cold>
   0x0000000000401138 <+24>:	nop
   0x0000000000401139 <+25>:	pop    %rbp
   0x000000000040113a <+26>:	retq
Address range 0x40110d to 0x401119:
   0x000000000040110d <-19>:	push   %rbp
   0x000000000040110e <-18>:	mov    %rsp,%rbp
   0x0000000000401111 <-15>:	callq  0x401106 <baz>
   0x0000000000401116 <-10>:	nop
   0x0000000000401117 <-9>:	pop    %rbp
   0x0000000000401118 <-8>:	retq
End of assembler dump.

Note that negative offsets are now displayed without the leading "+".
Also, the callq to foo_cold is now displayed as such instead of a callq
to foo with a large positive offset.

gdb/ChangeLog:

	* printcmd.c (print_address_symbolic): Print negative offsets.
	(build_address_symbolic): Force signed arithmetic when computing
	offset.
2019-07-30 09:19:13 -07:00
Christian Biesinger 2906593ffe [PR/24474] Add gdb.lookup_static_symbol to the python API
Similar to lookup_global_symbol, except that it checks the
STATIC_SCOPE.

gdb/ChangeLog:

2019-07-30  Christian Biesinger  <cbiesinger@google.com>

	PR/24474: Add a function to lookup static variables.
	* NEWS: Mention this new function.
	* python/py-symbol.c (gdbpy_lookup_static_symbol): New function.
	* python/python-internal.h (gdbpy_lookup_static_symbol): New function.
	* python/python.c (python_GdbMethods): Add new function.

gdb/doc/ChangeLog:

2019-07-30  Christian Biesinger  <cbiesinger@google.com>

	* python.texi (Symbols In Python): Document new function
	gdb.lookup_static_symbol.

gdb/testsuite/ChangeLog:

2019-07-30  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/py-symbol.c: Add a static variable and one in an anonymous
	namespace.
	* gdb.python/py-symbol.exp: Test gdb.lookup_static_symbol.
2019-07-30 11:04:37 -05:00
Christian Biesinger 5c4dde850c Add missing changelog entry
I forgot to commit the change before pushing commit
25ec892484
2019-07-30 10:41:32 -05:00
Tom de Vries 0f575925b6 [gdb/testsuite] Work around tcl bug in libsegfault.exp with check-read1
When running libsegfault.exp with check-read1, I get:
...
Running gdb/testsuite/gdb.base/libsegfault.exp ...
ERROR: tcl error sourcing gdb/testsuite/gdb.base/libsegfault.exp.
ERROR: no such variable
    (read trace on "env(LD_PRELOAD)")
    invoked from within
"set env(LD_PRELOAD)"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 [list set $var]"
    invoked from within
"if [uplevel 1 [list array exists $var]] {
                set saved_arrays($var) [uplevel 1 [list array get $var]]
            } else {
                set saved_scalars($var) [uplevel ..."
    invoked from within
"if [uplevel 1 [list info exists $var]] {
            if [uplevel 1 [list array exists $var]] {
                set saved_arrays($var) [uplevel 1 [list array get $var]]
          ..."
    (procedure "save_vars" line 11)
    invoked from within
"save_vars { env(LD_PRELOAD) } {
        if { ![info exists env(LD_PRELOAD) ]
             || $env(LD_PRELOAD) == "" } {
            set env(LD_PRELOAD) "$lib"
        } else {
         ..."
    (procedure "gdb_spawn_with_ld_preload" line 4)
    invoked from within
"gdb_spawn_with_ld_preload $libsegfault """
...

There are several things here interacting with environment variable
LD_PRELOAD:
- the expect "binary" build/gdb/testsuite/expect-read1 with does
  export LD_PRELOAD=build/gdb/testsuite/read1.so before calling native expect
- read1.so which does unsetenv ("LD_PRELOAD") upon first call to read
- the test-case, which wants to set or append libSegFault.so to LD_PRELOAD

The error occurs when accessing $env(LD_PRELOAD), in a branch where
"info exists env(LD_PRELOAD)" returns true. AFAIU, this is
https://core.tcl-lang.org/tcl/tktview?name=67fd4f973a "incorrect results of
'info exists' when unset env var in one interp and check for existence from
another interp".

Work around the tcl bug by not unsetting the variable, but setting it to ""
instead:
...
-      unsetenv ("LD_PRELOAD");
+      setenv ("LD_PRELOAD", "", 1);
...

Verified that reverting commit de28a3b72e "[gdb/testsuite, 2/2] Fix
gdb.linespec/explicit.exp with check-read1" reintroduced the check-read1
failure in gdb.linespec/explicit.exp.

This fixes a similar error in attach-slow-waitpid.exp, which also sets
LD_PRELOAD.

Tested on x86_64-linux with check-read1.

gdb/testsuite/ChangeLog:

2019-07-30  Tom de Vries  <tdevries@suse.de>

	* lib/read1.c (read): Don't use unsetenv (v), use setenv (v, "", 1)
	instead.
2019-07-30 16:15:46 +02:00
Tom de Vries b13057d9ce [gdb/testsuite] Fail in gdb_compile if nopie results in PIE executable
When running gdb.base/dump.exp with --target_board=unix/-fPIE/-pie, we get:
...
Running gdb/testsuite/gdb.base/dump.exp ...
FAIL: gdb.base/dump.exp: dump array as value, intel hex
...

The FAIL happens because although the test specifies nopie, the exec is
in fact compiled as PIE.  The "-fPIE -pie" options specified using the
target_board are interpreted by dejagnu as multilib_flags, and end up
overriding the nopie flags.

Fix this by checking in gdb_compile if the resulting exec is PIE despite of
a nopie setting, and if so return an error:
...
Running gdb/testsuite/gdb.base/dump.exp ...
gdb compile failed, nopie failed to prevent PIE executable

                === gdb Summary ===

nr of untested testcases         1
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-30  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24834
	* lib/gdb.exp (gdb_compile): Fail if nopie results in PIE executable.
	(exec_is_pie): New proc.
2019-07-30 09:42:07 +02:00
Christian Biesinger 25ec892484 Fix misspelling (nonexistant -> nonexistent)
gdb/testsuite/ChangeLog:

2019-07-29  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/py-objfile.exp: Fix misspelling (nonexistant -> nonexistent)
2019-07-29 21:01:13 -05:00
Christian Biesinger c620ed8866 Add Objfile.lookup_{global,static}_symbol functions
This is essentially the inverse of Symbol.objfile. This allows
handling different symbols with the same name (but from different
objfiles) and can also be faster if the objfile is known.

gdb/ChangeLog:

2019-07-29  Christian Biesinger  <cbiesinger@google.com>

	* NEWS: Mention new functions Objfile.lookup_{global,static}_symbol.
	* python/py-objfile.c (objfpy_lookup_global_symbol): New function.
	(objfpy_lookup_static_symbol): New function.
	(objfile_object_methods): Add new functions.

gdb/doc/ChangeLog:

2019-07-29  Christian Biesinger  <cbiesinger@google.com>

	* python.texi (Objfiles In Python): Document new functions
	  Objfile.lookup_{global,static}_symbol.

gdb/testsuite/ChangeLog:

2019-07-29  Christian Biesinger  <cbiesinger@google.com>

	* gdb.python/py-objfile.c: Add global and static vars.
	* gdb.python/py-objfile.exp: Test new functions Objfile.
	  lookup_global_symbol and lookup_static_symbol.
2019-07-29 20:44:08 -05:00
Tom Tromey 3d2357068b Two fixes for test suite's terminal
Exactly which escape sequences are emitted by gdb in TUI mode are
determined largely by the curses implementation.  Testing my latest
(as yet unsubmitted) series to refactor the TUI showed a couple of
failures that I tracked to the test suite's terminal implementation.

In particular, the CSI "@" sequence was not implemented; and the CSI
"X" sequence was implemented incorrectly.

This patch fixes both of these problems.  Tested on x86-64 Fedora 28.

gdb/testsuite/ChangeLog
2019-07-29  Tom Tromey  <tom@tromey.com>

	* lib/tuiterm.exp (Term::_csi_@): New proc.
	(Term::_csi_X): Don't move cursor.
2019-07-29 16:06:58 -06:00
Philippe Waroquiers bc4268a5d9 Document 'set print frame-info|frame-arguments presence'.
gdb/ChangeLog
2019-06-19  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Mention 'set|show print frame-info'.  Mention new
	'presence' value for 'frame-arguments'.  Mention new '-frame-info'
	backtrace argument.  Mention that python frame filtering code
	is now consistent with what 'backtrace' command prints.

gdb/doc/ChangeLog
2019-07-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Backtrace): Document the new '-frame-info'
	backtrace option.  Reference 'set print frame-info'.
	(Print Settings): Document 'set|show print frame-info'.
	Document new 'presence' value for 'set print frame-arguments.
2019-07-29 21:43:08 +02:00
Philippe Waroquiers c7e4c0a648 Test 'set print frame-info|frame-arguments presence'.
Updated tests to test the new options and new values.
Test the default for print_what in python frame filtering.
Updated the tests impacted by the default in python frame filtering
which is now consistent with the backtrace command.

gdb/testsuite/ChangeLog
2019-07-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/options.exp: Update backtrace - completion to
	new option -frame-info.
	* gdb.base/frame-args.exp: Test new 'frame-arguments presence'.
	Test new 'set print frame-info'.  Test backtrace -frame-info
	overriding 'set print frame-info'.
	* gdb.python/py-framefilter.exp: Test new 'frame-arguments presence'.
	Test new 'set print frame-info'.
	Verify consistency of backtrace with and without filters, with and
	without -no-filters.
	* gdb.python/py-framefilter-invalidarg.exp: Update to new print_what
	default.
2019-07-29 21:42:52 +02:00
Philippe Waroquiers 4b5e8d19af Implement 'set print frame-info|frame-arguments presence'.
New settings allow to better control what frame information is printed.

'set print frame-info' allows to override the default frame information
printed when a GDB command prints a frame.
The backtrace command has a new option -frame-info to override
this global setting.

It is now possible to have very short frame information by using the
new 'set print frame-arguments presence' and
'set print frame-info short-location'.

Combined with 'set print address off', a backtrace will only show
the essential information to see the function call chain, e.g.:
  (gdb) set print address off
  (gdb) set print frame-arguments presence
  (gdb) set print frame-info short-location
  (gdb) bt
  #0  break_me ()
  #1  call_me (...)
  #2  main ()
  (gdb)

This is handy in particular for big backtraces with functions having
many arguments.

Python frame filter printing logic has been updated to respect the new
setting in non MI mode.

Also, the default frame information printed was inconsistent when
backtrace was printing the frame information itself, or when the python
frame filtering code was printing the frame information.
This patch changes the default of python frame filtering to have a
consistent behaviour regarding printed frame-information, whatever
the presence/activity/matches of python filters.

2019-07-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* frame.h (enum print_what): New value 'SHORT_LOCATION', update
	comments.
	(print_frame_info_auto, print_frame_info_source_line,
	print_frame_info_location, print_frame_info_source_and_location,
	print_frame_info_location_and_address, print_frame_info_short_location):
	New declarations.
	(struct frame_print_options): New member print_frame_info.
	* extension.h (enum ext_lang_frame_args): New value CLI_PRESENCE.
	* stack.h (get_user_print_what_frame_info): New declaration.
	(frame_show_address): New declaration.
	* stack.c (print_frame_arguments_choices): New value 'presence'.
	(print_frame_info_auto, print_frame_info_source_line,
	print_frame_info_location, print_frame_info_source_and_location,
	print_frame_info_location_and_address, print_frame_info_short_location,
	print_frame_info_choices, print_frame_info_print_what): New definitions.
	(print_frame_args): Only print dots for args if print frame-arguments
	is 'presence'.
	(frame_print_option_defs): New element for "frame-info".
	(get_user_print_what_frame_info): New function.
	(frame_show_address): Make non static.  Move comment to stack.h.
	(print_frame_info_to_print_what): New function.
	(print_frame_info): Update comment.  Use fp_opts.print_frame_info
	to decide what to print.
	(backtrace_command_1): Handle the new print_frame_arguments_presence
	value.
	(_initialize_stack): Call add_setshow_enum_cmd for frame-info.
	* python/py-framefilter.c (py_print_args): Handle CLI_PRESENCE.
	(py_print_frame): In non-mi mode, use LOCATION as default for
	print_what, similarly to frame information printed directly by
	backtrace command. Handle frame-info user option in non MI mode.
2019-07-29 21:42:29 +02:00
Tom de Vries de28a3b72e [gdb/testsuite, 2/2] Fix gdb.linespec/explicit.exp with check-read1
When running gdb.linespec/explicit.exp with check-read1, we get:
...
(gdb) PASS: gdb.linespec/explicit.exp: set max-completions unlimited
break 
-function
  ...
top
(gdb) PASS: gdb.linespec/explicit.exp: complete with no arguments
break
-function
 ...
top
(gdb) FAIL: gdb.linespec/explicit.exp: complete with no arguments (clearing input line)
...

The problem is that the send_gdb "\t\t" triggers completion twice:
...
        set tst "complete with no arguments"
        send_gdb "break \t"
        gdb_test_multiple "" $tst {
            "break \\\x07" {
                send_gdb "\t\t"
                gdb_test_multiple "" $tst {
	...
	}
	clear_input_line $tst
...
but the following gdb_test_multiple only parses it once, so the second
completion is left for clear_input_line, which fails.

Fix this by triggering completion only once.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* gdb.linespec/explicit.exp: Fix completion trigger for "complete with
	no arguments".
2019-07-29 16:24:57 +02:00
Tom de Vries 507dd60e28 [gdb/testsuite, 1/2] Fix gdb.linespec/explicit.exp with check-read1
When running gdb.linespec/explicit.exp with check-read1, we get:
...
(gdb) PASS: gdb.linespec/explicit.exp: complete unique file name: break -source "3explicit.c"
break -source exp^Glicit^G^M
explicit.c   explicit2.c  ^M
(gdb) FAIL: gdb.linespec/explicit.exp: complete non-unique file name
...

The problem is that we have a gdb_test_multiple where we match two regexps:
...
        set tst "complete non-unique file name"
        send_gdb "break -source exp\t"
        gdb_test_multiple "" $tst {
            -re "break -source exp\\\x07licit" {
                ...
            }

            -re "break -source exp\\\x07l" {
                # This pattern may occur when glibc debuginfo is installed.
		...
            }
        }
...
but since second is a substring of the first, we'll usually match the first,
but with check-read1 we'll match the second.

Fix this by using a single regexp and merging the related code.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* gdb.linespec/explicit.exp: Fix gdb_test_multiple regexps where second
	is a substring of the first for "complete non-unique file name".
2019-07-29 16:24:57 +02:00
Tom de Vries 5beafce944 [gdb/testsuite] Fix python.exp with check-read1
when running python/python.exp with check-read1, we get:
...
(gdb) PASS: gdb.python/python.exp: prompt substitution readline - end
python gdb.prompt_hook = error_prompt^M
Python Exception <type 'exceptions.RuntimeError'> Python exception calledPASS: gdb.python/python.exp: set hook
: ^M
(gdb) PASS: gdb.python/python.exp: set the hook to default
python gdb.prompt_hook = None^M
(gdb) PASS: gdb.python/python.exp: set print-stack full for prompt error test
set python print-stack full^M
(gdb) FAIL: gdb.python/python.exp: set the hook
python gdb.prompt_hook = error_prompt^M
Traceback (most recent call last):^M
  File "<string>", line 3, in error_prompt^M
RuntimeError: Python exception called^M
(gdb) FAIL: gdb.python/python.exp: set the hook to default
...

The problem is that gdb_test_multiple here:
...
gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
    -re "Python Exception (exceptions.RuntimeError|<(type 'exceptions.|class ')RuntimeError'>) Python excepti
on called.*" {
       pass "set hook"
    }
}
...
specifies a regexp that ends with ".*" but doesn't specify the expected
$gdb_prompt.

Consequently, due to check-read1, the ".*" is matched to "" and the remaining
$gdb_prompt  is read by the the following gdb_py_test_silent_cmd, which has
its own $gdb_prompt read by the following gdb_py_test_silent_cmd, which has
its own $gdb_prompt causing a mismatch for the following gdb_test_multiple:
...
gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" {
    -re "Traceback.*File.*line.*RuntimeError.*Python exception called.*" {
        pass "set hook"
    }
}
...
which causes both FAILs.

The second gdb_test_multiple has the same problem as the first, but it happens
not to cause a FAIL because it's followed by a gdb_py_test_silent_cmd and a
clean_restart.

Fix the regexps in both gdb_test_multiple calls.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* gdb.python/python.exp: Don't terminate gdb_test_multiple regexp
	with ".*".
2019-07-29 15:07:47 +02:00
Tom de Vries 2d274232f3 [gdb/testsuite] Fix mi-catch-cpp-exceptions.exp and mi-nonstop.exp with check-read1
With check-read1 we get:
...
FAIL: gdb.mi/mi-catch-cpp-exceptions.exp: check for stap probe in libstdc++
FAIL: gdb.mi/mi-nonstop.exp: probe for target remote
...

In both cases this is due to using gdb_test_multiple (which expects $gdb_prompt
by default) in combination with gdb using $gdb_mi_prompt, similar to the
problem fixed by commit d17725d72f "Don't expect gdb_prompt in
mi_skip_python_test".

Fix this by adding the $prompt_regexp argument to the gdb_test_multiple calls.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (skip_libstdcxx_probe_tests_prompt, gdb_is_target_1):
	Pass prompt_regexp parameter to gdb_test_multiple calls.
2019-07-29 14:11:13 +02:00
Tom de Vries 9197cd8b52 [gdb/testsuite] Fix gdb.base/maint.exp with check-read1
With gdb.base/maint.exp and check-read1, we get:
...
FAIL: gdb.base/maint.exp: maint print registers
...

Using this patch:
...
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index a7675ea215..b81d7ec660 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -81,7 +81,9 @@ gdb_test_multiple $test $test {
         exp_continue
     }
     -re "$gdb_prompt $" {
-        gdb_assert { $saw_registers && $saw_headers } $test
+       gdb_assert { $saw_headers } "$test: saw headers"
+       gdb_assert { $saw_registers } "$test: saw registers"
+       pass "$test: got prompt"
     }
 }
...

We get more information:
...
PASS: gdb.base/maint.exp: maint print registers: saw headers
FAIL: gdb.base/maint.exp: maint print registers: saw registers
PASS: gdb.base/maint.exp: maint print registers: got prompt
...

The problem is that when matching:
...
(gdb) maint print registers^M
 Name         Nr  Rel Offset    Size  Type            ^M
 rax           0    0      0       8 int64_t         ^M
...
the regexp for $saw_headers ends in "\[\r\n\]+", which
allows it to match only the "\r".  The remaining "\n" then start the next line
to be matched, which doesn't match for the $saw_registers regexp since it
starts with "^\[^\r\n\]+".

Fix this by ending the regexps with "\r\n".

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* gdb.base/maint.exp: Use "\r\n" instead of "\[\r\n\]+" in "maint
          print registers" regexps.
2019-07-29 11:24:04 +02:00
Tom de Vries b528dae095 [gdb/testsuite] Fix gdb.base/define.exp with check-read1
When running gdb.base/define.exp with check-read1, we get:
...
show prompt^M
Gdb's prompt is "(gdb) ".^M
(gdb) PASS: gdb.base/define.exp: save gdb_prompt
set prompt \(blah\) ^M
(blah) PASS: gdb.base/define.exp: set gdb_prompt
set prompt (gdb) PASS: gdb.base/define.exp: reset gdb_prompt
^M
(gdb) FAIL: gdb.base/define.exp: define do-define
...

The problem is that the "$gdb_prompt $" regexp here:
...
gdb_test_multiple "set prompt $prior_prompt " "reset gdb_prompt" {
    -re "$gdb_prompt $" {
        pass "reset gdb_prompt"
    }
}
...
triggers for the echoing of the command "set prompt $prior_prompt " rather
than for the prompt after the command has executed.

Fix this by changing the regexp to "\r\n$gdb_prompt $".

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	* gdb.base/define.exp: Add "\r\n" to "reset gdb_prompt" regexp.
2019-07-29 11:24:04 +02:00
Tom de Vries d17725d72f [gdb/testsuite] Don't expect gdb_prompt in mi_skip_python_test
When running gdb.python/py-mi-events.exp with make check-read1, we get:
...
(gdb) ^M
python print ('test')^M
&"python print ('test')\n"^M
~"test\n"^M
^done^M
(gdb) FAIL: gdb.python/py-mi-events.exp: verify python support
^M
python print (sys.version_info[0])^M
&"python print (sys.version_info[0])\n"^M
~"2\n"^M
^done^M
(gdb) FAIL: gdb.python/py-mi-events.exp: check if python 3
^M
...

The FAILs happen as follows.

On one hand, skip_python_tests_prompt uses the prompt_regexp parameter for the
user_code argument of gdb_test_multiple:
...
proc skip_python_tests_prompt { prompt_regexp } {
    global gdb_py_is_py3k

    gdb_test_multiple "python print ('test')" "verify python support" {
	-re "not supported.*$prompt_regexp" {
	    unsupported "Python support is disabled."
	    return 1
	}
	-re "$prompt_regexp" {}
    }

    gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
	-re "3.*$prompt_regexp" {
            set gdb_py_is_py3k 1
        }
	-re ".*$prompt_regexp" {
            set gdb_py_is_py3k 0
        }
    }
...

On the other hand, gdb_test_multiple itself uses $gdb_prompt:
...
         -re "\r\n$gdb_prompt $" {
            if ![string match "" $message] then {
                fail "$message"
            }
            set result 1
        }
...

So when mi_skip_python_test calls skip_python_tests_prompt with prompt_regexp
set to $mi_gdb_prompt:
...
proc mi_skip_python_tests {} {
    global mi_gdb_prompt
    return [skip_python_tests_prompt "$mi_gdb_prompt$"]
}
...
and expect reads "(gdb) " and tries to match it (due to the READ1=1 setting),
the user_code regexps using $prompt_regexp (set to $mi_gdb_prompt) don't match,
but the $gdb_prompt regexp in gdb_test_multiple does match.

Fix this by adding a prompt_regexp parameter to gdb_test_multiple, and using the
parameter in skip_python_tests_prompt.

Tested gdb.python/py-mi-events.exp with make check READ1=1 x86_64-linux.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-29  Tom de Vries  <tdevries@suse.de>

	PR gdb/24855
	* lib/gdb.exp (gdb_test_multiple): Add prompt_regexp parameter.
	(skip_python_tests_prompt): Add prompt_regexp argument to
	gdb_test_multiple calls.
2019-07-29 11:24:04 +02:00
Tom Tromey 52b75bf1dc Add test that "file" shows "main"
This adds a new test that checks that the "file" command will show the
program's "main".

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* gdb.tui/main.exp: New file.
2019-07-27 21:08:36 -06:00
Tom Tromey 2b1d00c2b8 Add test case for empty TUI windows
My original intent here was to add a test case to test that empty TUI
windows re-render their contents after a resize.  However, this seems
pretty broken at the moment, so a lot of the test is actually
disabled.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* lib/tuiterm.exp (Term::clean_restart): Make "executable"
	optional.
	* gdb.tui/empty.exp: New file.
2019-07-27 21:08:35 -06:00
Tom Tromey ded631d57d Add TUI resizing test
This adds a test case that resizes the terminal and then checks that
the TUI updates properly.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* lib/tuiterm.exp (spawn): New proc.
	(Term::resize): New proc.
	* gdb.tui/resize.exp: New file.
2019-07-27 21:08:35 -06:00
Tom Tromey 58ac439d38 Add TUI test for "list"
This adds a test to check that the "list" command will update the TUI
source window.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* gdb.tui/list.exp: New file.
2019-07-27 21:08:34 -06:00
Tom Tromey fe1f56ee14 Add TUI register window test
This adds a very simple test of the TUI register window.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* gdb.tui/regs.exp: New file.
2019-07-27 21:08:34 -06:00
Tom Tromey f790b310d2 Add "layout split" test
This adds a test of "layout split" to the TUI test suite.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* gdb.tui/basic.exp: Add "layout split" test.
2019-07-27 21:08:33 -06:00
Tom Tromey d95fc6eec0 Add test for "layout asm"
This adds a very simple test for "layout asm".

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* gdb.tui/basic.exp: Add "layout asm" test.
2019-07-27 21:08:33 -06:00
Tom Tromey c3786b3aa3 A virtual terminal for the test suite
This patch implements a simple ANSI terminal emulator for the test
suite.  It is still quite basic, but it is good enough to allow some
simple TUI testing to be done.

gdb/testsuite/ChangeLog
2019-07-27  Tom Tromey  <tom@tromey.com>

	* lib/tuiterm.exp: New file.
	* gdb.tui/basic.exp: New file.
2019-07-27 21:08:32 -06:00
Kevin Buettner 6bdfee8157 Fix gdb.python/py-thrhandle.exp failures for -m32 multilib
This patch fixes the following failures when testing with
"target_board unix/-m32" using a x86_64-pc-linux-gnu native GDB.

FAIL: gdb.python/py-thrhandle.exp: print thread for bogus handle thrs[3]
FAIL: gdb.python/py-thrhandle.exp: print thread for bogus handle thrs[4]
FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[0]
FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[1]
FAIL: gdb.python/py-thrhandle.exp: print thread id for thrs[2]
FAIL: gdb.python/py-thrhandle.exp: thread 0: fetch thread handle from thread
FAIL: gdb.python/py-thrhandle.exp: thread 0: verify that handles are the same
FAIL: gdb.python/py-thrhandle.exp: thread 1: fetch thread handle from thread
FAIL: gdb.python/py-thrhandle.exp: thread 1: verify that handles are the same
FAIL: gdb.python/py-thrhandle.exp: thread 2: fetch thread handle from thread
FAIL: gdb.python/py-thrhandle.exp: thread 2: verify that handles are the same

I've written it so that it might work for other 64-bit host / 32-bit target
combos too.

gdb/ChangeLog:

	* linux-thread-db.c (thread_db_target::thread_handle_to_thread_info):
	Add case for debugging 32-bit target on 64-bit host.  Revise
	comment.
2019-07-27 13:52:45 -07:00
Kevin Buettner 98a617f8d5 Fix stepping bug associated with non-contiguous blocks
I recently noticed the following behavior while debugging
dw2-ranges-func-low-cold.  This is one of the test programs associated
with the test gdb.dwarf2/dw2-ranges-func.exp.

(gdb) b 70
Breakpoint 1 at 0x401129: file dw2-ranges-func-lo-cold.c, line 70.
(gdb) run
Starting program: dw2-ranges-func-lo-cold

Breakpoint 1, foo ()
    at dw2-ranges-func-lo-cold.c:70
70	  if (e) foo_cold ();				/* foo foo_cold call */
(gdb) set var e=1
(gdb) step
[Inferior 1 (process 12545) exited normally]

This is incorrect.  When stepping, we expect a step to occur.  We do not
expect the program to exit.  Instead, we should see the following behavior:

...
(gdb) set var e=1
(gdb) step
foo ()
    at dw2-ranges-func-lo-cold.c:54
54	  baz ();					/* foo_cold baz call */

(Note that I've shortened the paths in the above sessions to improve
readability.)

The bug is in fill_in_stop_func() in infrun.c.  While working on
non-contiguous address range improvements in 2018, I replaced the
call to find_pc_partial_function() with a call to
find_function_entry_range_from_pc().  Although this seemed like the
right thing to do at the time, I now think that calling
find_pc_partial_function (along with some other tweaks) is the right
thing to do.

For blocks with a single contiguous range, these functions do pretty
much the same thing: when the function succeeds, the function name,
start address, and end address are all filled in.  Additionally,
find_pc_partial_function contains an additional output parameter
which is set to the block containing that PC.

For blocks with non-contiguous ranges, find_pc_partial_function
sets the start and end addresses to the start and end addresses
of the range containing the pc.  find_function_entry_range_from_pc
does what it says; it sets the start and end addresses to those
of the range containing the entry pc.

The reason that I had thought that using the entry pc range was
correct is due to the fact that fill_in_stop_func() contains some
code for advancing past the function start and entry point.  To do
this, we'd need the range that contains the entry pc.

However, when stepping, we actually want the range that contains the
stop pc.  If that range also contains the entry pc, we should then
attempt to advance stop_func_start past the start offset and entry
point.  (I haven't thought very hard about the reason for advancing
the stop_func_start in this manner.  Since it's been there for quite
a while, I'm assuming that it's still a good idea.)

Back when I wrote the test case, I had included a test for doing the
step shown in the example above.  I had problems with it, however.  At
the time, I thought it was due to differing compiler versions, so I
disabled that portion of the test.  I have now reenabled those tests,
but have left in place the logic which may be used to disable it.

The changes to dw2-ranges-func.exp depend on my other recent changes
to the file which have not been pushed yet.

Finally, I'll note that the only caller of
find_function_entry_range_from_pc() is/was fill_in_stop_func().  Once
this commit goes in, it'll be dead code.  I considered removing it,
but I think that it ought to be used (instead of
find_pc_partial_function) for determining the correct range to scan
for prologue analysis, so I'm going to leave it in place for now.

gdb/ChangeLog:

	* infrun.c (fill_in_stop_func): Use find_pc_partial_function
	instead of find_function_entry_range_from_pc.

testsuite/ChangeLog:

	* gdb.dwarf2/dw2-ranges-func.exp (enable_foo_cold_stepping):
	Enable tests associated with this flag.  Adjust regex
	referencing "foo_low" to now refer to "foo_cold" instead.
2019-07-27 13:43:10 -07:00
Kevin Buettner 5c076da45c Improve test gdb.dwarf2/dw2-ranges-func.exp
The original dw2-ranges-func.exp test caused a function named foo to be
created with two non-contiguous address ranges.  In the C source file,
a function named foo_low was incorporated into the function foo which
was also defined in that file.  The DWARF assembler is used to do this
manipulation.  The source file had been laid out so that foo_low would
likely be placed (by the compiler and linker) at a lower address than
foo().

The case where a range at a higher set of addresses (than foo) was not
being tested.  In a recent discussion on gdb-patches, it became clear
that performing such tests are desirable because bugs were discovered
which only became evident when the other range was located at high(er)
addresses than the range containing the entry point for the function.

This other (non entry pc) address range is typically used for "cold"
code which executes less frequently.  Thus, I renamed foo_low to
foo_cold and renamed the C source file from dw-ranges-func.c to
dw-ranges-func-lo.c.  I then made a copy of this file, naming it
dw-ranges-func-hi.c.  (That was my intent anyway.  According to git,
I renamed dw-ranges-func.c to dw-ranges-func-hi.c and then modified it.
dw-ranges-func-lo.c shows up as an entirely new file.)

Within dw-ranges-func-hi.c, I changed the placement of foo_cold()
along with some of the other functions so that foo_cold() would be at
a higher address than foo() while also remaining non-contiguous.  The
two files, dw-ranges-func-lo.c and dw-ranges-func-hi.c, are
essentially the same except for the placement of some of the functions
therein.

The tests in dw2-ranges-func.exp where then wrapped in a new proc named
do_test which was then called in a loop from the outermost level.  The
loop causes each of the source files to have the same tests run upon
them.

I also added a few new tests which test functionality fixed by the other
commits to this patch series.  Due to the reorganization of the file,
it's hard to identify these changes in the patch.  So, here are the
tests which were added:

    with_test_prefix "no-cold-names" {

	# Due to the calling sequence, this backtrace would normally
	# show function foo_cold for frame #1.  However, we don't want
	# this to be the case due to placing it in the same block
	# (albeit at a different range) as foo.  Thus it is correct to
	# see foo for frames #1 and #2.  It is incorrect to see
	# foo_cold at frame #1.
	gdb_test_sequence "bt" "backtrace from baz" {
	    "\[\r\n\]#0 .*? baz \\(\\) "
	    "\[\r\n\]#1 .*? foo \\(\\) "
	    "\[\r\n\]#2 .*? foo \\(\\) "
	    "\[\r\n\]#3 .*? main \\(\\) "
	}

	# Doing x/2i foo_cold should show foo_cold as the first symbolic
	# address and an offset from foo for the second.  We also check to
	# make sure that the offset is not too large - we don't GDB to
	# display really large offsets that would (try to) wrap around the
	# address space.
	set foo_cold_offset 0
	set test "x/2i foo_cold"
	gdb_test_multiple $test $test {
	    -re "   (?:$hex) <foo_cold>.*?\n   (?:$hex) <foo\[+-\](\[0-9\]+)>.*${gdb_prompt}" {
	        set foo_cold_offset $expect_out(1,string)
		pass $test
	    }
	}
	gdb_assert {$foo_cold_offset <= 10000} "offset to foo_cold is not too large"

	# Likewise, verify that second address shown by "info line" is at
	# and offset from foo instead of foo_cold.
	gdb_test "info line *foo_cold" "starts at address $hex <foo_cold> and ends at $hex <foo\[+-\].*?>.*"

    }

When run against a GDB without the requisite bug fixes (from this patch
series), these 6 failures should be seen:

FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: no-cold-names: backtrace from baz (pattern 4)
FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: no-cold-names: x/2i foo_cold
FAIL: gdb.dwarf2/dw2-ranges-func.exp: lo-cold: no-cold-names: info line *foo_cold
FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: no-cold-names: backtrace from baz (pattern 3)
FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: no-cold-names: x/2i foo_cold
FAIL: gdb.dwarf2/dw2-ranges-func.exp: hi-cold: no-cold-names: info line *foo_cold

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-ranges-func.c: Rename to...
	* gdb.dwarf2/dw2-ranges-func-lo-cold.c: ...this.
	* gdb.dwarf2/dw2-ranges-func-lo-cold.c (foo_low): Change name to
	foo_cold.  Revise comments to match.
	* gdb.dwarf2/dw2-ranges-func-hi-cold.c: New file.
	* gdb.dwarf2/dw2-ranges-func.exp (do_test): New proc. Existing tests
	were wrapped into this proc; Call do_test in loop from outermost
	level.
	(foo_low): Rename all occurrences to "foo_cold".
	(backtrace from baz): New test.
	(x2/i foo_cold): New test.
	(info line *foo_cold): New test.
2019-07-27 13:38:44 -07:00
Kevin Buettner 1aff717310 dwarf2-frame.c: Fix FDE processing bug involving non-contiguous ranges
In the course of revising the test case for
gdb.dwarf2/dw2-ranges-func.exp, I added a new .c file which would
cause the "cold" range to be at a higher address than the rest of the
function.  In these tests, the range in question isn't really cold in
the sense that a compiler has determined that it'll be executed less
frequently.  Instead, it's simply the range that does not include the
entry pc.  These tests are intended to mimic the output of such a
compiler, so I'll continue to refer to this range as "cold" in the
following discussion.

The original test case had only tested a cold range placed
at lower addresses than the rest of the function.  During testing of the
new code where the cold range was placed at higher addresses, I found
that I could produce the following backtrace:

    (gdb) bt
    #0  0x0000000000401138 in baz ()
	at dw2-ranges-func-hi-cold.c:72
    #1  0x0000000000401131 in foo_cold ()
	at dw2-ranges-func-hi-cold.c:64
    #2  0x000000000040111e in foo ()
	at dw2-ranges-func-hi-cold.c:50
    #3  0x0000000000401144 in main ()
	at dw2-ranges-func-hi-cold.c:78

This is correct, except that we'd like to see foo() listed instead
of foo_cold().  (I handle that problem in another patch.)

Now look at what happens for a similar backtrace where the cold range
is at a lower address than the foo's entry pc:

    (gdb) bt
    #0  0x000000000040110a in baz ()
	at dw2-ranges-func-lo-cold.c:48
    #1  0x0000000000401116 in foo ()
	at dw2-ranges-func-lo-cold.c:54
    #2  0x00007fffffffd4c0 in ?? ()
    #3  0x0000000000401138 in foo ()
	at dw2-ranges-func-lo-cold.c:70

Note that the backtrace doesn't go all the way back to main().  Moreover,
frame #2 is messed up.

I had seen this behavior when I had worked on the non-contiguous
address problem last year.  At the time I convinced myself that the
mangled backtrace was "okay" since we're doing strange things with
the DWARF assembler.  We're taking a function called foo_cold (though
it was originally called foo_low - my recent changes to the test case
changed the name) and via the magic of the DWARF assembler, we're
combining it into a separate (non-contiguous) range for foo.  Thus,
it was a surprise to me when I got a good and complete backtrace when
the cold symbol is placed at an address that's greater than entry pc.

The function dwarf2_frame_cache (in dwarf2-frame.c) is making this
call:

    if (get_frame_func_if_available (this_frame, &entry_pc)) ...

If that call succeeds (returns a true value), the FDE is then
processed up to the entry pc.  It doesn't make sense to do this,
however, when the FDE in question does not contain the entry pc.  This
can happen when the function in question is comprised of more than one
(non-contiguous) address range.

My fix is to add some comparisons to the test above to ensure that
ENTRY_PC is within the address range covered by the FDE.

gdb/ChangeLog:

	* dwarf2-frame.c (dwarf2_frame_cache): Don't decode FDE instructions
	for entry pc when entry pc is out of range for that FDE.
2019-07-27 13:35:53 -07:00
Kevin Buettner 2dc80cf8a5 Restrict use of minsym names when printing addresses in disassembled code
build_address_symbolic contains some code which causes it to
prefer the minsym over the the function symbol in certain cases.
The cases where this occurs are the same as the "certain pathological
cases" that used to exist in find_frame_funname().

This commit largely disables that code; it will only prefer the
minsym when the address of minsym is identical to that of the address
under consideration AND the function address for the symbtab sym is
not the same as the address under consideration.

So, without this change, when using the dw2-ranges-func-lo-cold
executable from the gdb.dwarf2/dw2-ranges-func.exp test, GDB exhibits
the following behavior:

(gdb) x/5i foo_cold
   0x40110d <foo+4294967277>:	push   %rbp
   0x40110e <foo+4294967278>:	mov    %rsp,%rbp
   0x401111 <foo+4294967281>:	callq  0x401106 <baz>
   0x401116 <foo+4294967286>:	nop
   0x401117 <foo+4294967287>:	pop    %rbp

On the other hand, still without this change, using the
dw2-ranges-func-hi-cold executable from the same test, GDB
does this instead:

(gdb) x/5i foo_cold
   0x401128 <foo_cold>:	push   %rbp
   0x401129 <foo_cold+1>:	mov    %rsp,%rbp
   0x40112c <foo_cold+4>:	callq  0x401134 <baz>
   0x401131 <foo_cold+9>:	nop
   0x401132 <foo_cold+10>:	pop    %rbp

This is inconsistent behavior.  When foo_cold is at a lower
address than the function's entry point, the symtab symbol (foo)
is displayed along with a large positive offset which would wrap
around the address space if the address space were only 32 bits wide.
(A later patch fixes this problem by displaying negative offsets.)

This commit makes the behavior uniform for both the "lo-cold" and
"hi-cold" cases:

lo-cold:

(gdb) x/5i foo_cold
   0x40110d <foo_cold>:	push   %rbp
   0x40110e <foo-18>:	mov    %rsp,%rbp
   0x401111 <foo-15>:	callq  0x401106 <baz>
   0x401116 <foo-10>:	nop
   0x401117 <foo-9>:	pop    %rbp

hi-cold:

(gdb) x/5i foo_cold
   0x401128 <foo_cold>:	push   %rbp
   0x401129 <foo+35>:	mov    %rsp,%rbp
   0x40112c <foo+38>:	callq  0x401134 <baz>
   0x401131 <foo+43>:	nop
   0x401132 <foo+44>:	pop    %rbp

In both cases, the symbol shown for the address at which foo_cold
resides is shown as <foo_cold>.  Subsequent offsets are shown as
either negative or positive offsets from the entry pc for foo.

When disassembling a function, care must be taken to NOT display
<+0> as the offset for the second range.  For this reason, I found
it necessary to add the "prefer_sym_over_minsym" parameter to
build_address_symbolic.  The type of this flag is a bool; do_demangle
ought to be a bool also, so I made this change at the same time.

gdb/ChangeLog:

	* valprint.h (build_address_symbolic): Add "prefer_sym_over_minsym"
	parameter.  Change type of "do_demangle" to bool.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Pass suitable "prefer_sym_over_minsym" flag to
	build_address_symbolic().  Don't output "+" for negative offsets.
	* printcmd.c (print_address_symbolic): Update invocation of
	build_address_symbolic to include a "prefer_sym_over_minsym"
	flag.
	(build_address_symbolic): Add "prefer_sym_over_minsym" parameter.
	Restrict cases in which use of minimal symbol is preferred to that
	of a found symbol.  Update comments.
2019-07-27 13:28:56 -07:00
Kevin Buettner 567238c956 Prefer symtab symbol over minsym for function names in non-contiguous blocks
The discussion on gdb-patches which led to this patch may be found
here:

https://www.sourceware.org/ml/gdb-patches/2019-05/msg00018.html

Here's a brief synopsis/analysis:

Eli Zaretskii, while debugging a Windows emacs executable, found
that functions comprised of more than one (non-contiguous)
address range were not being displayed correctly in a backtrace.  This
is the example that Eli provided:

  (gdb) bt
  #0  0x76a63227 in KERNELBASE!DebugBreak ()
     from C:\Windows\syswow64\KernelBase.dll
  #1  0x012e7b89 in emacs_abort () at w32fns.c:10768
  #2  0x012e1f3b in print_vectorlike.cold () at print.c:1824
  #3  0x011d2dec in print_object (obj=<optimized out>, printcharfun=XIL(0),
      escapeflag=true) at print.c:2150

The function print_vectorlike consists of two address ranges, one of
which contains "cold" code which is expected to not execute very often.
There is a minimal symbol, print_vectorlike.cold.65, which is the address
of the "cold" range.

GDB is prefering this minsym over the the name provided by the
DWARF info due to some really old code in GDB which handles
"certain pathological cases".  This comment reads as follows:

      /* In certain pathological cases, the symtabs give the wrong
	 function (when we are in the first function in a file which
	 is compiled without debugging symbols, the previous function
	 is compiled with debugging symbols, and the "foo.o" symbol
	 that is supposed to tell us where the file with debugging
	 symbols ends has been truncated by ar because it is longer
	 than 15 characters).  This also occurs if the user uses asm()
	 to create a function but not stabs for it (in a file compiled
	 with -g).

	 So look in the minimal symbol tables as well, and if it comes
	 up with a larger address for the function use that instead.
	 I don't think this can ever cause any problems; there
	 shouldn't be any minimal symbols in the middle of a function;
	 if this is ever changed many parts of GDB will need to be
	 changed (and we'll create a find_pc_minimal_function or some
	 such).  */

In an earlier version of this patch, I had left the code for the
pathological case intact, but those who reviwed that patch recommended
removing it.  So that's what I've done - I've removed it.

gdb/ChangeLog:

	* stack.c (find_frame_funname): Remove code which preferred
	minsym over symtab sym in "certain pathological cases".
2019-07-27 13:26:46 -07:00
Brian Callahan 89b085acaf Fix return type typo in obsd-nat.c that breaks build on OpenBSD
To recap the bug report:
Commit a068643 introduced a small typo that breaks the gdb build on OpenBSD.
Line 38 of obsd-nat.c needs to be changed from std::sring to std::string.

gdb/ChangeLog
2019-07-26  Brian Callahan  <bcallah@openbsd.org>

	PR gdb/24839:
	* gdb/obsd-nat.c (obsd_nat_target::pid_to_str): Fix typo in return
	type.
2019-07-26 15:04:41 -06:00
Tom de Vries 1512d3b7b9 [gdb/testsuite] Fix unterminated string in i386-pkru.exp
I ran into this error:
...
ERROR: tcl error sourcing gdb/testsuite/gdb.arch/i386-pkru.exp.
ERROR: missing "
    while executing
"untested ""
    invoked from within
"if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
     [list debug additional_flags=${comp_flags}]] } {
    untested "failed to c..."
    (file "gdb/testsuite/gdb.arch/i386-pkru.exp" line 25)
    invoked from within
...
caused by:
...
    untested "failed to compile x86 PKEYS test.
...

Fix the unterminated string.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-26  Tom de Vries  <tdevries@suse.de>

	* gdb.arch/i386-pkru.exp: Fix unterminated string.
2019-07-26 21:49:45 +02:00
Christian Biesinger f32feb4ab3 Fix comment about the signature of add_separate_debug_file
Also fixes the date in the changelog of my last commit.

gdb/ChangeLog:

2019-07-25  Christian Biesinger  <cbiesinger@google.com>

	* python/py-objfile.c (add_separate_debug_file): Fix comment about
  this function's Python signature.
2019-07-25 17:17:49 -05:00
Tom de Vries 297989a10c [gdb/testsuite] Test skip_libstdcxx_probe_tests in mi-catch-cpp-exceptions.exp
On a system without SDT probes in libstdc++, we run into:
...
FAIL: gdb.mi/mi-catch-cpp-exceptions.exp: all with invalid regexp: run until \
  breakpoint in main (unknown output after running)
...

The test-case uses a regexp argument for the catch throw/rethrow/catch
command, which is only supported on systems with SDT probes in libstdc++.

Fix this by marking the portions of the test-case that use a regexp argument
as unsupported on a system without SDT probes.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-25  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24830
	* gdb.mi/mi-catch-cpp-exceptions.exp: Call
	mi_skip_libstdcxx_probe_tests, and skip unsupported tests.
	* lib/gdb.exp (skip_libstdcxx_probe_tests_prompt): Factor out of ...
	(skip_libstdcxx_probe_tests): ... here.
	* lib/mi-support.exp (mi_skip_libstdcxx_probe_tests): New proc.
2019-07-25 18:39:31 +02:00
Christian Biesinger 442853af24 Allow passing a block to lookup_global_symbol_from_objfile
This has no behavior change in itself, but allows a future patch
to add a function to the Python API to look up symbols in the
static block.

gdb/ChangeLog:

2019-07-24  Christian Biesinger  <cbiesinger@google.com>

	* compile/compile-object-load.c (compile_object_load): Pass GLOBAL_SCOPE.
	* solib-spu.c (spu_lookup_lib_symbol): Pass GLOBAL_SCOPE.
	* solib-svr4.c (elf_lookup_lib_symbol): Pass GLOBAL_SCOPE.
	* symtab.c (lookup_global_symbol_from_objfile): Add a scope parameter.
	* symtab.h (lookup_global_symbol_from_objfile): Likewise.
2019-07-24 19:02:50 -05:00
Tom de Vries b3b965fb91 [gdb/testsuite] Fix implicit declaration of printf in gdb.objc/*.m
When running gdb.objc/objcdecode.exp we get:
...
objcdecode.m: In function '-[Decode multipleDef]':
objcdecode.m:14:3: warning: incompatible implicit declaration of built-in \
  function 'printf'
   printf("method multipleDef\n");
   ^~~~~~
objcdecode.m:14:3: note: include '<stdio.h>' or provide a declaration of \
  'printf'
...

Fix this in the three gdb.objc/*.m test-cases by including stdio.h.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-24  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24807
	* gdb.objc/basicclass.m: Include stdio.h.
	* gdb.objc/nondebug.m: Same.
	* gdb.objc/objcdecode.m: Same.
2019-07-24 19:01:59 +02:00
Tom de Vries 4625b4d081 [gdb/testsuite] Fix infoline-reloc-main-from-zero.exp compilation
When running gdb.base/infoline-reloc-main-from-zero.exp, I see:
...
Running gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp ...
gdb compile failed, ld: infoline-reloc-main-from-zero: \
  not enough room for program headers, try linking with -N
ld: final link failed: bad value
collect2: error: ld returned 1 exit status
UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: infoline-reloc-main-from-zero.exp
UNTESTED: gdb.base/infoline-reloc-main-from-zero.exp: failed to compile
...

Fix this by following the suggestion:
...
-set opts {debug "additional_flags=-nostdlib -emain -Wl,-Ttext=0x00"}
+set opts {debug "additional_flags=-nostdlib -emain -Wl,-Ttext=0x00 -Wl,-N"}
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-24  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24612
	* gdb.base/infoline-reloc-main-from-zero.exp: Add -Wl,-N to
	additional_flags.
2019-07-24 17:16:01 +02:00
Yoshinori Sato c54e42531a gdb/h8300-tdep.c: Fix register name in h8300h machine.
H8/300H general register name "ER0" - "ER7".
But gdb using "R0" - "R7".
This changes register name "ER0" - "ER7" in h8300h machine mode.

gdb/ChangeLog:

	* h8300-tdep.c (h8300_register_name_common): New.
	h8300_register_name): Use h8300_register_name_common.
	(h8300s_register_name): Likewise.
	(h8300sx_register_name): Likewise.
	(h8300h_register_nam): New.
	(h8300_gdbarch_init): Use h8300h_register_name in h8300h machine.
2019-07-24 20:51:52 +09:00
Tom de Vries 024a584000 Update expected info threads error messages in gdb.multi/tids.exp
We currently have these FAILs:
...
FAIL: gdb.multi/tids.exp: two inferiors: info threads -1
FAIL: gdb.multi/tids.exp: two inferiors: info threads -$one
...
because we're expecting:
...
Invalid thread ID: -1
...
but instead we have:
...
Unrecognized option at: -1
...

This error message for info threads has changed since commit 54d6600669
'Make "info threads" use the gdb::option framework'.

Update the test accordingly.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-24  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24831
	* gdb.multi/tids.exp: Update error messages for info threads.
2019-07-24 08:36:17 +02:00
Tom de Vries c76ddaa3f4 [gdb/testsuite] Fix info-types.exp for debug info from more than one file
On openSUSE Leap 15.0, I get:
...
FAIL: gdb.base/info-types.exp: l=c: info types
FAIL: gdb.base/info-types.exp: l=c++: info types
...
because the info type command prints info for files info-types.c, stddef.h,
elf-init.c and init.c, while the regexp in the test-case expect only info for
info-types.c.

Fix this by extending the regexp.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-24  Tom de Vries  <tdevries@suse.de>

	* gdb.base/info-types.exp: Allow info types to print info for more than
	one file.
2019-07-24 08:04:59 +02:00
Tom de Vries 9a618ef615 [gdb/testsuite] Add missing initial prompt read in multidictionary.exp
When running multidictionary.exp in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
we get:
...
Running gdb/testsuite/gdb.dwarf2/multidictionary.exp ...
ERROR: Couldn't load multidictionary into gdb.

                === gdb Summary ===

nr of unresolved testcases       1
...

The multidictionary test-case needs -readnow, and achieves this using:
...
gdb_spawn_with_cmdline_opts "-readnow"
gdb_load
...
but the initial gdb prompt is not read.  Usually, the following gdb_load
command accidentally consumes that initial prompt (at the gdb_expect for the
kill command in gdb_file_cmd).  But under high load, that doesn't happen and
we run into the error.

Fix this by consuming the initial gdb prompt after spawning gdb.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-23  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24842
	* gdb.dwarf2/multidictionary.exp: Consume initial prompt after
	gdb_spawn_with_cmdline_opts.
2019-07-23 15:15:20 +02:00
Srinath Parvathaneni 40eadf04ff [gdb][Arm]: gdb cannot step across CMSE secure entry function code.
GDB is not able to execute "step" command on function calls of Armv8-M cmse secure entry functions.
Everytime GNU linker come across definition of any cmse secure entry function in object file(s),
it creates two new instructions secure gateway (sg) and original branch destination (b.w),
place those two instructions in ".gnu.sgstubs" section of executable.
Any function calls to these cmse secure entry functions is re-directed through secure gateway (sg)
present in ".gnu.sgstubs" section.

Example:
Following is a function call to cmse secure entry function "foo":
        ...
        bl xxxx <foo>   --->(a)
        ...
        <foo>
        xxxx: push    {r7, lr}

GNU linker on finding out "foo" is a cmse secure entry function, created sg and b.w instructions and
place them in ".gnu.sgstubs" section (marked by c).

The "bl" instruction (marked by a) which is a call to cmse secure entry function is modified by GNU linker
(as marked by b) and call flow is re-directly through secure gateway (sg) in ".gnu.sgstubs" section.
       ...
       bl yyyy <foo>  ---> (b)
       ...
       section .gnu.sgstubs: ---> (c)
       yyyy <foo>
       yyyy: sg   // secure gateway
	     b.w xxxx <__acle_se_foo>  // original_branch_dest
       ...
       0000xxxx <__acle_se_foo>
       xxxx: push    {r7, lr} ---> (d)

On invoking GDB, when the control is at "b" and we pass "step" command, the pc returns "yyyy"
(sg address) which is a trampoline and which does not exist in source code. So GDB jumps
to next line without jumping to "__acle_se_foo" (marked by d).

The above details are published on the Arm website [1], please refer to section 5.4 (Entry functions)
and section 3.4.4 (C level development flow of secure code).

[1] https://developer.arm.com/architectures/cpu-architecture/m-profile/docs/ecm0359818/latest/armv8-m-security-extensions-requirements-on-development-tools-engineering-specification

This patch fixes above problem by returning target pc "xxxx" to GDB on executing "step"
command at "b", so that the control jumps to "__acle_se_foo" (marked by d).

gdb/ChangeLog:

	* arm-tdep.c (arm_skip_cmse_entry): New function.
	(arm_is_sgstubs_section): New function.
	(arm_skip_stub): Add call to arm_skip_cmse_entry function.

gdb/testsuite/ChangeLog:

	* gdb.arch/arm-cmse-sgstubs.c: New test.
	* gdb.arch/arm-cmse-sgstubs.exp: New file.
2019-07-23 12:06:05 +01:00
Tom de Vries 5ba2943476 [gdb/testsuite] Fix command result testing in mi-complete.exp
When running gdb.mi/mi-complete.exp in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
we get less than 50% full passes:
...
$ for n in  $(seq 1 100); do \
    make V=1 -O check \
      'RUNTESTFLAGS=gdb.mi/mi-complete.exp --target_board=unix'; \
  done 2>&1 \
  | grep "expected passes" | sort | uniq -c
     45 # of expected passes            7
      9 # of expected passes            8
     46 # of expected passes            9
...

A diff between a passing and failing gdb.log shows this difference:
...
-&"set max-completions 1\n"
 2-complete br
+&"set max-completions 1\n"
...

The problem is that the test-case issues the "set max-completion <n>" command,
and without waiting for the output issues a next command, and tries to parse
the results of both commands, expecting a specific interleaving of the various
output streams.

Fix the FAIL by waiting for the result of the "set max-completion <n>" command
before issuing another command.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-07-23  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24711
	* gdb.mi/mi-complete.exp: Wait for "set max-completions" result before
	issuing next command.
2019-07-23 10:38:33 +02:00
Tom Tromey bfa2a36d94 Remove self-assign from make_invisible_and_set_new_height
In https://sourceware.org/ml/gdb-patches/2019-07/msg00509.html, Jan
pointed out that clang points out that
make_invisible_and_set_new_height self-assigns "height".

This patch fixes the bug by renaming the formal parameter.

gdb/ChangeLog
2019-07-22  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_win_info::make_invisible_and_set_new_height):
	Don't self-assign.
2019-07-22 08:34:25 -06:00
Andrew Burgess a8e9d24718 gdb: Show type summary for anonymous structures from c_print_typedef
Currently each language has a la_print_typedef method, this is only
used for the "info types" command.

The documentation for "info types" says:

   Print a brief description of all types whose names match the regular
   expression @var{regexp} (or all types in your program, if you supply
   no argument).

However, if we consider this C code:

   typedef struct {
     int a;
   } my_type;

Then currently with "info types" this will be printed like this:

   3:      typedef struct {
       int a;
   } my_type;

I see two problems with this, first the indentation is clearly broken,
second, if the struct contained more fields then it feels like the
actual type names could easily get lost in the noise.

Given that "info types" is about discovering type names, I think there
is an argument to be made that we should focus on giving _only_ the
briefest summary for "info types", and if the user wants to know more
they can take the type name and plug it into "ptype".  As such, I
propose that a better output would be:

   3:      typedef struct {...} my_type;

The user understands that there is a type called `my_type`, and that
it's an alias for an anonymous structure type.

The change to achieve this turns out to be pretty simple, but only
effects languages that make use of c_print_typedef, which are C, C++,
asm, minimal, d, go, objc, and opencl.  Other languages will for now
do whatever they used to do.

The patch to change how anonymous structs are displayed also changes
the display of anonymous enums, consider this code sample:

   typedef enum {
     AA, BB, CC
   } anon_enum_t;

This used to be displayed like this:

   3:      typedef enum {AA, BB, CC} anon_enum_t;

Which will quickly become cluttered for enums with a large number of
values.  The modified output looks like this:

   3:      typedef enum {...} anon_enum_t;

Again, the user can always make use of ptype if they want to see the
details of the anon_enum_t type.

It is worth pointing out that this change (to use {...}) only effects
anonymous structs and enums, named types don't change with this patch,
consider this code:

   struct struct_t {
     int i;
   };
   enum enum_t {
    AA, BB, CC
   };

The output from 'info types' remains unchanged, like this:

   4:      enum enum_t;
   1:      struct struct_t;

An additional area of interest is how C++ handles anonymous types used
within a typedef; enums are handled basically inline with how C
handles them, but structs (and classes) are slightly different.  The
behaviour before the patch is different, and is unchanged by this
patch.  Consider this code compiled for C++:

   typedef struct {
     int i;
   } struct_t;

Both before and after this patch, this is show by 'info types' as:

   3:      typedef struct_t struct_t;

Unions are displayed similarly to structs in both C and C++, the
handling of anonymous unions changes for C in the same way that
it changes for anonymous structs.

I did look at ada, as this is the only language to actually have some
tests for "info types", however, as I understand it ada doesn't really
support typedefs, however, by forcing the language we can see what ada
would print.  So, if we 'set language ada', then originally we printed
this:

   3:      record
       a: int;
   end record

Again the indentation is clearly broken, but we also have no mention
of the type name at all, which is odd, but understandable given the
lack of typedefs.  If I make a similar change as I'm proposing for C,
then we now get this output:

   3:      record ... end record

Which is even less informative I think.  However, the original output
_is_ tested for in gdb.ada/info_auto_lang.exp, and its not clear to me
if the change is a good one or not, so for now I have left this out.

gdb/ChangeLog:

	* c-typeprint.c (c_print_typedef): Pass -1 instead of 0 to
	type_print.

gdb/testsuite/ChangeLog:

	* gdb.ada/info_auto_lang.exp: Update expected results.
	* gdb.base/info-types.c: Add additional types to check.
	* gdb.base/info-types.exp: Update expected results.
2019-07-22 10:43:03 +01:00
Andrew Burgess eb86c5e2e8 gdb: Improve output from "info types" commad
This commit makes two changes to the "info types" command:

First, only use typedef_print for printing typedefs, and use
type_print for printing non-typedef scalar (non-struct) types.  The
result of this is the output for builtin types goes from this:

    typedef double;
    typedef float;
    typedef int;

to this:

    double;
    float;
    int;

which seems to make more sense.

Next GDB no longer matches msymbols as possible type names.  When
looking for function symbols it makes sense to report matching
msymbols from the text sections, and for variables msymbols from the
data/bss sections, but when reporting types GDB would match msymbols
of type absolute.  But I don't see why these are likely to indicate
type names.  As such I've updated the msymbol matching lists in
symtab.c:search_symbols so that when searching in the TYPES_DOMAIN, we
never match any msymbols.

gdb/ChangeLog:

	* symtab.c (search_symbols): Adjust msymbol matching type arrays
	so that GDB doesn't match any msymbols when searching in the
	TYPES_DOMAIN.
	(print_symbol_info): Print using typedef_print or type_print based
	on the type of the symbol.  Add updated FIXME comment moved from...
	(_initialize_symtab): ... move and update FIXME comment to above.

gdb/testsuite/ChangeLog:

	* gdb.base/info-types.c: New file.
	* gdb.base/info-types.exp: New file.
2019-07-22 10:43:02 +01:00
Andrew Burgess a8eab7c6d5 gdb: Switch "info types" over to use the gdb::options framework
Adds a new -q flag to "info types" using the gdb::option framework.
This -q flag is similar to the -q flag already present for "info
variables" and "info functions".

gdb/ChangeLog:

	* NEWS: Mention adding -q option to "info types".
	* symtab.c (struct info_types_options): New struct.
	(info_types_options_defs): New variable.
	(make_info_types_options_def_group): New function.
	(info_types_command): Use gdb::option framework to parse options.
	(info_types_command_completer): New function.
	(_initialize_symtab): Extend the help text on "info types" and
	register command completer.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Add information about -q flag to "info
	types".
2019-07-22 10:43:00 +01:00
Christian Biesinger b4603c3464 Add ChangeLog entry for the last commit
Forgot to commit before pushing :(
2019-07-21 22:27:07 -05:00
Christian Biesinger c32e6a04f4 Use block_enum instead of int for better typesafety
gdb/ChangeLog:

2019-07-21  Christian Biesinger  <cbiesinger@google.com>

	* symtab.c (lookup_symbol_in_objfile_symtabs): Change int to block_enum.
	(lookup_symbol_in_objfile): Change int to block_enum and add a
	gdb_assert to make sure block_index is GLOBAL_BLOCK or STATIC_BLOCK.
2019-07-21 22:23:12 -05:00
Christian Biesinger c8cdc1e083 [FYI] Add myself to gdb/MAINTAINERS
gdb/Changelog:

	* MAINTAINERS (Write After Approval): Add myself.
2019-07-21 22:00:22 -05:00
Kevin Buettner 86ceaf9867 Make documentation of "python" command match actual behavior
The example in the documentation for the "python" command shows GDB
outputting instructions for how to terminate a sequence of python
commands entered from the command line.  The documentation shows that
the following two lines are being output, though this does not occur
when actually using the "python" command from GDB:

    Type python script
    End with a line saying just "end".

While display of this text might be helpful, GDB has several other
commands which also use the "end" terminator that offer no such text.
Examples include the "if" and "while" commands.  For example,

(gdb) if 1==1
 >print "a"
 >end
$1 = "a"

This seems similar to doing:

(gdb) python
 >print 23
 >end
23

If we decide that we want the "python" command to print such a message,
we should also adjust the behavior for other GDB commands which also use
"end" to terminate a command list.  I.e, if this decision is made, the
"if" and "while" commands ought to also print similar messages.

So, for the moment anyway, this commit adjusts the documentation of the
python command to match its implementation.

This patch was taken from a larger body of work originating from the
Archer project.  I haven't been able to determine its original author,
though I did find a commit log from Jan Kratochvil (in the Archer
repository) which suggests that the change had originally been made to
gdb.texinfo, but got inadvertently dropped when the python related
documentation was split out to python.texi.

gdb/doc/ChangeLog:

	* python.texi (python command): Revise example to match
	command behavior.
2019-07-20 22:47:15 -07:00
Andrew Burgess 01e175fe1b gdb/riscv: Write 4-byte nop to dummy code region before inferior calls
When making inferior function calls GDB sets up a dummy code region on
the stack, and places a breakpoint within that region.  If the random
stack contents appear to be a compressed instruction then GDB  will
place a compressed breakpoint, which can cause problems if the target
doesn't support compressed instructions.

This commit prevents this issue by writing a 4-byte nop instruction to
the dummy region at the time the region is allocated.  With this nop
instruction in place, when we come to insert the breakpoint then an
uncompressed breakpoint will be used.

This is similar to other targets, for example mips.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_push_dummy_code): Write a 4-byte nop
	instruction to the dummy code region.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-bp-infcall.c: New file.
	* gdb.arch/riscv-bp-infcall.exp: New file.
2019-07-19 21:00:22 +01:00
Tom Tromey 56f79b6307 Change ARI to mention C++11, and remove some rules
I noticed that ARI mentions "ISO C 90", but now gdb uses C++11.  This
patch updates some text to reflect this change.

I also noticed that a few rules can be removed now.  ARGSUSED doesn't
seem to be an issue any more (there's no code mentioning this and I
doubt most of us even remember this convention); PARAMS was specific
to K&R C; and __func__ is available in C++11.

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

	* contrib/ari/gdb_ari.sh: Mention C++11, not ISO C 90.
	(ARGSUSED, PARAMS, __func__): Remove rules.
2019-07-19 09:37:00 -06:00
Alan Hayward 4c5aa8e0b1 Arm: Remove unused feature files and tests
Remove the xml tests. Now that it has been proven the new descriptions
are identical, there is no need to keep testing that.  Also, it would
prevent the old xml files from being removed.

Remove the old xml files from gdbserver and delete them.

gdb/ChangeLog:

	* arm-tdep.c (_initialize_arm_tdep): Remove xml tests.
	* features/arm/arm-with-iwmmxt.c: Remove.
	* features/arm/arm-with-iwmmxt.xml: Remove.
	* features/arm/arm-with-m-fpa-layout.c: Remove.
	* features/arm/arm-with-m-fpa-layout.xml: Remove.
	* features/arm/arm-with-m-vfp-d16.c: Remove.
	* features/arm/arm-with-m-vfp-d16.xml: Remove.
	* features/arm/arm-with-m.c: Remove.
	* features/arm/arm-with-m.xml: Remove.
	* features/arm/arm-with-neon.c: Remove.
	* features/arm/arm-with-neon.xml: Remove.
	* features/arm/arm-with-vfpv2.c: Remove.
	* features/arm/arm-with-vfpv2.xml: Remove.
	* features/arm/arm-with-vfpv3.c: Remove.
	* features/arm/arm-with-vfpv3.xml: Remove.

gdb/gdbserver/ChangeLog:

2019-07-05  Alan Hayward  <alan.hayward@arm.com>

	* configure.srv: Remove Arm xml files.
2019-07-19 15:43:55 +01:00
Alan Hayward 7cc1743302 Arm: Use read_description funcs in gdbserver
Switch gdbserver over to using feature target descriptions.

Add a function for determining the type of a given target description,
and use where required.

gdb/gdbserver/ChangeLog:

	* configure.srv: Add new files. Remove xml generated files.
	* linux-aarch32-low.c (initialize_low_arch_aarch32): Don't init
	registers.
	* linux-aarch32-low.h (tdesc_arm_with_neon): Remove.
	* linux-aarch32-tdesc.c: New file.
	* linux-aarch32-tdesc.h: New file.
	* linux-aarch64-low.c (aarch64_arch_setup): Call aarch32_linux_read_description.
	* linux-arm-low.c (init_registers_arm, tdesc_arm)
	(init_registers_arm_with_iwmmxt, tdesc_arm_with_iwmmxt)
	(init_registers_arm_with_vfpv2, tdesc_arm_with_vfpv2)
	(init_registers_arm_with_vfpv3, tdesc_arm_with_vfpv3): Remove.
	(arm_fill_wmmxregset, arm_store_wmmxregset, arm_fill_vfpregset)
	(arm_store_vfpregset): Call arm_linux_get_tdesc_fp_type.
	(arm_read_description): Call arm_linux_read_description.
	(initialize_low_arch): Don't init registers.
	* linux-arm-tdesc.c: New file.
	* linux-arm-tdesc.h: New file.
2019-07-19 15:43:49 +01:00
Alan Hayward f42b26179a Arm: Add xml unit tests
Use the record_xml_tdesc tests to prove the new target descriptions
are identical to the previous xml file ones.

This is tested as part of gdb.gdb/unittest.exp.

gdb/ChangeLog:

	* arm-tdep.c (_initialize_arm_tdep): Add xml regression tests.
2019-07-19 15:02:41 +01:00
Alan Hayward f29ec96643 Arm: Use feature target descriptions
In arm arm_create_target_description and
aarch32_create_target_description create feature based target descriptions
instead of returning the old style descriptions.

Ensure the descriptions are created in exactly the same way as the old xml
files.

Remove the old initialize calls.

gdb/ChangeLog:

	* arch/aarch32.c (aarch32_create_target_description): Create
	target descriptions using features.
	* arch/arm.c (arm_create_target_description)
	(arm_create_mprofile_target_description): Likewise.
	* arm-tdep.c (_initialize_arm_tdep): Remove tdesc init calls.
2019-07-19 15:01:11 +01:00
Alan Hayward d105cce5dd Arm: Add read_description read funcs and use in GDB
Switch the Arm target to get target descriptions via arm_read_description
and aarch32_read_description, in the same style as other feature targets.
Add an enum to specify the different types - this will also be of use to
gdbserver in a later patch.

Under the hood return the same existing pre-feature target descriptions.

gdb/ChangeLog:

	* Makefile.in: Add new files.
	* aarch32-tdep.c: New file.
	* aarch32-tdep.h: New file.
	* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
	Call aarch32_read_description.
	* arch/aarch32.c: New file.
	* arch/aarch32.h: New file.
	* arch/arm.c (arm_create_target_description)
	(arm_create_mprofile_target_description): New function.
	* arch/arm.h (arm_fp_type, arm_m_profile_type): New enum.
	(arm_create_target_description)
	(arm_create_mprofile_target_description): New declaration.
	* arm-fbsd-tdep.c (arm_fbsd_read_description_auxv): Call
	read_description functions.
	* arm-linux-nat.c (arm_linux_nat_target::read_description):
	Likewise.
	* arm-linux-tdep.c (arm_linux_core_read_description): Likewise.
	* arm-tdep.c (tdesc_arm_list): New variable.
	(arm_register_g_packet_guesses): Call create description functions.
	(arm_read_description) (arm_read_mprofile_description): New
	function.
	* arm-tdep.h (arm_read_description)
	(arm_read_mprofile_description): Add declaration.
	* configure.tgt: Add new files.
2019-07-19 14:59:10 +01:00
Guillaume LABARTHE afe09f0b63 Fix for using named pipes on Windows
On Windows, passing a named pipe as terminal argument to the new-ui
command does not work.

The problem is that the new_ui_command function in top.c opens the
same tty three times, for stdin, stdout and stderr.  With Windows
named pipes, the second and third calls to open fail.

Opening the file only once and passing the same stream for stdin,
stdout and stderr makes it work.

Pedro says:

 I tried it on GNU/Linux and things still work.
 I ran all the MI tests with forced new-ui, with:

 $ make check TESTS="gdb.mi/*.exp" RUNTESTFLAGS="FORCE_MI_SEPARATE_UI=1"

 and saw no regressions.

gdb/ChangeLog:
2019-07-18  Guillaume LABARTHE  <guillaume.labarthe@gmail.com>

	* top.c (new_ui_command): Open specified terminal just once.
2019-07-18 17:20:04 +01:00
Tom Tromey cd215b2eb7 Constify main_name
This patch constifies the return type of main_name.  There is a
comment indicating that this wasn't possible at some point in the
past, but whatever the barrier was, it is gone now.

Tested by rebuilding.

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

	* symtab.c (main_name): Constify return type.
	* symfile.c (set_initial_language): Update.
	* symtab.h (main_name): Constify return type.
2019-07-18 09:31:12 -06:00
Tom Tromey d8f68fcb93 Remove unnecessary "return"s
The TUI has some "return;" statements at the end of void-returning
functions.  There's no need for these, so this patch removes them.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_update_source_window)
	(tui_update_source_window_as_is)
	(tui_update_source_windows_with_line): Remove return.
	* tui/tui-disasm.c (tui_show_disassem)
	(tui_show_disassem_and_update_source): Remove return.
	* tui/tui.c (tui_reset): Remove return.
	* tui/tui-wingeneral.c
	(tui_check_and_display_highlight_if_needed): Remove return.
2019-07-17 12:19:26 -06:00
Tom Tromey ca5af91ed2 Fix an error in parse_scrolling_args
parse_scrolling_args combines two errors into one message, which also
happens to end with a newline.  This separates the errors and fixes
the message.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (parse_scrolling_args): Throw separate errors.
2019-07-17 12:19:25 -06:00
Tom Tromey 5104fe361d Move source window common to code to tui-winsource.[ch]
Like the previous rearranging patches, this moves the source and
disassembly window base class code to tui-winsource.[ch].  The
execution info window is also moved, because it is associated with
this base class.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_exec_info_window)
	(struct tui_source_window_base): Move from tui-data.h.
	* tui/tui-winsource.c: Move many method definitions from
	elsewhere.  Remove "structuring" comments.
	* tui/tui-wingeneral.c (tui_source_window_base::make_visible)
	(tui_source_window_base::refresh_window): Move to
	tui-winsource.c.
	* tui/tui-win.c (tui_source_window_base::refresh_all)
	(tui_source_window_base::update_tab_width)
	(tui_source_window_base::set_new_height)
	(tui_source_window_base::do_make_visible_with_new_height): Move to
	tui-winsource.c.
	* tui/tui-source.h: Update.
	* tui/tui-source.c (tui_source_window_base::reset): Move to
	tui-winsource.c.
	* tui/tui-disasm.h: Update.
	* tui/tui-data.h (struct tui_exec_info_window): Move to
	tui-winsource.h.
	(struct tui_source_window_base): Likewise.
	* tui/tui-data.c (tui_source_window_base::clear_detail)
	(tui_source_window_base, ~tui_source_window_base): Move to
	tui-winsource.c.
2019-07-17 12:19:25 -06:00
Tom Tromey daa15dde72 Change make_invisible_and_set_new_height to be a method
This changes make_invisible_and_set_new_height to be a method on
tui_win_info.  I felt that this was cleaner.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_resize_all)
	(tui_source_window_base::update_tab_width)
	(tui_adjust_win_heights): Update.
	(tui_win_info::make_invisible_and_set_new_height): Rename from
	make_invisible_and_set_new_height.
	* tui/tui-data.h (struct tui_win_info)
	<make_invisible_and_set_new_height>: New method.
2019-07-17 12:19:24 -06:00
Tom Tromey bfad453707 Move tui_source_window to tui-source.h
This moves tui_source_window to tui-source.h.  In this case there were
no method definitions to be moved.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui.c: Update.
	* tui/tui-source.h (struct tui_source_window): Move from
	tui-data.h.
	* tui/tui-layout.c: Update.
	* tui/tui-disasm.c: Update.
	* tui/tui-data.h (struct tui_source_window): Move to
	tui-source.h.
2019-07-17 12:19:24 -06:00
Tom Tromey 88f7e87336 Move tui_disasm_window to tui-disasm.h
This moves tui_disasm_window to tui-disasm.h.  In this case there were
no method definitions to be moved.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-disasm.h (struct tui_disasm_window): Move from
	tui-data.h.
	* tui/tui-data.h (struct tui_disasm_window): Move to
	tui-disasm.h.
2019-07-17 12:19:23 -06:00
Tom Tromey 96bd6233af Move TUI data item window to tui-regs.h
The TUI data item window is only used by the TUI register window.  So,
this patch moves the relevant code to tui-regs.[ch].

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (struct tui_data_item_window): Move from
	tui-data.h.
	* tui/tui-regs.c (tui_data_item_window): Move from tui-data.c.
	* tui/tui-data.h (struct tui_data_item_window): Move to
	tui-regs.h.
	* tui/tui-data.c (~tui_data_item_window): Move to tui-regs.c.
2019-07-17 12:19:23 -06:00
Tom Tromey ce38393b1a Move TUI command window code
Like the earlier change to the data window, this moves the TUI command
window code to tui-command.[ch], and removes the old "structuring"
comments from tui-command.c.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui.c: Update.
	* tui/tui-win.c (tui_cmd_window::do_make_visible_with_new_height)
	(tui_cmd_window::max_height): Move to tui-command.c.
	* tui/tui-layout.c: Update.
	* tui/tui-data.h (struct tui_cmd_window): Move to tui-command.h.
	* tui/tui-data.c (tui_cmd_window::clear_detail): Move to
	tui-command.c.
	* tui/tui-command.h (struct tui_cmd_window): Move from
	tui-data.h.
	* tui/tui-command.c: Remove "structuring" comments.
	(tui_cmd_window::clear_detail)
	(tui_cmd_window::do_make_visible_with_new_height)
	(tui_cmd_window::max_height): Move from elsewhere.
2019-07-17 12:19:22 -06:00
Tom Tromey 2d8b51cba3 Move tui_dispatch_ctrl_char to tui-io.c
tui_dispatch_ctrl_char is only called from a single spot in tui-io.c,
so move the function to that file and make it static.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-io.c (tui_dispatch_ctrl_char): Move from tui-command.c.
	Now static.
	* tui/tui-command.h (tui_dispatch_ctrl_char): Don't declare.
	* tui/tui-command.c (tui_dispatch_ctrl_char): Move to tui-io.c.
2019-07-17 12:19:22 -06:00
Tom Tromey 18ab23af8b Rearrange TUI data window code
An earlier patch caused tui-windata.h to be essentially empty.  And,
other earlier patches implemented TUI data window methods in any spot
that happened to be convenient at the time.

This patch rearranges all the data window code to be somewhat more
organized.  It moves tui_data_window to tui-regs.h, and moves the
implementation of all methods to tui-regs.c.  It then removes
tui-windata.h and tui-windata.c.

It also removes the "structuring" comments from tui-regs.c; these are
not the usual gdb style, and were out of date anyhow.  Finally, it
moves _initialize_tui_regs to the end of the file, per the usual gdb
convention.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui.c: Update.
	* tui/tui-wingeneral.c (tui_data_window::refresh_window): Move to
	tui-regs.c.
	* tui/tui-windata.h: Remove file.
	* tui/tui-windata.c: Remove file.
	* tui/tui-win.c (tui_data_window::set_new_height)
	(tui_data_window::do_make_visible_with_new_height): Move to
	tui-regs.c.
	* tui/tui-regs.h (struct tui_data_window): Move from tui-data.h.
	* tui/tui-regs.c: Remove "structuring" comments.
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows)
	(tui_data_window::erase_data_content)
	(tui_data_window::display_all_data)
	(tui_data_window::refresh_all)
	(tui_data_window::do_scroll_vertical)
	(tui_data_window::clear_detail, tui_data_window::set_new_height)
	(tui_data_window::do_make_visible_with_new_height)
	(tui_data_window::refresh_window): Move from elsewhere.
	(_initialize_tui_regs): Move to end of file.
	* tui/tui-layout.c: Update.
	* tui/tui-hooks.c: Update.
	* tui/tui-data.h (struct tui_data_window): Move to tui-regs.h.
	* tui/tui-data.c (tui_data_window::clear_detail): Move to
	tui-regs.c.
	* Makefile.in (SUBDIR_TUI_SRCS): Remove tui-windata.c.
2019-07-17 12:19:21 -06:00
Tom Tromey 88b7e7ccb9 Fix flushing bug in tui_puts_internal
A while back I changed gdb not to flush in some places.  It turned out
that this broke the TUI a little.  An easy way to see it is to run
"gdb -tui -nx", then "file gdb" at the gdb prompt.  gdb will print the
usual "Reading symbols..." message -- but it won't appear on-screen
until the reading is complete.

This patch changes the TUI to do the equivalent of line buffering in
tui_puts_internal.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-io.c (tui_puts_internal): Call wrefresh if newline is
	seen.
2019-07-17 12:19:20 -06:00
Tom Tromey 0fcd37117e Remove has_locator method
Earlier changes made it obvious that the has_locator method can only
be called for source/disassembly windows.  Because the only reference
to this now occurs in methods on this object, we can remove the
has_locator method entirely, in favor of using the member directly.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_source_window_base::set_new_height)
	(tui_source_window_base::do_make_visible_with_new_height): Use
	m_has_locator field directly.
	* tui/tui-data.h (struct tui_win_info) <has_locator>: Remove
	method.
	(struct tui_source_window_base) <has_locator>: Likewise.
2019-07-17 12:19:20 -06:00
Tom Tromey 4a38112da0 Remove tui_make_visible and tui_make_invisible
tui_make_visible and tui_make_invisible are just wrappers for a method
call, so remove them and have the callers simply make the method call
themselves.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.h (tui_make_visible, tui_make_invisible):
	Don't declare.
	* tui/tui-wingeneral.c (tui_make_visible, tui_make_invisible):
	Remove.
	* tui/tui-win.c (tui_source_window_base::set_new_height)
	(tui_source_window_base::set_new_height)
	(make_invisible_and_set_new_height)
	(tui_source_window_base::do_make_visible_with_new_height)
	(tui_source_window_base::do_make_visible_with_new_height):
	Update.
	* tui/tui-layout.c (show_source_disasm_command, show_data)
	(show_source_or_disasm_and_command): Update.
	* tui/tui-layout.c (show_layout): Update.
2019-07-17 12:19:19 -06:00
Tom Tromey 0912922656 Remove make_data_window
As with the previous patches, unifying the creation and
re-initialization cases for the data window lets us remove
make_data_window in favor of simply using "new".

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (make_data_window): Remove.
	(show_data): Unify creation and re-initialization cases.
2019-07-17 12:19:19 -06:00
Tom Tromey 4a8a5e84a7 Remove make_source_window and make_disasm_window
This unifies the remaining creation and re-initialization cases for
the source and disassembly windows.  Once this is done, it's clear
that make_source_window and make_disasm_window aren't needed any more,
so remove them.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (make_source_window, make_disasm_window):
	Remove.
	(show_data): Unify creation and re-initialization cases.
2019-07-17 12:19:18 -06:00
Tom Tromey 76d2be8e92 Remove make_command_window
This unifies the creation and re-initialization cases for the command
window.  When this is done, it becomes clear that make_command_window
isn't needed -- it can be replaced with a simple "new", so this is
removed as well.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (make_command_window): Remove.
	(show_source_disasm_command, show_source_or_disasm_and_command):
	Unify creation and re-initialization cases.
2019-07-17 12:19:18 -06:00
Tom Tromey 890b8bde7a Simplify show_source_or_disasm_and_command
This changes show_source_or_disasm_and_command to unify the creation
and re-initialization cases.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_source_or_disasm_and_command): Unify
	creation and re-initialization cases.
2019-07-17 12:19:17 -06:00
Tom Tromey 2cdfa11333 Change tui_get_register to return void
tui_get_register returns a tui_status, but nothing checks this, so it
can return void instead.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_get_register): Return void.
2019-07-17 12:19:17 -06:00
Tom Tromey 8e3cfd09e8 Simplify tui_gen_win_info::make_visible
I noticed that tui_gen_win_info::make_visible was much wordier than it
needed to be.  This simplifies it.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.c (tui_gen_win_info::make_visible):
	Simplify.
2019-07-17 12:19:16 -06:00
Tom Tromey f4e049775a Simplify show_source_disasm_command
This is the first of a few patches to further simplify window
(re-)initialization in tui-layout.c.  When changing the layout, a
window may be created or, if it already exists, simply resized.  These
two cases normally are identical, but this was obscured by the way the
code was written.  This patch changes show_source_disasm_command to
unify the creation and re-initialization cases.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_source_disasm_command): Simplify window
	resetting.
2019-07-17 12:19:16 -06:00
Tom Tromey 0379b8837a Clean up tui_layout_command
tui_layout_command is a simple wrapper for tui_set_layout_by_name.
This removes the extra layer and cleans up the resulting function a
bit -- changing it to call error rather than return a result.  This
necessitated a small change to tui-regs.c, to avoid calling the
function that is being removed.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui.h (tui_set_layout_by_name): Don't declare.
	* tui/tui-regs.c (tui_reg_layout): New function.
	(tui_show_registers, tui_reg_command): Use it.
	* tui/tui-layout.c (LAYOUT_USAGE): Remove.
	(tui_layout_command): Rename from tui_set_layout_by_name.  Change
	parameters.
	(tui_layout_command): Remove.
2019-07-17 12:19:15 -06:00
Tom Tromey b7fbad913e Change tui_set_layout to return void
tui_set_layout can't meaningfully be called with UNDEFINED_LAYOUT; and
instead of trying to handle this case, simply assert and have the
function return void.  No caller was checking the return value anyway.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.h (tui/tui-layout): Return void.
	* tui/tui-layout.c (tui_set_layout): Return void.  Add assert.
2019-07-17 12:19:15 -06:00
Tom Tromey 4e1e56b981 Remove reset_locator
reset_locator was introduced just a few patches ago, but it's already
time to remove it.  It consists of a call to the locator's "reset"
method, plus a call to tui_make_window; but the latter is redundant at
all the places that call reset_locator.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_source_disasm_command, show_data):
	Update.
	(reset_locator): Remove.
	(show_source_or_disasm_and_command): Update.
2019-07-17 12:19:14 -06:00
Tom Tromey 1e0c09ba0b Remove the win_type parameter from tui_gen_win_info::reset
tui_gen_win_info::reset has a window type parameter that is only used
for an assertion.  This made sense as a defensive measure when window
creation was more dynamic -- it ensured that one did not make
mistakes.  However, there's no need for it any more, so this removes
it.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-source.c (tui_source_window_base::reset): Remove
	win_type parameter.
	* tui/tui-layout.c (make_command_window, make_source_window)
	(make_disasm_window, make_data_window)
	(show_source_disasm_command, show_data, tui_gen_win_info::reset)
	(reset_locator, show_source_or_disasm_and_command): Update.
	* tui/tui-data.h (struct tui_gen_win_info) <reset>: Remove
	win_type parameter.
	(struct tui_source_window_base) <reset>: Likewise.
2019-07-17 12:19:13 -06:00
Tom Tromey 1bf605de8e Introduce reset_locator function in tui-layout.c
init_and_make_win in tui-layout.c is now only called for the locator
-- earlier changes have made most of the cases here obsolete.  This
patch removes init_and_make_win and introduces a reset_locator
function.  Window creation is now much simpler to follow, because it
is no longer quite so dynamic.  (Though it will become even simpler in
coming patches.)

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_source_disasm_command): Use
	reset_locator.
	(reset_locator): New function.
	(init_and_make_win): Remove.
	(show_source_or_disasm_and_command): Use reset_locator.
2019-07-17 12:19:13 -06:00
Tom Tromey 098f9ed48e Always create an execution info window for a source window
A source or disassembly window will always have an "execution info"
window (the window along the side that displays breakpoint info), but
this isn't immediately clear from the source.  As a result, some code
has checks to see whether the execution_info is NULL.

This changes the source window base class to always instantiate an
execution_info window, then updates the rest of the code.  It also
simplifies window creation in tui-layout.c.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_set_exec_info_content): Remove
	condition.
	* tui/tui-wingeneral.c (tui_source_window_base::make_visible):
	Remove condition.
	* tui/tui-source.c (tui_source_window_base::reset): New method.
	* tui/tui-layout.c (make_command_window): Don't call
	init_and_make_win.
	(make_source_window, make_disasm_window): Don't call
	make_source_or_disasm_window.
	(make_data_window): Don't call init_and_make_win.  Change calling
	convention.
	(show_source_disasm_command, show_data): Simplify.
	(make_source_or_disasm_window): Remove.
	(show_source_or_disasm_and_command): Simplify.
	* tui/tui-data.h (struct tui_gen_win_info) <reset>: Now virtual.
	(struct tui_source_window_base) <reset>: Likewise.
	<execution_info>: Remove initializer.
	* tui/tui-data.c (tui_source_window_base): Initialize
	execution_info.
2019-07-17 12:19:12 -06:00
Tom Tromey 801109578c Remove some dead code from tui_set_layout
tui_set_layout sets regs_populate using:

      regs_populate = (new_layout == SRC_DATA_COMMAND
		       || new_layout == DISASSEM_DATA_COMMAND);

Then later it checks this variable:

	  if (!regs_populate
	      && (new_layout == SRC_DATA_COMMAND
		  || new_layout == DISASSEM_DATA_COMMAND))

However, this is equivalent to "!regs_populate && regs_populate",
which can never be true.  So, remove the dead code and the variable.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (tui_set_layout): Remove regs_populate
	variable.
2019-07-17 12:19:12 -06:00
Tom Tromey cf82af058d Remove TUI data window special case
The TUI has a couple of special cases for updating the data window:
one in tui_rl_other_windowand one in tui_set_focus_command.  As part
of the project to remove references to globals, I wanted to remove
these calls; but when I did, some simple operations (like "C-x o")
would cause the register window to blank.

This fixes the underlying problem by arranging for the data window's
refresh_window method to call the superclass method first, and then to
refresh the child windows.  Then the special cases can be removed.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui.c (tui_rl_other_window): Update.
	* tui/tui-wingeneral.c (tui_data_window::refresh_window): Call
	superclass method first.  Always iterate over regs_content.
	(tui_unhighlight_win, tui_highlight_win): Use refresh_window
	method.
	* tui/tui-win.c (tui_set_focus_command): Update.
2019-07-17 12:19:11 -06:00
Tom Tromey 01aeb396d0 Remove tui_set_focus
tui_set_focus_command is a simple wrapper for tui_set_focus, so rename
the latter and remove the wrapper function.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_focus_command): Rename from
	tui_set_focus.  Call tui_enable.
	(tui_set_focus_command): Remove.
2019-07-17 12:19:10 -06:00
Tom Tromey fd6c75eecd Merge refresh and refresh_window methods
Earlier refactorings introduced the refresh and refresh_window
methods, following the previous TUI code.  However, these methods are
essentially the same, so this patch merges them.  It also removes some
redundant refresh_window calls, because the execution window is
updated automatically by the corresponding source (or disassembly)
window.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_show_exec_info_content): Don't call
	refresh_window.
	* tui/tui-wingeneral.c (tui_gen_win_info::refresh_window): Call
	touchwin.
	(tui_data_window::refresh_window): Call refresh_window on data
	items.  Always call superclass refresh_window.
	(tui_win_info::refresh): Remove.
	(tui_source_window_base::refresh_window): Update.
	(tui_refresh_all): Update.
	* tui/tui-layout.c (show_source_disasm_command): Remove call to
	refresh_window.
	(show_source_or_disasm_and_command): Likewise.
	* tui/tui-data.h (struct tui_win_info) <refresh>: Remove.
	(struct tui_source_window_base) <refresh>: Likewise.
2019-07-17 12:19:10 -06:00
Tom Tromey f6cc34a91c Remove tui_source_window::content_in_use
Now that source window clearing has been simplified, we don't need a
special flag to say whether the source window is in use -- we can
simply check whether the contents are set.  This patch implements this
idea, removing the content_in_use field.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_clear_source_content)
	(tui_show_source_content): Update.
	* tui/tui-source.c (tui_source_window::showing_source_p): Check
	whether content is empty.
	* tui/tui-data.h (struct tui_source_window_base) <content_in_use>:
	Remove.
2019-07-17 12:19:09 -06:00
Tom Tromey f31ec9af48 Simplify source window clearing
When a TUI source window is empty, it displays a "No Source Available"
message.  The function tui_set_source_content_nil also made sure to
put this message into the window's "content" field.

However, I believe this isn't really necessary.  Instead, it's simpler
to just empty the contents and let curses handle the refreshing.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_erase_source_content): Clear the
	window's contents.
	* tui/tui-source.h (tui_set_source_content_nil): Don't declare.
	* tui/tui-source.c (tui_set_source_content_nil): Remove.
2019-07-17 12:19:09 -06:00
Tom Tromey d1b6f1e5eb Remove UNDEFINED_ITEM define from TUI
The TUI defined UNDEFINED_ITEM, but only used it in a single spot.  I
think this isn't very useful, so this removes the define.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (UNDEFINED_ITEM): Remove define.
	(struct tui_data_item_window): Update.
2019-07-17 12:19:08 -06:00
Tom Tromey d9743a13e0 Remove unused TUI defines
This removes some #defines that were unused in the TUI.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (MAX_CONTENT_COUNT, TUI_NULL_STR)
	(DEFAULT_HISTORY_COUNT, WITH_LOCATOR, NO_LOCATOR): Remove
	defines.
2019-07-17 12:19:07 -06:00
Tom Tromey caf0bc4e8b Remove unused parameter from two TUI functions
The "display_prompt" parameter of tui_erase_source_content and
tui_clear_source_content was never passed the NO_EMPTY_SOURCE_PROMPT
value, so remove the parameter.  Once this is done, the
EMPTY_SOURCE_PROMPT and NO_EMPTY_SOURCE_PROMPT defines are unused, so
remove those as well.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (tui_erase_source_content)
	(tui_clear_source_content): Remove "display_prompt" parameter.
	* tui/tui-winsource.c (tui_update_source_window_as_is)
	(tui_update_source_windows_with_addr): Update.
	(tui_clear_source_content): Remove "display_prompt" parameter.
	(tui_erase_source_content): Likewise.  Simplify.
	(tui_show_source_content): Update.
	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Update.
	* tui/tui-stack.c (tui_show_frame_info): Update.
	* tui/tui-data.h (EMPTY_SOURCE_PROMPT, NO_EMPTY_SOURCE_PROMPT):
	Remove defines.
2019-07-17 12:19:07 -06:00
Tom Tromey 9d391078d1 Add win_info parameter to tui_set_disassem_content
This adds a win_info parameter to tui_set_disassem_content, removing
uses of the TUI_DISASM_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_update_source_window_as_is): Update.
	* tui/tui-disasm.h (tui_set_disassem_content): Add win_info
	parameter.
	* tui/tui-disasm.c (tui_set_disassem_content): Add win_info
	parameter.
2019-07-17 12:19:06 -06:00
Tom Tromey a38da35d7b Move content_in_use to tui_source_window class
From scanning the source now, it's clear that the content_in_use field
is only used for the source window.  This patch moves the field there,
and changes it to be a bool at the same time.  (A future patch will
clean this up further, removing the field entirely.)

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_clear_source_content)
	(tui_show_source_content, tui_show_exec_info_content)
	(tui_clear_exec_info_content): Update.
	* tui/tui-stack.c (tui_show_locator_content): Update.
	(tui_show_frame_info): Update.
	* tui/tui-source.h (tui_source_window): Don't declare.
	* tui/tui-source.c (tui_source_window::showing_source_p): Rename
	from tui_source_is_displayed.
	* tui/tui-data.h (struct tui_gen_win_info) <content_in_use>:
	Remove field.
	(struct tui_source_window_base) <content_in_use>: New field.  Now
	bool.
	(struct tui_source_window) <showing_source_p>: New method.
	(TUI_SRC_WIN): Change cast.
	* tui/tui-data.c (tui_initialize_static_data): Update.
2019-07-17 12:19:06 -06:00
Tom Tromey c2cd899466 Introduce tui_source_window_base::location_matches_p method
This introduces the location_matches_p method, removing a spot that
explicitly examines a window's type.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_update_breakpoint_info): Use
	location_matches_p.
	* tui/tui-source.c (tui_source_window::location_matches_p): New
	method.
	* tui/tui-disasm.c (tui_disasm_window::location_matches_p): New
	method.
	* tui/tui-data.h (struct tui_source_window_base)
	<location_matches_p>: New method.
	(struct tui_source_window, struct tui_disasm_window)
	<location_matches_p>: Likewise.
2019-07-17 12:19:05 -06:00
Tom Tromey 4dde7b34f4 Remove tui_set_win_height
tui_set_win_height_command is just a simple wrapper for
tui_set_win_height, so rename the latter and remove the wrapper.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_win_height_command): Rename from
	tui_set_win_height.
	(tui_set_win_height_command): Remove.
2019-07-17 12:19:04 -06:00
Tom Tromey b73dd8779c Make source windows be self-updating
This changes the TUI source window to register itself on the
source_styling_changed observable, and removes a bit of code from
tui-hooks.c.  This reduces the number of uses of the TUI_SRC_WIN
global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-source.c (tui_source_window): New constructor.  Add
	observer.
	(~tui_source_window): New destructor.
	(tui_source_window::style_changed): New method.
	* tui/tui-hooks.c (tui_redisplay_source): Remove.
	(tui_attach_detach_observers): Update.
	* tui/tui-data.h (struct tui_source_window): Make constructor not
	inline.  Add destructor.
	(struct tui_source_window) <style_changed>: New method.
	<m_observable>: New member.
2019-07-17 12:19:04 -06:00
Tom Tromey ae2b53806d Fix comment typos
This fixes a couple of comment typos that I noticed.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.c (tui_clear_source_windows_detail): Fix typo.
	* tui/tui-win.c (tui_resize_all): Fix typo.
2019-07-17 12:19:03 -06:00
Tom Tromey 1ce3e8442e Introduce TUI window iterator
This introduces an iterator class and a range adapter to make it
simpler to iterate over TUI windows.

One explicit iteration remains, in tui-win.c, because that spot is
deleting windows as well.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.h (tui_refresh_all): Update.
	* tui/tui-wingeneral.c (make_all_visible): Use foreach.
	(tui_refresh_all): Remove "list" parameter.  Use foreach.
	* tui/tui-win.c (window_name_completer): Use foreach.
	(tui_refresh_all_win, tui_rehighlight_all, tui_all_windows_info)
	(update_tab_width): Likewise.
	* tui/tui-layout.c (show_layout): Update.
	* tui/tui-data.h (class tui_window_iterator): New.
	(struct all_tui_windows): New.
	* tui/tui-data.c (tui_partial_win_by_name): Use foreach.
2019-07-17 12:19:03 -06:00
Tom Tromey fe3eaf1cd9 Minor tui_reg_next / tui_reg_prev cleanup
This changes tui_reg_next and tui_reg_prev so that they don't need to
reference the TUI_DATA_WIN globals.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_reg_next, tui_reg_prev): Add "current_group"
	parameter.  Don't reference globals.
	(tui_reg_command): Update.
2019-07-17 12:19:02 -06:00
Tom Tromey 368c1354e5 Simplify tui_show_registers
tui_show_registers keeps a local status variable, but it is not
actually needed.  This rearranges the function to remove the variable.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_show_registers): Simplify.
2019-07-17 12:19:01 -06:00
Tom Tromey e80cd20470 Parameterize tui_show_register_group with window
This changes tui_show_register_group not to reference the TUI_DATA_WIN
global, instead leaving that to its caller.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_show_registers): Update.
	(tui_show_register_group): Add win_info parameter.
2019-07-17 12:19:01 -06:00
Tom Tromey aca2dd1647 Introduce tui_data_window::display_reg_element_at_line method
This changes tui_display_reg_element_at_line to be a method on
tui_data_window, allowing for the removal of some uses of the
TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::display_reg_element_at_line):
	Rename from tui_display_reg_element_at_line.
	(tui_data_window::display_registers_from_line): Update.
	* tui/tui-data.h (struct tui_data_window)
	<display_reg_element_at_line>: New method.
2019-07-17 12:19:00 -06:00
Tom Tromey 517e9505fa Introduce two more tui_data_window methods
This changes tui_display_registers_from and
tui_display_registers_from_line to be methods on tui_data_window,
allowing for the removal of more uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (tui_display_registers_from)
	(tui_display_registers_from_line): Don't declare.
	* tui/tui-windata.c (tui_data_window::display_all_data)
	(tui_data_window::refresh_all)
	(tui_data_window::do_scroll_vertical): Update.
	* tui/tui-regs.c (tui_data_window::display_registers_from): Rename
	from tui_display_registers_from.
	(tui_display_reg_element_at_line): Update.
	(tui_data_window::display_registers_from_line): Rename from
	tui_display_registers_from_line.
	* tui/tui-data.h (struct tui_data_window) <display_registers_from,
	display_registers_from_line>: New methods.
2019-07-17 12:18:59 -06:00
Tom Tromey f76d8b19e8 Introduce tui_data_window::erase_data_content method
This changes tui_erase_data_content to be a method on tui_data_window,
allowing for the removal of some uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_erase_data_content): Don't declare.
	* tui/tui-windata.c (tui_data_window::erase_data_content): Rename
	from tui_erase_data_content.
	(tui_data_window::display_all_data)
	(tui_data_window::refresh_all)
	(tui_data_window::do_scroll_vertical): Update.
	* tui/tui-regs.c (tui_show_registers): Update.
	* tui/tui-data.h (struct tui_data_window) <erase_data_content>:
	New method.
2019-07-17 12:18:59 -06:00
Tom Tromey b4094625d8 Introduce tui_data_window::delete_data_content_windows method
This changes tui_delete_data_content_windows to be a method on
tui_data_window, removing some uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_delete_data_content_windows): Don't
	declare.
	* tui/tui-windata.c
	(tui_data_window::delete_data_content_windows): Rename from
	tui_delete_data_content_windows.
	(tui_data_window::display_all_data)
	(tui_data_window::do_scroll_vertical): Update.
	* tui/tui-data.h (struct tui_data_window)
	<delete_data_content_windows>: New method.
2019-07-17 12:18:58 -06:00
Tom Tromey c223a7299e Don't declare unimplemented functions
A couple of functions were declared but never defined.  This removes
the declarations.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_refresh_data_win): Don't declare.
	* tui/tui-regs.h (tui_first_reg_element_inline): Don't declare.
2019-07-17 12:18:58 -06:00
Tom Tromey 50daf2683b Introduce tui_data_window::display_all_data method
This changes tui_display_all_data to be a method on tui_data_window.
This helps cluster uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_display_all_data): Don't declare.
	* tui/tui-windata.c (tui_data_window::display_all_data): Rename
	from tui_display_all_data.
	* tui/tui-win.c
	(tui_data_window::do_make_visible_with_new_height): Update.
	* tui/tui-regs.c (tui_show_registers): Update.
	* tui/tui-layout.c (tui_set_layout): Update.
	* tui/tui-data.h (struct tui_data_window) <display_all_data>: New
	method.
2019-07-17 12:18:57 -06:00
Tom Tromey df5f8cab00 Remove tui_display_data_from
tui_display_data_from is only called from a single place.  Inlining it
there lets us remove some uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_display_data_from): Don't declare.
	* tui/tui-windata.c (tui_display_data_from): Remove.
	(tui_data_window::refresh_all): Update.
2019-07-17 12:18:57 -06:00
Tom Tromey 80cb6c2709 Remove tui_display_data_from_line
tui_display_data_from_line is just a wrapper for
tui_display_registers_from_line, so remove it.  Also, nothing passed 0
as the "force_display" parameter to tui_display_registers_from_line,
so remove that parameter as well.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.h (tui_display_data_from_line): Don't declare.
	* tui/tui-windata.c (tui_display_data_from_line): Remove.
	(tui_display_data_from, tui_data_window::do_scroll_vertical): Call
	tui_display_registers_from_line.
	* tui/tui-regs.h (tui_display_registers_from_line): Update.
	* tui/tui-regs.c (tui_display_registers_from_line): Remove
	"force_display" parameter.
2019-07-17 12:18:54 -06:00
Tom Tromey baff0c28b8 Introduce tui_data_window::first_reg_element_no_inline
This changes tui_first_reg_element_no_inline to be a method on
tui_data_window.  This again moves uses of the TUI_DATA_WIN global
from this function into other functions that are already using the
global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (tui_first_reg_element_no_inline): Don't
	declare.
	* tui/tui-regs.c (tui_data_window::first_reg_element_no_inline):
	Rename from tui_first_reg_element_no_inline.
	(tui_display_reg_element_at_line)
	(tui_display_registers_from_line): Update.
	* tui/tui-data.h (struct tui_data_window)
	<first_reg_element_no_inline>: New method.
2019-07-17 12:18:54 -06:00
Tom Tromey 3b23c5f266 Introduce tui_data_window::line_from_reg_element_no method
This changes tui_line_from_reg_element_no to be a method on
tui_data_window, allowing for the removal of some uses of the
TUI_DATA_WIN global.  (Actually, in this particular patch, the number
of uses is not decreased, but rather the uses are moved to spots that
are already using the global, i.e., increasing the clustering.)

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-windata.c (tui_display_data_from)
	(tui_data_window::do_scroll_vertical): Update.
	* tui/tui-regs.h (tui_line_from_reg_element_no): Don't declare.
	* tui/tui-regs.c (tui_data_window::line_from_reg_element_no):
	Rename from tui_line_from_reg_element_no.
	(tui_display_registers_from_line): Update.
	* tui/tui-data.h (struct tui_data_window)
	<line_from_reg_element_no>: New method.
2019-07-17 12:18:53 -06:00
Tom Tromey 0b5ec21882 Introduce tui_data_window::last_regs_line_no method
This changes tui_last_regs_line_no into a method on tui_data_window,
allowing the removal of uses of the TUI_DATA_WIN global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (tui_last_regs_line_no): Don't declare.
	* tui/tui-regs.c (tui_data_window::last_regs_line_no): Rename from
	tui_last_regs_line_no.
	(tui_display_reg_element_at_line)
	(tui_display_registers_from_line): Update.
	* tui/tui-data.h (struct tui_data_window) <last_regs_line_no>: New
	method.
2019-07-17 12:18:53 -06:00
Tom Tromey 0807ab7b88 Remove deleted breakpoint from TUI display
PR tui/24722 points out that deleting a breakpoint does not cause the
"b" to be removed from the breakpoint display.  The issue here was
that the breakpoint still exists at the moment the breakpoint-deleted
observer is notified.  This fixes the problem by specially handling
the case where a breakpoint is being removed.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	PR tui/24722:
	* tui/tui-winsource.h (tui_update_all_breakpoint_info)
	(tui_update_breakpoint_info): Add "being_deleted" parameter.
	* tui/tui-winsource.c (tui_update_source_window_as_is): Update.
	(tui_update_all_breakpoint_info): Add "being_deleted" parameter.
	(tui_update_breakpoint_info): Likewise.
	* tui/tui-hooks.c (tui_event_create_breakpoint)
	(tui_event_delete_breakpoint, tui_event_modify_breakpoint):
	Update.
2019-07-17 12:18:53 -06:00
Tom Tromey 9ad7fdef7c Consolidate "if"s in tui_show_frame_info
tui_show_frame_info has two parallel "if"s with the same condition and
no intervening code.  The second "if" perhaps wasn't obviously
identical, but earlier refactorings made it clearer, by pointing out
that only source and disassembly windows can be handled here.  This
merges the two statements.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.c (tui_show_frame_info): Consolidate "if"s.
2019-07-17 12:18:52 -06:00
Tom Tromey 5813316fa4 Remove some uses of TUI_WIN_SRC
This adds a 'win_info' parameter to a couple of functions.  This
reduces the number of references to the TUI_WIN_SRC global.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c (tui_update_source_window_as_is)
	(tui_update_source_windows_with_addr): Update.
	* tui/tui-source.h (tui_set_source_content)
	(tui_show_symtab_source): Add "win_info" parameter.
	* tui/tui-source.c (tui_set_source_content): Add "win_info"
	parameter.
	(tui_show_symtab_source): Likewise.
2019-07-17 12:18:52 -06:00
Tom Tromey 00e264e762 Check can_highlight in tui_check_and_display_highlight_if_needed
tui_check_and_display_highlight_if_needed currently checks the
window's type; but this can be replaced with a check of
"can_highlight", making it more polymorphically-correct.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.c
	(tui_check_and_display_highlight_if_needed): Check can_highlight.
2019-07-17 12:18:51 -06:00
Tom Tromey 06210ce428 Introduce can_scroll method
This introduces a "can_scroll" method, removing a spot that explicitly
checks a window's type.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (struct tui_win_info) <can_scroll>: New method.
	(struct tui_cmd_window) <can_scroll>: New method.
	* tui/tui-command.c (tui_dispatch_ctrl_char): Use can_scroll
	method.
2019-07-17 12:18:51 -06:00
Tom Tromey 381befeedf Rename field_int to field_signed
This renames ui_out::field_int to field_signed, and field_fmt_int to
field_fmt_signed; and changes the type of the "value" parameter from
int to LONGEST.

Tested by the buildbot.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tromey@adacore.com>

	* ui-out.h (class ui_out) <field_signed, field_fmt_signed,
	do_field_signed>: Rename.  Change type of "value".
	* ui-out.c (ui_out::field_signed): Rename from field_int.
	Change type of "value".
	(ui_out::field_fmt_signed): Rename from field_fmt_int.  Change
	type of "value".
	* tui/tui-out.h (class tui_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* tui/tui-out.c (tui_ui_out::do_field_signed): Rename from
	do_field_int.  Change type of "value".
	* tracepoint.c (trace_status_mi, tfind_1)
	(print_one_static_tracepoint_marker): Update.
	* thread.c (print_thread_info_1, print_selected_thread_frame):
	Update.
	* stack.c (print_frame, print_frame_info): Update.
	* spu-tdep.c (info_spu_signal_command, info_spu_dma_cmdlist):
	Update.
	* source.c (print_source_lines_base): Update.
	* skip.c (info_skip_command): Update.
	* record-btrace.c (btrace_ui_out_decode_error)
	(btrace_call_history_src_line): Update.
	* python/py-framefilter.c (py_print_single_arg, py_print_frame):
	Update.
	* progspace.c (print_program_space): Update.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Update.
	* mi/mi-out.h (class mi_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* mi/mi-out.c (mi_ui_out::do_table_begin)
	(mi_ui_out::do_table_header): Update.
	(mi_ui_out::do_field_signed): Rename from do_field_int.  Change
	type of "value".
	* mi/mi-main.c (mi_cmd_thread_list_ids, print_one_inferior)
	(mi_cmd_data_list_changed_registers, output_register)
	(mi_cmd_data_read_memory, mi_load_progress)
	(mi_cmd_trace_frame_collected): Update.
	* mi/mi-interp.c (mi_on_normal_stop_1, mi_output_solib_attribs):
	Update.
	* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_create)
	(mi_cmd_var_delete, mi_cmd_var_info_num_children)
	(mi_cmd_var_list_children, varobj_update_one): Update.
	* mi/mi-cmd-stack.c (mi_cmd_stack_info_depth)
	(mi_cmd_stack_list_args, list_arg_or_local): Update.
	* mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file): Update.
	* inferior.c (print_inferior): Update.
	* gdb_bfd.c (print_one_bfd): Update.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Update.
	* darwin-nat-info.c (darwin_debug_regions_recurse): Update.
	* cli-out.h (class cli_ui_out) <do_field_signed>: Rename from
	do_field_int.  Change type of "value".
	* cli-out.c (cli_ui_out::do_field_signed): Rename from
	do_field_int.  Change type of "value".
	* breakpoint.c (watchpoint_check, print_breakpoint_location)
	(print_one_breakpoint_location, print_it_catch_fork)
	(print_one_catch_fork, print_it_catch_vfork)
	(print_one_catch_vfork, print_it_catch_solib)
	(print_it_catch_exec, print_it_ranged_breakpoint)
	(print_mention_watchpoint, print_mention_masked_watchpoint)
	(bkpt_print_it, update_static_tracepoint): Update.
	* break-catch-throw.c (print_it_exception_catchpoint): Update.
	* break-catch-syscall.c (print_it_catch_syscall): Update.
	* ada-tasks.c (print_ada_task_info): Update.
	* ada-lang.c (print_it_exception, print_mention_exception):
	Update.
2019-07-17 10:34:05 -06:00
Andrew Burgess 6b78c3f83c gdb: Remove a non-const reference parameter
Non-const reference parameter should be avoided according to the GDB
coding standard:

  https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Avoid_non-const_reference_parameters.2C_use_pointers_instead

This commit updates the gdbarch method gdbarch_stap_adjust_register,
and the one implementation i386_stap_adjust_register to avoid using a
non-const reference parameter.

I've also removed the kfail from the testsuite for bug 24541, as this
issue is now resolved.

gdb/ChangeLog:

	PR breakpoints/24541
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh: Adjust return type and parameter types for
	'stap_adjust_register'.
	(i386_stap_adjust_register): Adjust signature and return new
	register name.
	* stap-probe.c (stap_parse_register_operand): Adjust use of
	'gdbarch_stap_adjust_register'.

gdb/testsuite/ChangeLog:

	PR breakpoints/24541
	* gdb.mi/mi-catch-cpp-exceptions.exp: Remove kfail due to 24541.
2019-07-17 16:24:32 +01:00
Tom Tromey d72a9b8565 Remove a VEC from s390-linux-nat.c
This removes a use of VEC fro s390-linux-nat.c, replacing it with
std::vector.

Tested using the Fedora-s390x-m64 buildbot builder.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tromey@adacore.com>

	* s390-linux-nat.c (s390_watch_area): Remove typedef.  Don't
	declare VEC.
	(struct s390_debug_reg_state) <watch_areas, break_areas>: Now
	std::vector.
	(struct s390_process_info): Add initializers.
	(s390_add_process): Use new.
	(s390_linux_nat_target::low_forget_process): Use delete.
	(s390_linux_nat_target::low_new_fork)
	(s390_linux_nat_target::stopped_by_watchpoint)
	(s390_linux_nat_target::low_prepare_to_resume)
	(s390_linux_nat_target::insert_watchpoint)
	(s390_linux_nat_target::insert_hw_breakpoint)
	(s390_linux_nat_target::remove_watchpoint)
	(s390_linux_nat_target::remove_hw_breakpoint): Update.
2019-07-17 07:29:58 -06:00
John Baldwin 206e6c58a7 Fix build for aarch64, arm, and riscv FreeBSD native targets.
Remove unused gdbarch argument to helper functions originally
copied from mips-fbsd-nat.c.  Include regcache.h previously
included from defs.h via gdbarch.h.

gdb/ChangeLog:

	* aarch64-fbsd-nat.c: Include regcache.h.
	(getregs_supplies, getfpregs_supplies): Remove unused gdbarch
	argument.
	(aarch64_fbsd_nat_target::fetch_registers)
	(aarch64_fbsd_nat_target::store_registers): Remove gdbarch
	variable.
	* arm-fbsd-nat.c, riscv-fbsd-nat.c: Likewise.
2019-07-15 17:21:36 -07:00
John Baldwin cbde90f25e Add include of gdbarch.h.
gdb/ChangeLog:

	* fbsd-nat.c: Include gdbarch.h.
2019-07-15 17:21:36 -07:00
Tom Tromey 07128006d6 Fix a FIXME in mi-out.c
This removes a FIXME comment from mi_ui_out::do_field_int, by
replacing a printf with a use of plongest.

2019-07-15  Tom Tromey  <tromey@adacore.com>

	* mi/mi-out.c (mi_ui_out::do_field_int): Use plongest.
2019-07-15 09:31:19 -06:00
Tom Tromey 1f77b012e6 Introduce field_unsigned
This adds field_unsigned and changes various places using field_fmt
with "%u" to use this instead.  This also replaces an existing
equivalent helper function in record-btrace.c.

2019-07-15  Tom Tromey  <tromey@adacore.com>

	* mi/mi-out.h (class mi_ui_out) <do_field_unsigned>: Declare.
	* mi/mi-out.c (mi_ui_out::do_field_unsigned): New method.
	* cli-out.h (class cli_ui_out) <do_field_unsigned>: Declare.
	* cli-out.c (cli_ui_out::do_field_int): New method.
	* ui-out.c (ui_out::field_unsigned): New method.
	* symfile.c (generic_load): Use field_unsigned.
	(print_transfer_performance): Likewise.
	* record-btrace.c (ui_out_field_uint): Remove.
	(btrace_call_history_insn_range, btrace_call_history): Use
	field_unsigned.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Use
	field_unsigned.
	* ui-out.h (class ui_out) <field_unsigned>: New method.
	<do_field_unsigned>: Likewise.
2019-07-15 09:31:18 -06:00
Tom Tromey 33eca68072 Use field_string in more places
This replaces uses of field_fmt with a "%s" format string to use
field_string instead.  Also, one use of "%9lx" is replaced with a call
to phex_nz; the '9' is dropped as it is implicit in the field width.

2019-07-15  Tom Tromey  <tromey@adacore.com>

	* mi/mi-main.c (list_available_thread_groups): Use field_string.
	* mi/mi-interp.c (mi_memory_changed): Use field_string.
	* target.c (flash_erase_command): Use field_string.
	* infrun.c (print_signal_received_reason): Use field_string.
	* i386-tdep.c (i386_mpx_print_bounds): Use field_string.
	* breakpoint.c (maybe_print_thread_hit_breakpoint): Use
	field_string.
	* ada-tasks.c (print_ada_task_info): Use field_string.
2019-07-15 09:31:18 -06:00
Tom Tromey ca8d69beb1 Use field_core_addr in more places
This changes a few spots that use field_fmt to use field_core_addr
instead.

gdb/ChangeLog
2019-07-15  Tom Tromey  <tromey@adacore.com>

	* target.c (flash_erase_command): Use field_core_addr.
	* symfile.c (generic_load): Use field_core_addr.
	* sparc64-linux-tdep.c (sparc64_linux_handle_segmentation_fault):
	Use field_core_addr.
	* i386-linux-tdep.c (i386_linux_handle_segmentation_fault): Use
	field_core_addr.
2019-07-15 09:28:59 -06:00
Tom de Vries da73816739 [gdb/testsuite] Fix unterminated string in gdb.objc/basicclass.exp
The test-case gdb.objc/basicclass.exp contains an unterminated string,
introduced in refactoring commit fa43b1d7ca "after gdb_run_cmd, gdb_expect ->
gdb_test_multiple/gdb_test".

Fix the unterminated string.

gdb/testsuite/ChangeLog:

2019-07-14  Tom de Vries  <tdevries@suse.de>

	PR testsuite/24760
	* gdb.objc/basicclass.exp: Fix unterminated string.
2019-07-14 13:23:04 +02:00
Andrew Burgess 0d4e84ed37 gdb: Better support for dynamic properties with negative values
When the type of a property is smaller than the CORE_ADDR in which the
property value has been placed, and if the property is signed, then
sign extend the property value from its actual type up to the size of
CORE_ADDR.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Sign extend property
	value if its desired type is smaller than a CORE_ADDR and signed.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-ptype.exp: Print array with negative bounds.
	* gdb.fortran/vla-sizeof.exp: Print the size of an array with
	negative bounds.
	* gdb.fortran/vla-value.exp: Print elements of an array with
	negative bounds.
	* gdb.fortran/vla.f90: Setup an array with negative bounds for
	testing.
2019-07-12 12:09:55 +01:00
Andrew Burgess 9a49df9d4b gdb: Carry default property type around with dynamic properties
This commit is preparation for the next one, with the aim of better
supporting signed dynamic properties on targets where the address size
specified in the DWARF headers is smaller than a CORE_ADDR, for
example debugging an i386 application on x86-64.

Consider this small Fortran program 'bounds.f90':

    program test
      integer, allocatable :: array (:)
      allocate (array (-5:5))
      array(3) = 1
    end program test

Compiled with 'gfortran -m32 -g3 -O0 -o bounds bounds.f90'.  The DWARF
for 'array' looks like this:

   <2><97>: Abbrev Number: 10 (DW_TAG_variable)
      <98>   DW_AT_name        : (indirect string, offset: 0x0): array
      <9c>   DW_AT_decl_file   : 1
      <9d>   DW_AT_decl_line   : 2
      <9e>   DW_AT_type        : <0xaf>
      <a2>   DW_AT_location    : 2 byte block: 91 58              (DW_OP_fbreg: -40)
   <2><a5>: Abbrev Number: 11 (DW_TAG_lexical_block)
      <a6>   DW_AT_low_pc      : 0x80485c3
      <aa>   DW_AT_high_pc     : 0x8b
   <2><ae>: Abbrev Number: 0
   <1><af>: Abbrev Number: 12 (DW_TAG_array_type)
      <b0>   DW_AT_data_location: 2 byte block: 97 6              (DW_OP_push_object_address; DW_OP_deref)
      <b3>   DW_AT_allocated   : 4 byte block: 97 6 30 2e         (DW_OP_push_object_address; DW_OP_deref; DW_OP_lit0; DW_OP_ne)
      <b8>   DW_AT_type        : <0x2a>
   <2><bc>: Abbrev Number: 13 (DW_TAG_subrange_type)
      <bd>   DW_AT_lower_bound : 4 byte block: 97 23 10 6         (DW_OP_push_object_address; DW_OP_plus_uconst: 16; DW_OP_deref)
      <c2>   DW_AT_upper_bound : 4 byte block: 97 23 14 6         (DW_OP_push_object_address; DW_OP_plus_uconst: 20; DW_OP_deref)
      <c7>   DW_AT_byte_stride : 6 byte block: 97 23 c 6 34 1e    (DW_OP_push_object_address; DW_OP_plus_uconst: 12; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
   <2><ce>: Abbrev Number: 0

If we look at the DW_AT_lower_bound attribute, which will become a
dynamic property that GDB evaluates when needed by calling
dwarf2_evaluate_property.

The process of evaluating a dynamic property requires GDB to execute
each DW_OP_* operation, the results of these operations is held on a
stack of 'struct value *'s.

When the entire expression is evaluated the result is on top of the
stack.

If we look at DW_AT_lower_bound then the last operation is
DW_OP_deref, this loads a signed address the size of which matches the
DWARF address size, and so in our i386 on x86-64 situation, the top of
the stack will be a signed 4-byte value.

The problem is how these values are fetched from the stack.  Currently
they are always fetched by a call to dwarf_expr_context::fetch_address,
which converts the value to an unsigned value with a length matching
the values current length, before converting to a CORE_ADDR.  This
means we loose the signed nature of the property.

I wonder if the best solution for dealing with signed properties will
be to move away from an over reliance on fetch_address, and instead
come up with a new solution that considers the current type of the
value on the stack, and the type that the value needs to become;
basically a solution built around casting rather than assuming we
always want an address.

However, before we can start to even think about moving away from
fetch_address, there is a more urgent issue to fix, which is we don't
currently know what type each property should be.  We just hold the
value of the property in a CORE_ADDR as returned by fetch_address, and
rely on higher level code (outside of the DWARF expression evaluation
code) to fix things up for us.  This is what this patch aims to
address.

When creating a dynamic property (see attr_to_dynamic_prop in
dwarf2read.c) we can sometimes figure out the type of a property; if
the property is a reference to another DIE then it will have a
DW_AT_type attribute.

However, the DW_AT_lower_bound case above isn't a reference to another
DIE, it's just a DWARF expression.  We don't have any indication for
what type the property should have.

Luckily, the DWARF spec helps us out, for the lower and upper bounds
5.13 of the DWARFv5 spec tells us that without any other type
information the bounds are signed integers the same size as a DWARF
address.

It is my belief that we can find a suitable default type for every
dynamic property, either specified explicitly in the DWARF spec, or we
can infer an obvious choice if the spec doesn't help us.

This commit extends the creation of all dynamic properties to include
suggesting a suitable default type, all dynamic properties now always
carry their type around with them.

In later commits we can use this property type to ensure that the
value we extract from the DWARF stack is handled in a suitable manor
to correctly maintain its sign extension.

There should be no user visible changes from this commit.  The actual
fix to correctly support negative array bounds will come later.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Update to take account
	of changes to field names, and use new is_reference field to
	decide if a property is a reference or not.
	* dwarf2loc.h (struct dwarf2_locexpr_baton): Add 'is_reference'
	field.
	(struct dwarf2_property_baton): Update header comment, rename
	'referenced_type' to 'property_type' and update comments.
	* dwarf2read.c (attr_to_dynamic_prop): Add extra parameter to hold
	default property type, store in property baton, update to take
	accound of renamed field.
	(read_func_scope): Update call to attr_to_dynamic_prop.
	(read_array_type): Likewise.
	(dwarf2_per_cu_addr_sized_int_type): New function.
	(read_subrange_index_type): Move type finding code to
	dwarf2_per_cu_addr_sized_int_type.
	(read_subrange_type): Update calls to attr_to_dynamic_prop.
	(dwarf2_per_cu_addr_type): New function.
	(set_die_type): Update calls to attr_to_dynamic_prop.
2019-07-12 12:09:54 +01:00
Andrew Burgess b86352cfc1 gdb/dwarf: Ensure the target type of ranges is not void
If a DW_TAG_subrange_type DWARF entry has no DW_AT_type then a default
type based on the size of an address on the current target is assumed.
We store this type as the target type for GDB's range types.

Currently GDB can create ranges for which the target type is VOID,
this is incorrect but seems to cause no problems. I believe the reason
this doesn't cause any issues is because the languages (for example
Ada) that actually make use of a ranges target type also have
compilers that generate DWARF that includes a DW_AT_type attribute.

However, gfortran does not include a DW_AT_type, its DWARF instead
relies on the default target type.  This isn't currently a problem for
GDB as gfortran doesn't make use of the target type when printing
subranges, but it shouldn't hurt to fix this issue now.

I've added an assert into create_range_type that will catch this issue
if it comes up again.

This was tested on an x86-64/GNU-Linux machine with both the Ada and
gfortran compilers available with both '--target_board=unix' and
'--target_board=unix/-m32'.  There are no user visible changes after
this commit.

gdb/ChangeLog:

	* dwarf2read.c (read_subrange_index_type): New function.
	(read_subrange_type): Move code into new function and call it.
	* gdbtypes.c (create_range_type): Add some asserts.
2019-07-12 12:09:53 +01:00
Andrew Burgess 603490bf53 gdb: Convert dwarf2_evaluate_property to return bool
Convert dwarf2_evaluate_property to return a bool, there should be no
user visible change after this commit.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Change return type, and
	update return statements.
	* dwarf2loc.h (dwarf2_evaluate_property): Update return type on
	declaration, and update comment to match.
	* gdbtypes.c (resolve_dynamic_array): Update call to
	dwarf2_evaluate_property to match new return type.
2019-07-12 12:09:52 +01:00
Andrew Burgess 592f9d271c gdb: Update type of lower bound in value_subscripted_rvalue
The dynamic lower (and upper) bounds of ranges are stored as type
LONGEST (see union dynamic_prop_data in gdbtypes.h).  In most places
that range bounds are handled they are held in a LONGEST, however in
value_subscripted_rvalue the bound is placed into an int.

This commit changes value_subscripted_rvalue to use LONGEST, there
should be no user visible changes after this commit.

gdb/ChangeLog:

	* valarith.c (value_subscripted_rvalue): Change lowerbound
	parameter type from int to LONGEST.
	* value.h (value_subscripted_rvalue): Likewise in declaration.
2019-07-12 12:09:52 +01:00
Andrew Burgess 60cfcb20ce gdb: Add command completers for some info commands
Add command completion for info variables, functions, args, and
locals.  This completer only completes the command line options as
these commands all take a regexp which GDB can't really offer
completions for.

gdb/ChangeLog:

	* cli/cli-utils.c (info_print_command_completer): New function.
	* cli/cli-utils.h: Add 'completer.h' include, and forward
	declaration for 'struct cmd_list_element'.
	(info_print_command_completer): Declare.
	* stack.c (_initialize_stack): Add completer for 'info locals' and
	'info args'.
	* symtab.c (_initialize_symtab): Add completer for 'info
	variables' and 'info functions'.
	* NEWS: Mention completion for additional info commands.
2019-07-11 20:19:24 +01:00
Andrew Burgess b16507e091 gdb: Make use of gdb::option framework for some info commands
Update the 'info variables', 'info functions', 'info locals', and
'info args' commands to make use of the gdb::options framework.

There should be no user visible changes after this commit as I have
left the help text generation using the existing mechanism, which
already tries to customise the text for each of the commands.

gdb/ChangeLog:

	* cli/cli-utils.c (extract_info_print_args): Delete.
	(extract_arg_maybe_quoted): Delete.
	(info_print_options_defs): New variable.
	(make_info_print_options_def_group): New function.
	(extract_info_print_options): Define new function.
	* cli/cli-utils.h (extract_info_print_args): Delete.
	(struct info_print_options): New structure.
	(extract_info_print_options): Declare new function.
	* stack.c (info_locals_command): Update to use new
	extract_info_print_options, also add a header comment.
	(info_args_command): Likewise.
	* symtab.c (info_variables_command): Likewise.
	(info_functions_command): Likewise.
2019-07-11 20:18:17 +01:00
Andrew Burgess 021d8588f6 gdb: Allow quoting around string options in the gdb::option framework
Currently string options must be a single string with no whitespace,
this limitation prevents the gdb::option framework being used in some
places.

After this commit, string options can be quoted in single or double
quotes, and quote characters can be escaped with a backslash if needed
to either place them within quotes, or to avoid starting a quoted
argument.

This test adds a new function extract_string_maybe_quoted which is
basically a copy of extract_arg_maybe_quoted from cli/cli-utils.c,
however, the cli-utils.c function will be deleted in the next commit.

There are tests to exercise the new quoting mechanism.

gdb/ChangeLog:

	* cli/cli-option.c (parse_option): Use extract_string_maybe_quoted
	to extract string arguments.
	* common/common-utils.c (extract_string_maybe_quoted): New function.
	* common/common-utils.h (extract_string_maybe_quoted): Declare.

gdb/testsuite/ChangeLog:

	* gdb.base/options.exp (expect_string): Dequote strings in
	results.
	(test-string): Test strings with different quoting and reindent.
2019-07-11 20:18:11 +01:00
Tom Tromey b777eb6de2 Remove init_cli_cmds
I noticed that init_cli_cmds only installs a command, and so doesn't
need to be handled specially.  This patch merges it into
_initialize_cli_cmds.

The help text is constructed dynamically, which is sometimes an
indication that special treatment is needed; but in this case it is
just to insert the value of "gdbinit", which is created at
compile-time and not modified; so this doesn't affect the result.

This version also removes the "gdbinit" global.  There's no need for
it, as GDBINIT can be used instead.  Note, though, that the help text
in question must still be dynamically constructed, in order to be
i18n-friendly.

gdb/ChangeLog
2019-07-11  Tom Tromey  <tromey@adacore.com>

	* main.c (get_init_files): Use GDBINIT, not gdbinit.
	* auto-load.c (file_is_auto_load_safe): Use GDBINIT, not gdbinit.
	* top.h (gdbinit): Don't declare.
	* cli/cli-cmds.c (init_cli_cmds): Remove, merging contents
	into...
	(_initialize_cli_cmds): ...here.  Use GDBINIT, not gdbinit.
	* top.c (gdb_init): Don't call init_cli_cmds.
	(gdbinit): Remove.
	* cli/cli-cmds.h (init_cli_cmds): Don't declare.
2019-07-11 10:28:27 -06:00
Tom Tromey 72ee03ff58 Fix use-after-move bug in add_thread_object
commit 05b08ac160 ("Reduce manual reference counting in
py-inferior.c") introduced a use-after-move bug in add_thread_object,
causing a test suite failure.  This patch fixes the bug.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-11  Tom Tromey  <tromey@adacore.com>

	* python/py-inferior.c (add_thread_object): Don't use thread_obj
	after it has been moved.
2019-07-11 09:15:18 -06:00
Simon Marchi 00db953196 Make value_must_coerce_to_target return a bool
... and move comment to header file.

gdb/ChangeLog:

	* valops.c (value_must_coerce_to_target): Change return type to
	bool.
	* value.h (value_must_coerce_to_target): Likewise.
2019-07-10 21:49:32 -04:00
Simon Marchi f2478a7e8b breakpoint: Make is_*point functions return bool
This includes changing the FILTER parameters of two functions
accordingly.  I also tried to normalize the function comments to our
current standards.

gdb/ChangeLog:

	* breakpoint.c (is_hardware_watchpoint): Remove
	forward-declaration.
	(is_masked_watchpoint): Change return type to bool.
	(is_tracepoint): Likewise.
	(is_breakpoint): Likewise.
	(is_hardware_watchpoint): Likewise.
	(is_watchpoint): Likewise.
	(is_no_memory_software_watchpoint): Likewise.
	(is_catchpoint): Likewise.
	(breakpoint_1): Make FILTER parameter's return type bool.
	is_masked_watchpoint): Change return type to bool.
	(save_breakpoints): Make FILTER parameter's return type bool.
	* breakpoint.h (is_breakpoint): Change return type to bool.
	(is_watchpoint): Likewise.
	(is_catchpoint): Likewise.
	(is_tracepoint): Likewise.
2019-07-10 21:20:50 -04:00
Tom Tromey 0d12e84cfc Don't include gdbarch.h from defs.h
I touched symtab.h and was surprised to see how many files were
rebuilt.  I looked into it a bit, and found that defs.h includes
gdbarch.h, which in turn includes many things.

gdbarch.h is only needed by a minority ofthe files in gdb, so this
patch removes the include from defs.h and updates the fallout.

I did "wc -l" on the files in build/gdb/.deps; this patch reduces the
line count from 139935 to 137030; so there are definitely future
build-time savings here.

Note that while I configured with --enable-targets=all, it's possible
that some *-nat.c file needs an update.  I could not test all of
these.  The buildbot caught a few problems along these lines.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tom@tromey.com>

	* defs.h: Don't include gdbarch.h.
	* aarch64-ravenscar-thread.c, aarch64-tdep.c, alpha-bsd-tdep.h,
	alpha-linux-tdep.c, alpha-mdebug-tdep.c, arch-utils.h, arm-tdep.h,
	ax-general.c, btrace.c, buildsym-legacy.c, buildsym.h, c-lang.c,
	cli/cli-decode.h, cli/cli-dump.c, cli/cli-script.h,
	cli/cli-style.h, coff-pe-read.h, compile/compile-c-support.c,
	compile/compile-cplus.h, compile/compile-loc2c.c, corefile.c,
	cp-valprint.c, cris-linux-tdep.c, ctf.c, d-lang.c, d-namespace.c,
	dcache.c, dicos-tdep.c, dictionary.c, disasm-selftests.c,
	dummy-frame.c, dummy-frame.h, dwarf2-frame-tailcall.c,
	dwarf2expr.c, expression.h, f-lang.c, frame-base.c,
	frame-unwind.c, frv-linux-tdep.c, gdbarch-selftests.c, gdbtypes.h,
	go-lang.c, hppa-nbsd-tdep.c, hppa-obsd-tdep.c, i386-dicos-tdep.c,
	i386-tdep.h, ia64-vms-tdep.c, interps.h, language.c,
	linux-record.c, location.h, m2-lang.c, m32r-linux-tdep.c,
	mem-break.c, memattr.c, mn10300-linux-tdep.c, nios2-linux-tdep.c,
	objfiles.h, opencl-lang.c, or1k-linux-tdep.c, p-lang.c,
	parser-defs.h, ppc-tdep.h, probe.h, python/py-record-btrace.c,
	record-btrace.c, record.h, regcache-dump.c, regcache.h,
	riscv-fbsd-tdep.c, riscv-linux-tdep.c, rust-exp.y,
	sh-linux-tdep.c, sh-nbsd-tdep.c, source-cache.c,
	sparc-nbsd-tdep.c, sparc-obsd-tdep.c, sparc-ravenscar-thread.c,
	sparc64-fbsd-tdep.c, std-regs.c, target-descriptions.h,
	target-float.c, tic6x-linux-tdep.c, tilegx-linux-tdep.c, top.c,
	tracefile.c, trad-frame.c, type-stack.h, ui-style.c, utils.c,
	utils.h, valarith.c, valprint.c, varobj.c, x86-tdep.c,
	xml-support.h, xtensa-linux-tdep.c, cli/cli-cmds.h: Update.
	* s390-linux-nat.c, procfs.c, inf-ptrace.c: Likewise.
2019-07-10 14:53:53 -06:00
Tom Tromey f06f1252b0 Change Ada catchpoints to be bp_catchpoint
Like Pedro's earlier patches to change catchpoint to be of type
bp_catchpoint, this changes the Ada catchpoints to follow.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.h (is_ada_exception_catchpoint): Declare.
	* breakpoint.c (init_ada_exception_breakpoint): Register as
	bp_catchpoint.
	(print_one_breakpoint_location, print_one_breakpoint): Use
	is_ada_exception_catchpoint.
	* ada-lang.c (class ada_catchpoint_location): Pass
	bp_loc_software_breakpoint to bp_location constructor.
	(is_ada_exception_catchpoint): New function.

gdb/testsuite/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/mi_ex_cond.exp: Update expected results.
	* gdb.ada/mi_catch_ex_hand.exp: Update expected results.
	* gdb.ada/mi_catch_ex.exp: Update expected results.
	* gdb.ada/mi_catch_assert.exp: Update expected results.
	* gdb.ada/catch_ex.exp (catch_exception_info)
	(catch_exception_entry, catch_assert_entry)
	(catch_unhandled_entry): Update.
	* gdb.ada/catch_assert_if.exp: Update expected results.
2019-07-10 14:48:53 -06:00
Tom Tromey 7a5d944b9e Change arm-tdep.c to use type-safe registry
This changes arm-tdep.c to use the type-safe registry, removing a use
of VEC in the process.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* arm-tdep.c (arm_exidx_entry_s): Remove typedef.  Don't define
	VEC.
	(struct arm_exidx_entry): New method operator<.
	(struct arm_exidx_data) <section_maps>: Change type.
	(arm_exidx_data_free): Remove.
	(arm_exidx_data_key): Change type.  Move lower.
	(arm_exidx_new_objfile): Update.
	(arm_compare_exidx_entries): Remove.
	(arm_find_exidx_entry, _initialize_arm_tdep)
2019-07-10 14:34:11 -06:00
Tom Tromey 48c66e1d07 Change solib-spu.c to use type-safe registry
This changes solib-spu.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-spu.c (ocl_program_data_key): Change type.
	(append_ocl_sos, ocl_enable_break, _initialize_spu_solib):
	Update.
2019-07-10 14:34:11 -06:00
Tom Tromey a269fbf12d Change solib-aix.c to use type-safe registry
This changes solib-aix.c to use the type-safe registry, and removes a
use of VEC in the process.

gdb/ChangeLog
2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-aix.c (lm_info_aix_p): Remove typedef.  Don't define VEC.
	(struct solib_aix_inferior_data) <library_list>: Change type.
	(solib_aix_inferior_data_handle): Change type.
	(get_solib_aix_inferior_data): Update.
	(solib_aix_free_library_list): Remove.
	(library_list_start_library): Update.
	(solib_aix_parse_libraries, solib_aix_get_library_list): Change
	return type.
	(solib_aix_get_library_list)
	(solib_aix_solib_create_inferior_hook, solib_aix_current_sos)
	(solib_aix_normal_stop_observer, _initialize_solib_aix): Update.
2019-07-10 14:34:09 -06:00
Tom Tromey c294730c54 Change solib-dsbt.c to use type-safe registry
This changes solib-dsbt.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* solib-dsbt.c (struct dsbt_info): Add initializers.
	(solib_dsbt_pspace_data): Change type.
	(dsbt_pspace_data_cleanup): Remove.
	(get_dsbt_info, _initialize_dsbt_solib): Update.
2019-07-10 12:43:38 -06:00
Tom Tromey 9d52077d65 Change spu-tdep.c to use type-safe registry
This changes spu-tdep.c to use the type-safe registry.

2019-07-10  Tom Tromey  <tromey@adacore.com>

	* spu-tdep.c (spu_overlay_data): Change type.
	(spu_get_overlay_table, spu_overlay_new_objfile)
	(_initialize_spu_tdep): Update.
2019-07-10 12:43:38 -06:00