Commit Graph

923 Commits

Author SHA1 Message Date
Simon Marchi
5538b03c98 gdb: remove cmd_list_element::function::sfunc
I don't understand what the sfunc function type in
cmd_list_element::function is for.  Compared to cmd_simple_func_ftype,
it has an extra cmd_list_element parameter, giving the callback access
to the cmd_list_element for the command being invoked.  This allows
registering the same callback with many commands, and alter the behavior
using the cmd_list_element's context.

From the comment in cmd_list_element, it sounds like at some point it
was the callback function type for set and show functions, hence the
"s".  But nowadays, it's used for many more commands that need to access
the cmd_list_element object (see add_catch_command for example).

I don't really see the point of having sfunc at all, since do_sfunc is
just a trivial shim that changes the order of the arguments.  All
commands using sfunc could just as well set cmd_list_element::func to
their callback directly.

Therefore, remove the sfunc field in cmd_list_element and everything
that goes with it.  Rename cmd_const_sfunc_ftype to cmd_func_ftype and
use it for cmd_list_element::func, as well as for the add_setshow
commands.

Change-Id: I1eb96326c9b511c293c76996cea0ebc51c70fac0
2021-07-23 15:38:54 -04:00
Simon Marchi
0c1bcd2327 gdb: convert obj_section macros to methods
Convert these three macros to methods of obj_section.  The problem fixed
by the following patch is caused by an out of bound access of the
objfile::section_offsets vector.  Since this is deep in macros, we don't
get a clear backtrace and it's difficult to debug.  Changing that to
methods means we can step in them and break on them.

Because their implementation requires knowing about struct objfile, move
struct obj_section below struct objfile in objfiles.h.

The obj_section_offset was used in one place as an lvalue to set
offsets, in machoread.c.  Replace that with a set_offset method.

Add the objfile::section_offset and objfile::set_section_offset methods
to improve encapsulation (reduce other objects poking into struct
objfile's internals).

gdb/ChangeLog:

	* objfiles.h (struct obj_section): Move down.
	<offset, set_offset, addr, endaddr>: New.
	(obj_section_offset, obj_section_addr, obj_section_endaddr),
	replace all users to use obj_section methods.
	(struct objfile) <section_offset, set_section_offset>: New.

Change-Id: I97e8fcae93ab2353fbdadcb4a5ec10d7949a7334
2021-06-28 15:28:26 -04:00
Simon Marchi
0f8e203412 gdb: add context getter/setter to cmd_list_element
Straightforward replacement of get_cmd_context / set_cmd_context with
cmd_list_element methods.

gdb/ChangeLog:

	* cli/cli-decode.h (struct cmd_list_element) <set_context,
	context>: New.
	<context>: Rename to...
	<m_context>: ... this.
	* cli/cli-decode.c (set_cmd_context, get_cmd_context): Remove.
	* command.h (set_cmd_context, get_cmd_context): Remove, use
	cmd_list_element::set_context and cmd_list_element::context
	everywhere instead.

Change-Id: I5016b0079014e3f17d1aa449ada7954473bf2b5d
2021-06-25 21:35:40 -04:00
Pedro Alves
82a5082ed3 Make the TUI command window support the mouse
Currently, when the focus is on the command window, we disable the
keypad.  This means that when the command window has the focus, keys
such as up/down/home/end etc. are not processed by curses, and their
escape sequences go straight to readline.

A side effect of disabling keypad mode is that wgetch no longer
processes mouse escape sequences, with the end result being the mouse
doesn't work, and worse, the raw mouse escape sequences are printed on
the terminal.

This commit makes the TUI command window support the mouse as well, by
always enabling the keypad, and then to avoid losing support for
up/down browsing the command history, home/end/left/right moving the
cursor position, etc., we forward those keys as raw escape sequences
to readline.  Note we don't make an effort to pass down to readline
all keys returned by curses, only the common ones that readline
understands by default.  Given users can specify their own readline
bindings (inputrc file, bind utility), this approach is good in
practice, though not 100% transparent or perfect.

Note that the patch makes it so that CTLC-L is always passed to
readline even if the command window does not have the focus.  It was
simpler to implement that way, and it just seems correct to me.  I
don't know of a reason we shouldn't do that.

The patch improves the TUI behavior in a related way.  Now we can pass
special keys to readline irrespective of which window has the focus.
First, we try to dispatch the key to a window, via
tui_displatch_ctrl_char.  If the key is dispatched, then we don't pass
it to readline.  E.g., pressing "up" when you have the source window
in focus results in scrolling the source window, and nothing else.  If
however, you press ctrl-del instead, that results in killing the next
word in the command window, no matter which window has has focus.
Before, it would only work if you had the command window in focus.
Similarly, ctrl-left/ctrl-right to move between words, etc.

Similarly, the previous spot where we handled mouse events was
incorrect.  It was never reached if the window with focus can't
scroll, which is the case for the command window.  Mouse scrolling
affects the window under the mouse cursor, not the window in focus.
We now always try to dispatch mouse events.

One last bit in the patch -- now if we don't recognize the non-8-bit
curses key, then we don't pass it down to readline at all.  Before
that would result in bogus characters in the input line.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* tui/tui-io.c (tui_dispatch_mouse_event): New, factored out from
	...
	(tui_dispatch_ctrl_char): ... this.  Move CTRL-L handling to
	tui_getc_1.
	(cur_seq, start_sequence): New.
	(tui_getc_1): Pass key escape sequences for curses control keys to
	readline.  Handle mouse and ctrl-l here.
	(tui_resize_all): Disable/reenable the keypad if the command
	window has the focus too.
	* tui/tui-win.c (tui_set_focus_command): Don't change keypad
	setting.
	* tui/tui.c (tui_rl_other_window): Don't change keypad setting.

Change-Id: Ie0a7d849943cfb47f4a6589e1c73341563740fa9
2021-06-17 11:57:56 +01:00
Hannes Domani
1bace02a96 Initial TUI mouse support
Implements an overridable tui_win_info::click method whose arguments
are the mouse coordinates inside the specific window, and the mouse
button clicked.

And if the curses implementation supports 5 buttons, the 4th and 5th
buttons are used for scrolling.

gdb/ChangeLog:

2021-06-04  Hannes Domani  <ssbssa@yahoo.de>

	* ser-mingw.c (console_select_thread): Handle MOUSE_EVENT.
	* tui/tui-data.h (struct tui_win_info): Add click function.
	* tui/tui-io.c (tui_prep_terminal): Enable mouse events.
	(tui_deprep_terminal): Disable mouse events.
	(tui_dispatch_ctrl_char): Handle KEY_MOUSE.
	* tui/tui.c (tui_disable): Disable mouse events.
2021-06-04 16:15:01 +02:00
Simon Marchi
240edef62f gdb: remove iterate_over_breakpoints function
Now that we have range functions that let us use ranged for loops, we
can remove iterate_over_breakpoints in favor of those, which are easier
to read and write.  This requires exposing the declaration of
all_breakpoints and all_breakpoints_safe in breakpoint.h, as well as the
supporting types.

Change some users of iterate_over_breakpoints to use all_breakpoints,
when they don't need to delete the breakpoint, and all_breakpoints_safe
otherwise.

gdb/ChangeLog:

	* breakpoint.h (iterate_over_breakpoints): Remove.  Update
	callers to use all_breakpoints or all_breakpoints_safe.
	(breakpoint_range, all_breakpoints, breakpoint_safe_range,
	all_breakpoints_safe): Move here.
	* breakpoint.c (all_breakpoints, all_breakpoints_safe): Make
	non-static.
	(iterate_over_breakpoints): Remove.
	* python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb):
	Return void.
	* python/py-breakpoint.c (build_bp_list): Add comment, reverse
	return value logic.
	* guile/scm-breakpoint.c (bpscm_build_bp_list): Return void.

Change-Id: Idde764a1f577de0423e4f2444a7d5cdb01ba5e48
2021-05-27 14:58:37 -04:00
Simon Marchi
40cb8ca539 gdb: add breakpoint::locations method
Add the breakpoint::locations method, which returns a range that can be
used to iterate over a breakpoint's locations.  This shortens

  for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next)

into

  for (bp_location *loc : b->locations ())

Change all the places that I found that could use it.

gdb/ChangeLog:

	* breakpoint.h (bp_locations_range): New.
	(struct breakpoint) <locations>: New.  Use where possible.

Change-Id: I1ba2f7d93d57e544e1f8609124587dcf2e1da037
2021-05-27 14:58:37 -04:00
Simon Marchi
3947f654ea gdb: make add_com_alias accept target as a cmd_list_element
The alias creation functions currently accept a name to specify the
target command.  They pass this to add_alias_cmd, which needs to lookup
the target command by name.

Given that:

 - We don't support creating an alias for a command before that command
   exists.
 - We always use add_info_alias just after creating that target command,
   and therefore have access to the target command's cmd_list_element.

... change add_com_alias to accept the target command as a
cmd_list_element (other functions are done in subsequent patches).  This
ensures we don't create the alias before the target command, because you
need to get the cmd_list_element from somewhere when you call the alias
creation function.  And it avoids an unecessary command lookup.  So it
seems better to me in every aspect.

gdb/ChangeLog:

	* command.h (add_com_alias): Accept target as
	cmd_list_element.  Update callers.

Change-Id: I24bed7da57221cc77606034de3023fedac015150
2021-05-27 14:00:07 -04:00
Marco Barisione
2f822da535 gdb: generate the prefix name for prefix commands on demand
Previously, the prefixname field of struct cmd_list_element was manually
set for prefix commands.  This seems verbose and error prone as it
required every single call to functions adding prefix commands to
specify the prefix name while the same information can be easily
generated.

Historically, this was not possible as the prefix field was null for
many commands, but this was fixed in commit
3f4d92ebdf by Philippe Waroquiers, so
we can rely on the prefix field being set when generating the prefix
name.

This commit also fixes a use after free in this scenario:
* A command gets created via Python (using the gdb.Command class).
  The prefix name member is dynamically allocated.
* An alias to the new command is created. The alias's prefixname is set
  to point to the prefixname for the original command with a direct
  assignment.
* A new command with the same name as the Python command is created.
* The object for the original Python command gets freed and its
  prefixname gets freed as well.
* The alias is updated to point to the new command, but its prefixname
  is not updated so it keeps pointing to the freed one.

gdb/ChangeLog:

	* command.h (add_prefix_cmd): Remove the prefixname argument as
	it can now be generated automatically.  Update all callers.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.c (add_prefix_cmd): Ditto.
	(add_basic_prefix_cmd): Ditto.
	(add_show_prefix_cmd): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_prefix_cmd_suppress_notification): Ditto.
	(add_abbrev_prefix_cmd): Ditto.
	* cli/cli-decode.h (struct cmd_list_element): Replace the
	prefixname member variable with a method which generates the
	prefix name at runtime.  Update all code reading the prefix
	name to use the method, and remove all code setting it.
	* python/py-cmd.c (cmdpy_destroyer): Remove code to free the
	prefixname member as it's now a method.
	(cmdpy_function): Determine if the command is a prefix by
	looking at prefixlist, not prefixname.
2021-05-12 11:19:22 +01:00
Simon Marchi
c90e7d6352 gdbsupport, gdb: give names to observers
Give a name to each observer, this will help produce more meaningful
debug message.

gdbsupport/ChangeLog:

	* observable.h (class observable) <struct observer> <observer>:
	Add name parameter.
	<name>: New field.
	<attach>: Add name parameter, update all callers.

Change-Id: Ie0cc4664925215b8d2b09e026011b7803549fba0
2021-04-24 19:26:41 -04:00
Tom de Vries
d811a7cf74 [gdb/tui] Fix len_without_escapes in tui-disasm.c
On openSUSE Tumbleweed I run into:
...
FAIL: gdb.tui/basic.exp: asm window shows main
ERROR: invalid command name "_csi_L"
...

Using a minimal example, we get:
...
$ gdb -q outputs/gdb.tui/basic/basic -ex "tui enable" -ex "layout asm"
<TUI output>
src/gdb/ui-style.c:243: internal-error: bool \
  ui_file_style::parse(const char*, size_t*): Assertion `match == 0' failed.
...

The problem is in len_without_escapes, where we detect the start of an escape
sequence, but then pass ptr to style.parse while ptr no longer points to the
escape due to the ptr++ in the while condition:
...
  while ((c = *ptr++) != '\0')
     {
      if (c == '\033')
        {
          ui_file_style style;
          size_t n_read;
          if (style.parse (ptr, &n_read))
...

Fix this by removing the ++ in the while condition, and adding ptr++ in the
loop body where appropriate.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-04-06  Tom de Vries  <tdevries@suse.de>

	PR tui/27680
	* tui/tui-disasm.c (len_without_escapes): Pass ptr pointing at escape
	to style.parse.
2021-04-06 10:40:11 +02:00
Simon Marchi
d777bf0df2 gdb: move all "current target" wrapper implementations to target.c
The following patch removes the current_top_target function, replacing
uses with `current_inferior ()->top_target ()`.  This is a problem for
uses in target.h, because they don't have access to the current_inferior
function and the inferior structure: target.h can't include inferior.h,
otherwise that would make a cyclic inclusion.

Avoid this by moving all implementations of the wrappers that call
target methods with the current target to target.c.  Many of them are
changed from a macro to a function, which is an improvement for
readability and debuggability, IMO.

target_shortname and target_longname were not function-like macros, so a
few adjustments are needed.

gdb/ChangeLog:

	* target.h (target_shortname): Change to function declaration.
	(target_longname): Likewise.
	(target_attach_no_wait): Likewise.
	(target_post_attach): Likewise.
	(target_prepare_to_store): Likewise.
	(target_supports_enable_disable_tracepoint): Likewise.
	(target_supports_string_tracing): Likewise.
	(target_supports_evaluation_of_breakpoint_conditions): Likewise.
	(target_supports_dumpcore): Likewise.
	(target_dumpcore): Likewise.
	(target_can_run_breakpoint_commands): Likewise.
	(target_files_info): Likewise.
	(target_post_startup_inferior): Likewise.
	(target_insert_fork_catchpoint): Likewise.
	(target_remove_fork_catchpoint): Likewise.
	(target_insert_vfork_catchpoint): Likewise.
	(target_remove_vfork_catchpoint): Likewise.
	(target_insert_exec_catchpoint): Likewise.
	(target_remove_exec_catchpoint): Likewise.
	(target_set_syscall_catchpoint): Likewise.
	(target_rcmd): Likewise.
	(target_can_lock_scheduler): Likewise.
	(target_can_async_p): Likewise.
	(target_is_async_p): Likewise.
	(target_execution_direction): Likewise.
	(target_extra_thread_info): Likewise.
	(target_pid_to_exec_file): Likewise.
	(target_thread_architecture): Likewise.
	(target_find_memory_regions): Likewise.
	(target_make_corefile_notes): Likewise.
	(target_get_bookmark): Likewise.
	(target_goto_bookmark): Likewise.
	(target_stopped_by_watchpoint): Likewise.
	(target_stopped_by_sw_breakpoint): Likewise.
	(target_supports_stopped_by_sw_breakpoint): Likewise.
	(target_stopped_by_hw_breakpoint): Likewise.
	(target_supports_stopped_by_hw_breakpoint): Likewise.
	(target_have_steppable_watchpoint): Likewise.
	(target_can_use_hardware_watchpoint): Likewise.
	(target_region_ok_for_hw_watchpoint): Likewise.
	(target_can_do_single_step): Likewise.
	(target_insert_watchpoint): Likewise.
	(target_remove_watchpoint): Likewise.
	(target_insert_hw_breakpoint): Likewise.
	(target_remove_hw_breakpoint): Likewise.
	(target_can_accel_watchpoint_condition): Likewise.
	(target_can_execute_reverse): Likewise.
	(target_get_ada_task_ptid): Likewise.
	(target_filesystem_is_local): Likewise.
	(target_trace_init): Likewise.
	(target_download_tracepoint): Likewise.
	(target_can_download_tracepoint): Likewise.
	(target_download_trace_state_variable): Likewise.
	(target_enable_tracepoint): Likewise.
	(target_disable_tracepoint): Likewise.
	(target_trace_start): Likewise.
	(target_trace_set_readonly_regions): Likewise.
	(target_get_trace_status): Likewise.
	(target_get_tracepoint_status): Likewise.
	(target_trace_stop): Likewise.
	(target_trace_find): Likewise.
	(target_get_trace_state_variable_value): Likewise.
	(target_save_trace_data): Likewise.
	(target_upload_tracepoints): Likewise.
	(target_upload_trace_state_variables): Likewise.
	(target_get_raw_trace_data): Likewise.
	(target_get_min_fast_tracepoint_insn_len): Likewise.
	(target_set_disconnected_tracing): Likewise.
	(target_set_circular_trace_buffer): Likewise.
	(target_set_trace_buffer_size): Likewise.
	(target_set_trace_notes): Likewise.
	(target_get_tib_address): Likewise.
	(target_set_permissions): Likewise.
	(target_static_tracepoint_marker_at): Likewise.
	(target_static_tracepoint_markers_by_strid): Likewise.
	(target_traceframe_info): Likewise.
	(target_use_agent): Likewise.
	(target_can_use_agent): Likewise.
	(target_augmented_libraries_svr4_read): Likewise.
	(target_log_command): Likewise.
	* target.c (target_shortname): New.
	(target_longname): New.
	(target_attach_no_wait): New.
	(target_post_attach): New.
	(target_prepare_to_store): New.
	(target_supports_enable_disable_tracepoint): New.
	(target_supports_string_tracing): New.
	(target_supports_evaluation_of_breakpoint_conditions): New.
	(target_supports_dumpcore): New.
	(target_dumpcore): New.
	(target_can_run_breakpoint_commands): New.
	(target_files_info): New.
	(target_post_startup_inferior): New.
	(target_insert_fork_catchpoint): New.
	(target_remove_fork_catchpoint): New.
	(target_insert_vfork_catchpoint): New.
	(target_remove_vfork_catchpoint): New.
	(target_insert_exec_catchpoint): New.
	(target_remove_exec_catchpoint): New.
	(target_set_syscall_catchpoint): New.
	(target_rcmd): New.
	(target_can_lock_scheduler): New.
	(target_can_async_p): New.
	(target_is_async_p): New.
	(target_execution_direction): New.
	(target_extra_thread_info): New.
	(target_pid_to_exec_file): New.
	(target_thread_architecture): New.
	(target_find_memory_regions): New.
	(target_make_corefile_notes): New.
	(target_get_bookmark): New.
	(target_goto_bookmark): New.
	(target_stopped_by_watchpoint): New.
	(target_stopped_by_sw_breakpoint): New.
	(target_supports_stopped_by_sw_breakpoint): New.
	(target_stopped_by_hw_breakpoint): New.
	(target_supports_stopped_by_hw_breakpoint): New.
	(target_have_steppable_watchpoint): New.
	(target_can_use_hardware_watchpoint): New.
	(target_region_ok_for_hw_watchpoint): New.
	(target_can_do_single_step): New.
	(target_insert_watchpoint): New.
	(target_remove_watchpoint): New.
	(target_insert_hw_breakpoint): New.
	(target_remove_hw_breakpoint): New.
	(target_can_accel_watchpoint_condition): New.
	(target_can_execute_reverse): New.
	(target_get_ada_task_ptid): New.
	(target_filesystem_is_local): New.
	(target_trace_init): New.
	(target_download_tracepoint): New.
	(target_can_download_tracepoint): New.
	(target_download_trace_state_variable): New.
	(target_enable_tracepoint): New.
	(target_disable_tracepoint): New.
	(target_trace_start): New.
	(target_trace_set_readonly_regions): New.
	(target_get_trace_status): New.
	(target_get_tracepoint_status): New.
	(target_trace_stop): New.
	(target_trace_find): New.
	(target_get_trace_state_variable_value): New.
	(target_save_trace_data): New.
	(target_upload_tracepoints): New.
	(target_upload_trace_state_variables): New.
	(target_get_raw_trace_data): New.
	(target_get_min_fast_tracepoint_insn_len): New.
	(target_set_disconnected_tracing): New.
	(target_set_circular_trace_buffer): New.
	(target_set_trace_buffer_size): New.
	(target_set_trace_notes): New.
	(target_get_tib_address): New.
	(target_set_permissions): New.
	(target_static_tracepoint_marker_at): New.
	(target_static_tracepoint_markers_by_strid): New.
	(target_traceframe_info): New.
	(target_use_agent): New.
	(target_can_use_agent): New.
	(target_augmented_libraries_svr4_read): New.
	(target_log_command): New.
	* bfin-tdep.c (bfin_sw_breakpoint_from_kind): Adjust.
	* infrun.c (set_schedlock_func): Adjust.
	* mi/mi-main.c (exec_reverse_continue): Adjust.
	* reverse.c (exec_reverse_once): Adjust.
	* sh-tdep.c (sh_sw_breakpoint_from_kind): Adjust.
	* tui/tui-stack.c (tui_locator_window::make_status_line): Adjust.
	* remote-sim.c (gdbsim_target::detach): Adjust.
	(gdbsim_target::files_info): Adjust.

Change-Id: I72ef56e9a25adeb0b91f1ad05e34c89f77ebeaa8
2021-03-24 18:07:30 -04:00
Andrew Burgess
29db1eb339 gdb: return true in TuiWindow.is_valid only if TUI is enabled
If the user implements a TUI window in Python, and this window
responds to GDB events and then redraws its window contents then there
is currently an edge case which can lead to problems.

The Python API documentation suggests that calling methods like erase
or write on a TUI window (from Python code) will raise an exception if
the window is not valid.

And the description for is_valid says:

  This method returns True when this window is valid. When the user
  changes the TUI layout, windows no longer visible in the new layout
  will be destroyed. At this point, the gdb.TuiWindow will no longer
  be valid, and methods (and attributes) other than is_valid will
  throw an exception.

From this I, as a user, would expect that if I did 'tui disable' to
switch back to CLI mode, then the window would no longer be valid.
However, this is not the case.

When the TUI is disabled the windows in the TUI are not deleted, they
are simply hidden.  As such, currently, the is_valid method continues
to return true.

This means that if the users Python code does something like:

  def event_handler (e):
    global tui_window_object
    if tui_window_object->is_valid ():
      tui_window_object->erase ()
      tui_window_object->write ("Hello World")
  gdb.events.stop.connect (event_handler)

Then when a stop event arrives GDB will try to draw the TUI window,
even when the TUI is disabled.

This exposes two bugs.  First, is_valid should be returning false in
this case, second, if the user forgot to add the is_valid call, then I
believe the erase and write calls should be throwing an
exception (when the TUI is disabled).

The solution to both of these issues is I think bound together, as it
depends on having a working 'is_valid' check.

There's a rogue assert added into tui-layout.c as part of this
commit.  While working on this commit I managed to break GDB such that
TUI_CMD_WIN was nullptr, this was causing GDB to abort.  I'm leaving
the assert in as it might help people catch issues in the future.

This patch is inspired by the work done here:

  https://sourceware.org/pipermail/gdb-patches/2020-December/174338.html

gdb/ChangeLog:

	* python/py-tui.c (gdbpy_tui_window) <is_valid>: New member
	function.
	(REQUIRE_WINDOW): Call is_valid member function.
	(REQUIRE_WINDOW_FOR_SETTER): New define.
	(gdbpy_tui_is_valid): Call is_valid member function.
	(gdbpy_tui_set_title): Call REQUIRE_WINDOW_FOR_SETTER instead.
	* tui/tui-data.h (struct tui_win_info) <is_visible>: Check
	tui_active too.
	* tui/tui-layout.c (tui_apply_current_layout): Add an assert.
	* tui/tui.c (tui_enable): Move setting of tui_active earlier in
	the function.

gdb/doc/ChangeLog:

	* python.texinfo (TUI Windows In Python): Extend description of
	TuiWindow.is_valid.

gdb/testsuite/ChangeLog:

	* gdb.python/tui-window-disabled.c: New file.
	* gdb.python/tui-window-disabled.exp: New file.
	* gdb.python/tui-window-disabled.py: New file.
2021-02-08 11:56:16 +00:00
Andrew Burgess
1cf2399651 gdb/tui: don't add windows to global list from tui_layout🪟:apply
This commit was inspired by this mailing list patch:

  https://sourceware.org/pipermail/gdb-patches/2021-January/174713.html

Currently, calling tui_layout_window::apply will add the window from
the layout object to the global tui_windows list.

Unfortunately, when the user runs the 'winheight' command, this calls
tui_adjust_window_height, which calls the tui_layout_base::adjust_size
function, which can then call tui_layout_base::apply.  The consequence
of this is that when the user does 'winheight' duplicate copies of a
window can be added to the global tui_windows list.

The original patch fixed this by changing the apply function to only
update the global list some of the time.

This patch takes a different approach.  The apply function no longer
updates the global tui_windows list.  Instead a new virtual function
is added to tui_layout_base which is used to gather all the currently
applied windows into a vector.  Finally tui_apply_current_layout is
updated to make use of this new function to update the tui_windows
list.

The benefits I see in this approach are, (a) the apply function now no
longer touches global state, this solves the immediate problem,
and (b) now that tui_windows is updated directly in the function
tui_apply_current_layout, we can drop the saved_tui_windows global.

gdb/ChangeLog:

	* tui-layout.c (saved_tui_windows): Delete.
	(tui_apply_current_layout): Don't make use of saved_tui_windows,
	call new get_windows member function instead.
	(tui_get_window_by_name): Check in tui_windows.
	(tui_layout_window::apply): Don't add to tui_windows.
	* tui-layout.h (tui_layout_base::get_windows): New member function.
	(tui_layout_window::get_windows): Likewise.
	(tui_layout_split::get_windows): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.tui/winheight.exp: Add more tests.
2021-02-08 11:18:33 +00:00
Andrew Burgess
a53a265752 gdb/tui: restore delete of window objects
In commit:

  commit f237f998d1
  Date:   Mon Jan 25 18:43:19 2021 +0000

      gdb/tui: remove special handling of locator/status window

I accidentally remove a call to delete the tui window objects.  Now
every time GDB changes tui layout it is leaking windows.

gdb/ChangeLog:

	* tui/tui-layout.c (tui_apply_current_layout): Restore the delete
	of the window objects.
2021-02-08 11:11:24 +00:00
Andrew Burgess
cd074e0415 gdb/tui: fix issue with handling the return character
My initial goal was to fix our gdb/testsuite/lib/tuiterm.exp such that
it would correctly support (some limited) scrolling of the command
window.

What I observe is that when sending commands to the tui command window
in a test script with:

  Term::command "p 1"

The command window would be left looking like this:

  (gdb)
  (gdb) p 1$1 = 1
  (gdb)

When I would have expected it to look like this:

  (gdb) p 1
  $1 = 1
  (gdb)

Obviously a bug in our tuiterm.exp library, right???

Wrong!

Turns out there's a bug in GDB.

If in GDB I enable the tui and then type (slowly) the 'p 1\r' (the \r
is pressing the return key at the end of the string), then you do
indeed get the "expected" terminal output.

However, if instead I copy the 'p 1\r' string and paste it into the
tui in one go then I now see the same corrupted output as we do when
using tuiterm.exp.

It turns out the problem is that GDB fails when handling lots of input
arriving quickly with a \r (or \n) on the end.

The reason for this bug is as follows:

When the tui is active the terminal is in no-echo mode, so characters
sent to the terminal are not echoed out again.  This means that when
the user types \r, this is not echoed to the terminal.

The characters read in are passed to readline and \r indicates that
the command line is complete and ready to be processed.  However, the
\r is not included in readlines command buffer, and is NOT printed by
readline when is displays its buffer to the screen.

So, in GDB we have to manually spot the \r when it is read in and
update the display.  Printing a newline character to the output and
moving the cursor to the next line.  This is done in tui_getc_1.

Now readline tries to reduce the number of write calls.  So if we very
quickly (as in paste in one go) the text 'p 1' to readline (this time
with no \r on the end), then readline will fetch the fist character
and add it to its internal buffer.  But before printing the character
out readline checks to see if there's more input incoming.  As we
pasted multiple characters, then yes, readline sees the ' ' and adds
this to its buffer, and finally the '1', this too is added to the
buffer.

Now if at this point we take a break, readline sees there is no more
input available, and so prints its buffer out.

Now when we press \r the code in tui_getc_1 kicks in, adds a \n to the
output and moves the cursor to the next line.

But, if instead we paste 'p 1\r' in one go then readline adds 'p 1' to
its buffer as before, but now it sees that there is still more input
available.  Now it fetches the '\r', but this triggers the newline
behaviour, we print '\n' and move to the next line - however readline
has not printed its buffer yet!

So finally we end up on the next line.  There's no more input
available so readline prints its buffer, then GDB gets passed the
buffer, handles it, and prints the result.

The solution I think is to put of our special newline insertion code
until we know that readline has finished printing its buffer.  Handily
we know when this is - the next thing readline does is pass us the
command line buffer for processing.  So all we need to do is hook in
to the command line processing, and before we pass the command line to
GDB's internals we do all of the magic print a newline and move the
cursor to the next line stuff.

Luckily, GDB's interpreter mechanism already provides the hooks we
need to do this.  So all I do here is move the newline printing code
from tui_getc_1 into a new function, setup a new input_handler hook
for the tui, and call my new newline printing function.

After this I can enable the tui and paste in 'p 1\r' and see the
correct output.

Also the tuiterm.exp library will now see non-corrupted output.

gdb/ChangeLog:

	* tui/tui-interp.c (tui_command_line_handler): New function.
	(tui_interp::resume): Register tui_command_line_handler as the
	input_handler.
	* tui/tui-io.c (tui_inject_newline_into_command_window): New
	function.
	(tui_getc_1): Delete handling of '\n' and '\r'.
	* tui-io.h (tui_inject_newline_into_command_window): Declare.

gdb/testsuite/ChangeLog:

	* gdb.tui/scroll.exp: Tighten expected results.  Remove comment
	about bug in GDB, update expected results, and add more tests.
2021-02-08 09:51:46 +00:00
Hannes Domani
4cf28e918a Don't draw register sub windows outside the visible area
If the regs window is not big enough to show all registers, the
registers whose values changed are always drawn, even if they are not
in the currently visible area.

So this marks the invisible register sub windows with y=0, and skips
their rerender call in check_register_values.

gdb/ChangeLog:

2021-02-07  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-regs.c (tui_data_window::display_registers_from):
	Mark invisible register sub windows.
	(tui_data_window::check_register_values): Ignore invisible
	register sub windows.
2021-02-07 19:13:45 +01:00
Hannes Domani
3537bc23d9 Don't fill regs window with a negative number of spaces
Function n_spaces can't handle negative values, and returns an invalid
pointer in this case.

gdb/ChangeLog:

2021-02-07  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-regs.c (tui_data_item_window::rerender): Don't call
	n_spaces with a negative value.
2021-02-07 19:11:53 +01:00
Hannes Domani
5fc2d6aa06 Refresh regs window in display_registers_from
Otherwise the register window is redrawn empty when scrolling or
changing its size with winheight.

gdb/ChangeLog:

2021-02-07  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-regs.c (tui_data_window::display_registers_from):
	Add refresh_window call.
2021-02-07 19:10:17 +01:00
Andrew Burgess
f237f998d1 gdb/tui: remove special handling of locator/status window
The locator window, or status window as it is sometimes called is
handled differently to all the other windows.

The reason for this is that the class representing this
window (tui_locator_window) does two jobs, first this class represents
a window just like any other that has space on the screen and fills
the space with content.  The second job is that this class serves as a
storage area to hold information about the current location that the
TUI windows represent, so the class has members like 'addr' and
'line_no', for example which are used within this class, and others
when they want to know which line/address the TUI windows should be
showing to the user.

Because of this dual purpose we must always have an instance of the
tui_locator_window so that there is somewhere to store this location
information.

The result of this is that the locator window must never be deleted
like other windows, which results in some special case code.

In this patch I propose splitting the two roles of the
tui_locator_window class.  The tui_locator_window class will retain
just its window drawing parts, and will be treated just like any other
window.  This should allow all special case code for this window to be
deleted.

The other role, that of tracking the current tui location will be
moved into a new class (tui_location_tracker), of which there will be
a single global instance.  All of the places where we previously use
the locator window to get location information will now be updated to
get this from the tui_location_tracker.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* Makefile.in (SUBDIR_TUI_SRCS): Add tui/tui-location.c.
	(HFILES_NO_SRCDIR): Add tui/tui-location.h.
	* tui/tui-data.h (TUI_STATUS_WIN): Define.
	(tui_locator_win_info_ptr): Delete declaration.
	* tui/tui-disasm.c: Add 'tui/tui-location.h' include.
	(tui_disasm_window::set_contents): Fetch state from tui_location
	global.
	(tui_get_begin_asm_address): Likewise.
	* tui/tui-layout.c (tui_apply_current_layout): Remove special case
	for locator window.
	(get_locator_window): Delete.
	(initialize_known_windows): Treat locator window just like all the
	rest.
	* tui/tui-source.c: Add 'tui/tui-location.h' include.
	(tui_source_window::set_contents): Fetch state from tui_location
	global.
	(tui_source_window::showing_source_p): Likewise.
	* tui/tui-stack.c: Add 'tui/tui-location.h' include.
	(_locator): Delete.
	(tui_locator_win_info_ptr): Delete.
	(tui_locator_window::make_status_line): Fetch state from
	tui_location global.
	(tui_locator_window::rerender): Remove check of 'handle',
	reindent function body.
	(tui_locator_window::set_locator_fullname): Delete.
	(tui_locator_window::set_locator_info): Delete.
	(tui_update_locator_fullname): Delete.
	(tui_show_frame_info): Likewise.
	(tui_show_locator_content): Access window through TUI_STATUS_WIN.
	* tui/tui-stack.h (tui_locator_window::set_locator_info): Moved to
	tui/tui-location.h and renamed to
	tui_location_tracker::set_location.
	(tui_locator_window::set_locator_fullname): Moved to
	tui/tui-location.h and renamed to
	tui_location_tracker::set_fullname.
	(tui_locator_window::full_name): Delete.
	(tui_locator_window::proc_name): Delete.
	(tui_locator_window::line_no): Delete.
	(tui_locator_window::addr): Delete.
	(tui_locator_window::gdbarch): Delete.
	(tui_update_locator_fullname): Delete declaration.
	* tui/tui-wingeneral.c (tui_refresh_all): Removed special handling
	for locator window.
	* tui/tui-winsource.c: Add 'tui/tui-location.h' include.
	(tui_display_main): Call function on tui_location directly.
	* tui/tui.h (enum tui_win_type): Add STATUS_WIN.
	* tui/tui-location.c: New file.
	* tui/tui-location.h: New file.
2021-01-28 17:00:30 +00:00
Andrew Burgess
5a11fff005 gdb/tui: compare pointer to nullptr, not 0
Compare pointers to nullptr, not 0.  I also fixed a trailing
whitespace in the same function.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* tui/tui.c (tui_is_window_visible): Compare to nullptr, not 0.
2021-01-15 20:23:12 +00:00
Hannes Domani
5519536196 Prevent flickering when redrawing the TUI source window
tui_win_info::refresh_window simply calls wrefresh, which internally
does a doupdate.
This redraws the source background window without the source pad.
Then prefresh of the source pad draws the actual source code on top,
which flickers.

By changing this to wnoutrefresh, the actual drawing on the screen is
only done once in the following prefresh, without flickering.

gdb/ChangeLog:

2021-01-05  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-winsource.c (tui_source_window_base::refresh_window):
	Call wnoutrefresh instead of tui_win_info::refresh_window.
2021-01-05 14:08:26 +01:00
Hannes Domani
1b6d4bb223 Redraw both spaces between line numbers and source code
There a 2 spaces between the numbers and source code, but only one of
them was redrawn.
So if you increase the source window height, the second space keeps the
character of the border rectangle.

With this both spaces are redrawn, so the border rectangle character is
overwritten.

gdb/ChangeLog:

2021-01-05  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-source.c (tui_source_window::show_line_number):
	Redraw second space after line number.
2021-01-05 14:08:26 +01:00
Hannes Domani
b5ff370e96 Fix TUI source window drawing
The smaxrow and smaxcol parameters of prefresh are the bottom right corner
of the text area inclusive, not exclusive.

And if the source window grows bigger in height, the pad has to grow as
well.

gdb/ChangeLog:

2021-01-05  Hannes Domani  <ssbssa@yahoo.de>

	PR tui/26927
	* tui/tui-winsource.c (tui_source_window_base::refresh_window):
	Fix source pad size in prefresh.
	(tui_source_window_base::show_source_content): Grow source pad
	if necessary.
2021-01-05 14:08:26 +01:00
Joel Brobecker
3666a04883 Update copyright year range in all GDB files
This commits the result of running gdb/copyright.py as per our Start
of New Year procedure...

gdb/ChangeLog

        Update copyright year range in copyright header of all GDB files.
2021-01-01 12:12:21 +04:00
Hannes Domani
96fb90861a Don't delete the locator win info
The locator win info is special because it is static, all the others are
created dynamically.

gdb/ChangeLog:

2020-11-29  Hannes Domani  <ssbssa@yahoo.de>

	PR tui/26973
	* tui/tui-layout.c (tui_apply_current_layout): Don't delete the
	static locator win info.
2020-11-29 18:47:38 +01:00
Simon Marchi
dda83cd783 gdb, gdbserver, gdbsupport: fix leading space vs tabs issues
Many spots incorrectly use only spaces for indentation (for example,
there are a lot of spots in ada-lang.c).  I've always found it awkward
when I needed to edit one of these spots: do I keep the original wrong
indentation, or do I fix it?  What if the lines around it are also
wrong, do I fix them too?  I probably don't want to fix them in the same
patch, to avoid adding noise to my patch.

So I propose to fix as much as possible once and for all (hopefully).

One typical counter argument for this is that it makes code archeology
more difficult, because git-blame will show this commit as the last
change for these lines.  My counter counter argument is: when
git-blaming, you often need to do "blame the file at the parent commit"
anyway, to go past some other refactor that touched the line you are
interested in, but is not the change you are looking for.  So you
already need a somewhat efficient way to do this.

Using some interactive tool, rather than plain git-blame, makes this
trivial.  For example, I use "tig blame <file>", where going back past
the commit that changed the currently selected line is one keystroke.
It looks like Magit in Emacs does it too (though I've never used it).
Web viewers of Github and Gitlab do it too.  My point is that it won't
really make archeology more difficult.

The other typical counter argument is that it will cause conflicts with
existing patches.  That's true... but it's a one time cost, and those
are not conflicts that are difficult to resolve.  I have also tried "git
rebase --ignore-whitespace", it seems to work well.  Although that will
re-introduce the faulty indentation, so one needs to take care of fixing
the indentation in the patch after that (which is easy).

gdb/ChangeLog:

	* aarch64-linux-tdep.c: Fix indentation.
	* aarch64-ravenscar-thread.c: Fix indentation.
	* aarch64-tdep.c: Fix indentation.
	* aarch64-tdep.h: Fix indentation.
	* ada-lang.c: Fix indentation.
	* ada-lang.h: Fix indentation.
	* ada-tasks.c: Fix indentation.
	* ada-typeprint.c: Fix indentation.
	* ada-valprint.c: Fix indentation.
	* ada-varobj.c: Fix indentation.
	* addrmap.c: Fix indentation.
	* addrmap.h: Fix indentation.
	* agent.c: Fix indentation.
	* aix-thread.c: Fix indentation.
	* alpha-bsd-nat.c: Fix indentation.
	* alpha-linux-tdep.c: Fix indentation.
	* alpha-mdebug-tdep.c: Fix indentation.
	* alpha-nbsd-tdep.c: Fix indentation.
	* alpha-obsd-tdep.c: Fix indentation.
	* alpha-tdep.c: Fix indentation.
	* amd64-bsd-nat.c: Fix indentation.
	* amd64-darwin-tdep.c: Fix indentation.
	* amd64-linux-nat.c: Fix indentation.
	* amd64-linux-tdep.c: Fix indentation.
	* amd64-nat.c: Fix indentation.
	* amd64-obsd-tdep.c: Fix indentation.
	* amd64-tdep.c: Fix indentation.
	* amd64-windows-tdep.c: Fix indentation.
	* annotate.c: Fix indentation.
	* arc-tdep.c: Fix indentation.
	* arch-utils.c: Fix indentation.
	* arch/arm-get-next-pcs.c: Fix indentation.
	* arch/arm.c: Fix indentation.
	* arm-linux-nat.c: Fix indentation.
	* arm-linux-tdep.c: Fix indentation.
	* arm-nbsd-tdep.c: Fix indentation.
	* arm-pikeos-tdep.c: Fix indentation.
	* arm-tdep.c: Fix indentation.
	* arm-tdep.h: Fix indentation.
	* arm-wince-tdep.c: Fix indentation.
	* auto-load.c: Fix indentation.
	* auxv.c: Fix indentation.
	* avr-tdep.c: Fix indentation.
	* ax-gdb.c: Fix indentation.
	* ax-general.c: Fix indentation.
	* bfin-linux-tdep.c: Fix indentation.
	* block.c: Fix indentation.
	* block.h: Fix indentation.
	* blockframe.c: Fix indentation.
	* bpf-tdep.c: Fix indentation.
	* break-catch-sig.c: Fix indentation.
	* break-catch-syscall.c: Fix indentation.
	* break-catch-throw.c: Fix indentation.
	* breakpoint.c: Fix indentation.
	* breakpoint.h: Fix indentation.
	* bsd-uthread.c: Fix indentation.
	* btrace.c: Fix indentation.
	* build-id.c: Fix indentation.
	* buildsym-legacy.h: Fix indentation.
	* buildsym.c: Fix indentation.
	* c-typeprint.c: Fix indentation.
	* c-valprint.c: Fix indentation.
	* c-varobj.c: Fix indentation.
	* charset.c: Fix indentation.
	* cli/cli-cmds.c: Fix indentation.
	* cli/cli-decode.c: Fix indentation.
	* cli/cli-decode.h: Fix indentation.
	* cli/cli-script.c: Fix indentation.
	* cli/cli-setshow.c: Fix indentation.
	* coff-pe-read.c: Fix indentation.
	* coffread.c: Fix indentation.
	* compile/compile-cplus-types.c: Fix indentation.
	* compile/compile-object-load.c: Fix indentation.
	* compile/compile-object-run.c: Fix indentation.
	* completer.c: Fix indentation.
	* corefile.c: Fix indentation.
	* corelow.c: Fix indentation.
	* cp-abi.h: Fix indentation.
	* cp-namespace.c: Fix indentation.
	* cp-support.c: Fix indentation.
	* cp-valprint.c: Fix indentation.
	* cris-linux-tdep.c: Fix indentation.
	* cris-tdep.c: Fix indentation.
	* darwin-nat-info.c: Fix indentation.
	* darwin-nat.c: Fix indentation.
	* darwin-nat.h: Fix indentation.
	* dbxread.c: Fix indentation.
	* dcache.c: Fix indentation.
	* disasm.c: Fix indentation.
	* dtrace-probe.c: Fix indentation.
	* dwarf2/abbrev.c: Fix indentation.
	* dwarf2/attribute.c: Fix indentation.
	* dwarf2/expr.c: Fix indentation.
	* dwarf2/frame.c: Fix indentation.
	* dwarf2/index-cache.c: Fix indentation.
	* dwarf2/index-write.c: Fix indentation.
	* dwarf2/line-header.c: Fix indentation.
	* dwarf2/loc.c: Fix indentation.
	* dwarf2/macro.c: Fix indentation.
	* dwarf2/read.c: Fix indentation.
	* dwarf2/read.h: Fix indentation.
	* elfread.c: Fix indentation.
	* eval.c: Fix indentation.
	* event-top.c: Fix indentation.
	* exec.c: Fix indentation.
	* exec.h: Fix indentation.
	* expprint.c: Fix indentation.
	* f-lang.c: Fix indentation.
	* f-typeprint.c: Fix indentation.
	* f-valprint.c: Fix indentation.
	* fbsd-nat.c: Fix indentation.
	* fbsd-tdep.c: Fix indentation.
	* findvar.c: Fix indentation.
	* fork-child.c: Fix indentation.
	* frame-unwind.c: Fix indentation.
	* frame-unwind.h: Fix indentation.
	* frame.c: Fix indentation.
	* frv-linux-tdep.c: Fix indentation.
	* frv-tdep.c: Fix indentation.
	* frv-tdep.h: Fix indentation.
	* ft32-tdep.c: Fix indentation.
	* gcore.c: Fix indentation.
	* gdb_bfd.c: Fix indentation.
	* gdbarch.sh: Fix indentation.
	* gdbarch.c: Re-generate
	* gdbarch.h: Re-generate.
	* gdbcore.h: Fix indentation.
	* gdbthread.h: Fix indentation.
	* gdbtypes.c: Fix indentation.
	* gdbtypes.h: Fix indentation.
	* glibc-tdep.c: Fix indentation.
	* gnu-nat.c: Fix indentation.
	* gnu-nat.h: Fix indentation.
	* gnu-v2-abi.c: Fix indentation.
	* gnu-v3-abi.c: Fix indentation.
	* go32-nat.c: Fix indentation.
	* guile/guile-internal.h: Fix indentation.
	* guile/scm-cmd.c: Fix indentation.
	* guile/scm-frame.c: Fix indentation.
	* guile/scm-iterator.c: Fix indentation.
	* guile/scm-math.c: Fix indentation.
	* guile/scm-ports.c: Fix indentation.
	* guile/scm-pretty-print.c: Fix indentation.
	* guile/scm-value.c: Fix indentation.
	* h8300-tdep.c: Fix indentation.
	* hppa-linux-nat.c: Fix indentation.
	* hppa-linux-tdep.c: Fix indentation.
	* hppa-nbsd-nat.c: Fix indentation.
	* hppa-nbsd-tdep.c: Fix indentation.
	* hppa-obsd-nat.c: Fix indentation.
	* hppa-tdep.c: Fix indentation.
	* hppa-tdep.h: Fix indentation.
	* i386-bsd-nat.c: Fix indentation.
	* i386-darwin-nat.c: Fix indentation.
	* i386-darwin-tdep.c: Fix indentation.
	* i386-dicos-tdep.c: Fix indentation.
	* i386-gnu-nat.c: Fix indentation.
	* i386-linux-nat.c: Fix indentation.
	* i386-linux-tdep.c: Fix indentation.
	* i386-nto-tdep.c: Fix indentation.
	* i386-obsd-tdep.c: Fix indentation.
	* i386-sol2-nat.c: Fix indentation.
	* i386-tdep.c: Fix indentation.
	* i386-tdep.h: Fix indentation.
	* i386-windows-tdep.c: Fix indentation.
	* i387-tdep.c: Fix indentation.
	* i387-tdep.h: Fix indentation.
	* ia64-libunwind-tdep.c: Fix indentation.
	* ia64-libunwind-tdep.h: Fix indentation.
	* ia64-linux-nat.c: Fix indentation.
	* ia64-linux-tdep.c: Fix indentation.
	* ia64-tdep.c: Fix indentation.
	* ia64-tdep.h: Fix indentation.
	* ia64-vms-tdep.c: Fix indentation.
	* infcall.c: Fix indentation.
	* infcmd.c: Fix indentation.
	* inferior.c: Fix indentation.
	* infrun.c: Fix indentation.
	* iq2000-tdep.c: Fix indentation.
	* language.c: Fix indentation.
	* linespec.c: Fix indentation.
	* linux-fork.c: Fix indentation.
	* linux-nat.c: Fix indentation.
	* linux-tdep.c: Fix indentation.
	* linux-thread-db.c: Fix indentation.
	* lm32-tdep.c: Fix indentation.
	* m2-lang.c: Fix indentation.
	* m2-typeprint.c: Fix indentation.
	* m2-valprint.c: Fix indentation.
	* m32c-tdep.c: Fix indentation.
	* m32r-linux-tdep.c: Fix indentation.
	* m32r-tdep.c: Fix indentation.
	* m68hc11-tdep.c: Fix indentation.
	* m68k-bsd-nat.c: Fix indentation.
	* m68k-linux-nat.c: Fix indentation.
	* m68k-linux-tdep.c: Fix indentation.
	* m68k-tdep.c: Fix indentation.
	* machoread.c: Fix indentation.
	* macrocmd.c: Fix indentation.
	* macroexp.c: Fix indentation.
	* macroscope.c: Fix indentation.
	* macrotab.c: Fix indentation.
	* macrotab.h: Fix indentation.
	* main.c: Fix indentation.
	* mdebugread.c: Fix indentation.
	* mep-tdep.c: Fix indentation.
	* mi/mi-cmd-catch.c: Fix indentation.
	* mi/mi-cmd-disas.c: Fix indentation.
	* mi/mi-cmd-env.c: Fix indentation.
	* mi/mi-cmd-stack.c: Fix indentation.
	* mi/mi-cmd-var.c: Fix indentation.
	* mi/mi-cmds.c: Fix indentation.
	* mi/mi-main.c: Fix indentation.
	* mi/mi-parse.c: Fix indentation.
	* microblaze-tdep.c: Fix indentation.
	* minidebug.c: Fix indentation.
	* minsyms.c: Fix indentation.
	* mips-linux-nat.c: Fix indentation.
	* mips-linux-tdep.c: Fix indentation.
	* mips-nbsd-tdep.c: Fix indentation.
	* mips-tdep.c: Fix indentation.
	* mn10300-linux-tdep.c: Fix indentation.
	* mn10300-tdep.c: Fix indentation.
	* moxie-tdep.c: Fix indentation.
	* msp430-tdep.c: Fix indentation.
	* namespace.h: Fix indentation.
	* nat/fork-inferior.c: Fix indentation.
	* nat/gdb_ptrace.h: Fix indentation.
	* nat/linux-namespaces.c: Fix indentation.
	* nat/linux-osdata.c: Fix indentation.
	* nat/netbsd-nat.c: Fix indentation.
	* nat/x86-dregs.c: Fix indentation.
	* nbsd-nat.c: Fix indentation.
	* nbsd-tdep.c: Fix indentation.
	* nios2-linux-tdep.c: Fix indentation.
	* nios2-tdep.c: Fix indentation.
	* nto-procfs.c: Fix indentation.
	* nto-tdep.c: Fix indentation.
	* objfiles.c: Fix indentation.
	* objfiles.h: Fix indentation.
	* opencl-lang.c: Fix indentation.
	* or1k-tdep.c: Fix indentation.
	* osabi.c: Fix indentation.
	* osabi.h: Fix indentation.
	* osdata.c: Fix indentation.
	* p-lang.c: Fix indentation.
	* p-typeprint.c: Fix indentation.
	* p-valprint.c: Fix indentation.
	* parse.c: Fix indentation.
	* ppc-linux-nat.c: Fix indentation.
	* ppc-linux-tdep.c: Fix indentation.
	* ppc-nbsd-nat.c: Fix indentation.
	* ppc-nbsd-tdep.c: Fix indentation.
	* ppc-obsd-nat.c: Fix indentation.
	* ppc-ravenscar-thread.c: Fix indentation.
	* ppc-sysv-tdep.c: Fix indentation.
	* ppc64-tdep.c: Fix indentation.
	* printcmd.c: Fix indentation.
	* proc-api.c: Fix indentation.
	* producer.c: Fix indentation.
	* producer.h: Fix indentation.
	* prologue-value.c: Fix indentation.
	* prologue-value.h: Fix indentation.
	* psymtab.c: Fix indentation.
	* python/py-arch.c: Fix indentation.
	* python/py-bpevent.c: Fix indentation.
	* python/py-event.c: Fix indentation.
	* python/py-event.h: Fix indentation.
	* python/py-finishbreakpoint.c: Fix indentation.
	* python/py-frame.c: Fix indentation.
	* python/py-framefilter.c: Fix indentation.
	* python/py-inferior.c: Fix indentation.
	* python/py-infthread.c: Fix indentation.
	* python/py-objfile.c: Fix indentation.
	* python/py-prettyprint.c: Fix indentation.
	* python/py-registers.c: Fix indentation.
	* python/py-signalevent.c: Fix indentation.
	* python/py-stopevent.c: Fix indentation.
	* python/py-stopevent.h: Fix indentation.
	* python/py-threadevent.c: Fix indentation.
	* python/py-tui.c: Fix indentation.
	* python/py-unwind.c: Fix indentation.
	* python/py-value.c: Fix indentation.
	* python/py-xmethods.c: Fix indentation.
	* python/python-internal.h: Fix indentation.
	* python/python.c: Fix indentation.
	* ravenscar-thread.c: Fix indentation.
	* record-btrace.c: Fix indentation.
	* record-full.c: Fix indentation.
	* record.c: Fix indentation.
	* reggroups.c: Fix indentation.
	* regset.h: Fix indentation.
	* remote-fileio.c: Fix indentation.
	* remote.c: Fix indentation.
	* reverse.c: Fix indentation.
	* riscv-linux-tdep.c: Fix indentation.
	* riscv-ravenscar-thread.c: Fix indentation.
	* riscv-tdep.c: Fix indentation.
	* rl78-tdep.c: Fix indentation.
	* rs6000-aix-tdep.c: Fix indentation.
	* rs6000-lynx178-tdep.c: Fix indentation.
	* rs6000-nat.c: Fix indentation.
	* rs6000-tdep.c: Fix indentation.
	* rust-lang.c: Fix indentation.
	* rx-tdep.c: Fix indentation.
	* s12z-tdep.c: Fix indentation.
	* s390-linux-tdep.c: Fix indentation.
	* score-tdep.c: Fix indentation.
	* ser-base.c: Fix indentation.
	* ser-mingw.c: Fix indentation.
	* ser-uds.c: Fix indentation.
	* ser-unix.c: Fix indentation.
	* serial.c: Fix indentation.
	* sh-linux-tdep.c: Fix indentation.
	* sh-nbsd-tdep.c: Fix indentation.
	* sh-tdep.c: Fix indentation.
	* skip.c: Fix indentation.
	* sol-thread.c: Fix indentation.
	* solib-aix.c: Fix indentation.
	* solib-darwin.c: Fix indentation.
	* solib-frv.c: Fix indentation.
	* solib-svr4.c: Fix indentation.
	* solib.c: Fix indentation.
	* source.c: Fix indentation.
	* sparc-linux-tdep.c: Fix indentation.
	* sparc-nbsd-tdep.c: Fix indentation.
	* sparc-obsd-tdep.c: Fix indentation.
	* sparc-ravenscar-thread.c: Fix indentation.
	* sparc-tdep.c: Fix indentation.
	* sparc64-linux-tdep.c: Fix indentation.
	* sparc64-nbsd-tdep.c: Fix indentation.
	* sparc64-obsd-tdep.c: Fix indentation.
	* sparc64-tdep.c: Fix indentation.
	* stabsread.c: Fix indentation.
	* stack.c: Fix indentation.
	* stap-probe.c: Fix indentation.
	* stubs/ia64vms-stub.c: Fix indentation.
	* stubs/m32r-stub.c: Fix indentation.
	* stubs/m68k-stub.c: Fix indentation.
	* stubs/sh-stub.c: Fix indentation.
	* stubs/sparc-stub.c: Fix indentation.
	* symfile-mem.c: Fix indentation.
	* symfile.c: Fix indentation.
	* symfile.h: Fix indentation.
	* symmisc.c: Fix indentation.
	* symtab.c: Fix indentation.
	* symtab.h: Fix indentation.
	* target-float.c: Fix indentation.
	* target.c: Fix indentation.
	* target.h: Fix indentation.
	* tic6x-tdep.c: Fix indentation.
	* tilegx-linux-tdep.c: Fix indentation.
	* tilegx-tdep.c: Fix indentation.
	* top.c: Fix indentation.
	* tracefile-tfile.c: Fix indentation.
	* tracepoint.c: Fix indentation.
	* tui/tui-disasm.c: Fix indentation.
	* tui/tui-io.c: Fix indentation.
	* tui/tui-regs.c: Fix indentation.
	* tui/tui-stack.c: Fix indentation.
	* tui/tui-win.c: Fix indentation.
	* tui/tui-winsource.c: Fix indentation.
	* tui/tui.c: Fix indentation.
	* typeprint.c: Fix indentation.
	* ui-out.h: Fix indentation.
	* unittests/copy_bitwise-selftests.c: Fix indentation.
	* unittests/memory-map-selftests.c: Fix indentation.
	* utils.c: Fix indentation.
	* v850-tdep.c: Fix indentation.
	* valarith.c: Fix indentation.
	* valops.c: Fix indentation.
	* valprint.c: Fix indentation.
	* valprint.h: Fix indentation.
	* value.c: Fix indentation.
	* value.h: Fix indentation.
	* varobj.c: Fix indentation.
	* vax-tdep.c: Fix indentation.
	* windows-nat.c: Fix indentation.
	* windows-tdep.c: Fix indentation.
	* xcoffread.c: Fix indentation.
	* xml-syscall.c: Fix indentation.
	* xml-tdesc.c: Fix indentation.
	* xstormy16-tdep.c: Fix indentation.
	* xtensa-config.c: Fix indentation.
	* xtensa-linux-nat.c: Fix indentation.
	* xtensa-linux-tdep.c: Fix indentation.
	* xtensa-tdep.c: Fix indentation.

gdbserver/ChangeLog:

	* ax.cc: Fix indentation.
	* dll.cc: Fix indentation.
	* inferiors.h: Fix indentation.
	* linux-low.cc: Fix indentation.
	* linux-nios2-low.cc: Fix indentation.
	* linux-ppc-ipa.cc: Fix indentation.
	* linux-ppc-low.cc: Fix indentation.
	* linux-x86-low.cc: Fix indentation.
	* linux-xtensa-low.cc: Fix indentation.
	* regcache.cc: Fix indentation.
	* server.cc: Fix indentation.
	* tracepoint.cc: Fix indentation.

gdbsupport/ChangeLog:

	* common-exceptions.h: Fix indentation.
	* event-loop.cc: Fix indentation.
	* fileio.cc: Fix indentation.
	* filestuff.cc: Fix indentation.
	* gdb-dlfcn.cc: Fix indentation.
	* gdb_string_view.h: Fix indentation.
	* job-control.cc: Fix indentation.
	* signals.cc: Fix indentation.

Change-Id: I4bad7ae6be0fbe14168b8ebafb98ffe14964a695
2020-11-02 10:28:45 -05:00
Tom Tromey
22cc388e2b Don't erase TUI source window when switching focus
PR tui/26719 points out that switching the focus can erase the TUI
source window.  This is a regression introduced by the patch to switch
the source window to using a pad.

This patch fixes the bug by arranging to call prefresh whenever the
window is refreshed.

2020-10-19  Tom Tromey  <tromey@adacore.com>

	PR tui/26719
	* tui/tui-winsource.h (struct tui_source_window_base)
	<refresh_window>: Rename from refresh_pad.
	* tui/tui-winsource.c (tui_source_window_base::refresh_window):
	Rename from refresh_pad.
	(tui_source_window_base::show_source_content)
	(tui_source_window_base::do_scroll_horizontal): Update.

gdb/testsuite/ChangeLog
2020-10-19  Tom Tromey  <tromey@adacore.com>

	PR tui/26719
	* gdb.tui/list.exp: Check source window contents after focus
	change.
2020-10-19 13:45:24 -06:00
Simon Marchi
db20ebdfae gdb: give names to async event/signal handlers
Assign names to async event/signal handlers.  They will be used in debug
messages when file handlers are invoked.

Unlike in the previous patch, the names are not copied in the structure,
since we don't need to (all names are string literals for the moment).

gdb/ChangeLog:

	* async-event.h (create_async_signal_handler): Add name
	parameter.
	(create_async_event_handler): Likewise.
	* async-event.c (struct async_signal_handler) <name>: New field.
	(struct async_event_handler) <name>: New field.
	(create_async_signal_handler): Assign name.
	(create_async_event_handler): Assign name.
	* event-top.c (async_init_signals): Pass name when creating
	handler.
	* infrun.c (_initialize_infrun): Likewise.
	* record-btrace.c (record_btrace_push_target): Likewise.
	* record-full.c (record_full_open): Likewise.
	* remote-notif.c (remote_notif_state_allocate): Likewise.
	* remote.c (remote_target::open_1): Likewise.
	* tui/tui-win.c (tui_initialize_win): Likewise.

Change-Id: Icd9d9f775542ae5fc2cd148c12f481e7885936d5
2020-10-02 14:47:06 -04:00
Simon Marchi
2554f6f564 gdb: give names to event loop file handlers
Assign names to event loop file handlers.  They will be used in debug
messages when file handlers are invoked.

In GDB, each UI used to get its own unique number, until commit
cbe256847e ("Remove ui::num").  Re-introduce this field, and use it to
make a unique name for the handler.

I'm not too sure what goes on in ser-base.c, all I know is that it's
what is used when debugging remotely.  I've just named the main handler
"serial".  It would be good to have unique names there too.  For instance
when debugging with two different remote connections, we'd ideally want
the handlers to have unique names.  I didn't do it in this patch though.

gdb/ChangeLog:

	* async-event.c (initialize_async_signal_handlers): Pass name to
	add_file_handler
	* event-top.c (ui_register_input_event_handler): Likewise.
	* linux-nat.c (linux_nat_target::async): Likewise.
	* run-on-main-thread.c (_initialize_run_on_main_thread):
	Likewise
	* ser-base.c (reschedule): Likewise.
	(ser_base_async): Likewise.
	* tui/tui-io.c: Likewise.
	* top.h (struct ui) <num>: New field.
	* top.c (highest_ui_num): New variable.
	(ui::ui): Initialize num.

gdbserver/ChangeLog:

	* linux-low.cc (linux_process_target::async): Pass name to
	add_file_handler.
	* remote-utils.cc (handle_accept_event): Likewise.
	(remote_open): Likewise.

gdbsupport/ChangeLog:

	* event-loop.h (add_file_handler): Add "name" parameter.
	* event-loop.cc (struct file_handler) <name>: New field.
	(create_file_handler): Add "name" parameter, assign it to file
	handler.
	(add_file_handler): Add "name" parameter.

Change-Id: I9f1545f73888ebb6778eb653a618ca44d105f92c
2020-10-02 14:46:56 -04:00
Tom Tromey
9dccd06e8a Remove target_has_registers macro
This removes the target_has_registers object-like macro, replacing it
with the underlying function.

gdb/ChangeLog
2020-09-28  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_get_register)
	(tui_data_window::show_registers): Update.
	* thread.c (scoped_restore_current_thread::restore)
	(scoped_restore_current_thread::scoped_restore_current_thread):
	Update.
	* regcache-dump.c (regcache_print): Update.
	* python/py-finishbreakpoint.c (bpfinishpy_detect_out_scope_cb):
	Update.
	* mi/mi-main.c (mi_cmd_data_write_register_values): Update.
	* mep-tdep.c (current_me_module, current_options): Update.
	* linux-thread-db.c (thread_db_load): Update.
	* infcmd.c (registers_info, info_vector_command)
	(info_float_command): Update.
	* ia64-tdep.c (ia64_frame_prev_register)
	(ia64_sigtramp_frame_prev_register): Update.
	* ia64-libunwind-tdep.c (libunwind_frame_prev_register): Update.
	* gcore.c (derive_stack_segment): Update.
	* frame.c (get_current_frame, has_stack_frames): Update.
	* findvar.c (language_defn::read_var_value): Update.
	* arm-tdep.c (arm_pc_is_thumb): Update.
	* target.c (target_has_registers): Rename from
	target_has_registers_1.
	* target.h (target_has_registers): Remove macro.
	(target_has_registers): Rename from target_has_registers_1.
2020-09-28 19:52:21 -06:00
Tom Tromey
841de12014 Remove target_has_stack macro
This removes the target_has_stack object-like macro, replacing it with
the underlying function.

gdb/ChangeLog
2020-09-28  Tom Tromey  <tom@tromey.com>

	* windows-tdep.c (tlb_make_value): Update.
	* tui/tui-regs.c (tui_data_window::show_registers): Update.
	* thread.c (scoped_restore_current_thread::restore)
	(scoped_restore_current_thread::scoped_restore_current_thread)
	(thread_command): Update.
	* stack.c (backtrace_command_1, frame_apply_level_command)
	(frame_apply_all_command, frame_apply_command): Update.
	* infrun.c (siginfo_make_value, restore_infcall_control_state):
	Update.
	* gcore.c (derive_stack_segment): Update.
	* frame.c (get_current_frame, has_stack_frames): Update.
	* auxv.c (info_auxv_command): Update.
	* ada-tasks.c (ada_build_task_list): Update.
	* target.c (target_has_stack): Rename from target_has_stack_1.
	* target.h (target_has_stack): Remove macro.
	(target_has_stack): Rename from target_has_stack_1.
2020-09-28 19:52:21 -06:00
Tom Tromey
a739972c7c Remove target_has_memory macro
This removes the target_has_memory object-like macro, replacing it
with the underlying function.

gdb/ChangeLog
2020-09-28  Tom Tromey  <tom@tromey.com>

	* target.c (target_has_memory): Rename from target_has_memory_1.
	* tui/tui-regs.c (tui_data_window::show_registers): Update.
	* thread.c (scoped_restore_current_thread::restore)
	(scoped_restore_current_thread::scoped_restore_current_thread):
	Update.
	* frame.c (get_current_frame, has_stack_frames): Update.
	* target.h (target_has_memory): Remove macro.
	(target_has_memory): Rename from target_has_memory_1.
2020-09-28 19:52:21 -06:00
Tom Tromey
2c72d5e58a Rewrite tui_puts
This rewrites tui_puts.  It now writes as many bytes as possible in a
call to waddnstr, letting curses handle multi-byte sequences properly.

Note that tui_puts_internal remains.  It is needed to handle computing
the start line of the readline prompt, which is difficult to do
properly in the case where redisplaying can also cause the command
window to scroll.  This might be possible to implement by reverting to
single "character" output, by using mbsrtowcs for its side effects to
find character boundaries in the input.  I have not attempted this.

gdb/ChangeLog
2020-09-27  Tom Tromey  <tom@tromey.com>

	PR tui/25342:
	* tui/tui-io.c (tui_puts): Rewrite.  Move earlier.
2020-09-27 20:30:33 -06:00
Tom Tromey
35a982372f Use ISCNTRL in tui_copy_source_line
This changes tui_copy_source_line to use ISCNTRL.  This lets it work
more nicely with UTF-8 input.  Note that this still won't work for
stateful multi-byte encodings; for that much more work would be
required.  However, I think this patch does not make gdb any worse in
this scenario.

gdb/ChangeLog
2020-09-27  Tom Tromey  <tom@tromey.com>

	PR tui/25342:
	* tui/tui-winsource.c (tui_copy_source_line): Use ISNCTRL.
2020-09-27 20:30:32 -06:00
Tom Tromey
9e820dec13 Use a curses pad for source and disassembly windows
This changes the TUI source and disassembly windows to use a curses
pad for their text.  This is an important step toward properly
handling non-ASCII characters, because it makes it easy to scroll
horizontally without needing gdb to also understand multi-byte
character boundaries -- this can be wholly delegated to curses.
Horizontal scrolling is probably also faster now, because no
re-rendering is required.

gdb/ChangeLog
2020-09-27  Tom Tromey  <tom@tromey.com>

	* unittests/tui-selftests.c: Update.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<extra_margin, show_line_number, refresh_pad>: New methods.
	<m_max_length, m_pad>: New members.
	(tui_copy_source_line): Update.
	* tui/tui-winsource.c (tui_copy_source_line): Remove line_no,
	first_col, line_width, ndigits parameters.  Add length.
	(tui_source_window_base::show_source_line): Write to pad.  Line
	number now 0-based.
	(tui_source_window_base::refresh_pad): New method.
	(tui_source_window_base::show_source_content): Write to pad.  Call
	refresh_pad.
	(tui_source_window_base::do_scroll_horizontal): Call refresh_pad,
	not refill.
	(tui_source_window_base::update_exec_info): Call
	show_line_number.
	* tui/tui-source.h (struct tui_source_window) <extra_margin>: New
	method.
	<m_digits>: New member.
	* tui/tui-source.c (tui_source_window::set_contents): Set m_digits
	and m_max_length.
	(tui_source_window::show_line_number): New method.
	* tui/tui-io.h (tui_puts): Fix comment.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Set
	m_max_length.
2020-09-27 20:30:32 -06:00
Tom Tromey
c15c15c8d9 Remove a call to show_source_line from TUI
This removes a call to show_source_line from tui_source_window_base.
This call isn't needed because this function already calls the
'refill' method if the state changed.

gdb/ChangeLog
2020-09-27  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.c
	(tui_source_window_base::set_is_exec_point_at): Don't call
	show_source_line.
2020-09-27 20:30:31 -06:00
Tom Tromey
b551a89f51 Don't let TUI focus on locator
PR tui/26638 notes that the C-x o binding can put the focus on the
locator window.  However, this is not useful and did not happen
historically.  This patch changes the TUI to skip this window when
switching focus.

gdb/ChangeLog
2020-09-24  Tom Tromey  <tromey@adacore.com>

	PR tui/26638:
	* tui/tui-stack.h (struct tui_locator_window) <can_focus>: New
	method.
	* tui/tui-data.h (struct tui_win_info) <can_focus>: New method.
	* tui/tui-data.c (tui_next_win): Exclude non-focusable windows.
	(tui_prev_win): Rewrite.

gdb/testsuite/ChangeLog
2020-09-24  Tom Tromey  <tromey@adacore.com>

	PR tui/26638:
	* gdb.tui/list.exp: Check output of "focus next".
2020-09-24 12:25:59 -06:00
Tom de Vries
90fcc46681 [gdb/tui] Fix Wmaybe-uninitialized warning in tui-winsource.c
When compiling with CFLAGS/CXXFLAGS="-O0 -g -Wall" and using g++ 11.0.0, we
run into:
...
src/gdb/tui/tui-winsource.c: In function \
  'void tui_update_all_breakpoint_info(breakpoint*)':
src/gdb/tui/tui-winsource.c:427:58: warning: '<unknown>' may be used \
  uninitialized [-Wmaybe-uninitialized]
  427 |   for (tui_source_window_base *win : tui_source_windows ())
      |                                                          ^
In file included from src/gdb/tui/tui-winsource.c:38:
src/gdb/tui/tui-winsource.h:236:30: note: by argument 1 of type \
  'const tui_source_windows*' to 'tui_source_window_iterator \
  tui_source_windows::begin() const' declared here
  236 |   tui_source_window_iterator begin () const
      |                              ^~~~~
src/gdb/tui/tui-winsource.c:427:58: note: '<anonymous>' declared here
  427 |   for (tui_source_window_base *win : tui_source_windows ())
      |                                                          ^
...

The warning doesn't make sense for an empty struct, PR gcc/96295 has been
filed about that.

For now, work around the warning by defining a default constructor.

Build on x86_64-linux.

gdb/ChangeLog:

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

	PR tui/26282
	* tui/tui-winsource.h (struct tui_source_windows::tui_source_windows):
	New default constructor.
2020-07-23 13:45:46 +02:00
Tom de Vries
947f759778 [gdb/tui,c++17] Fix NULL string_view in tui_partial_win_by_name
When building gdb with CFLAGS=-std=gnu17 and CXXFLAGS=-std=gnu++17 and running
test-case gdb.tui/new-layout.exp, we run into:
...
UNRESOLVED: gdb.tui/new-layout.exp: left window box after shrink (ll corner)
FAIL: gdb.tui/new-layout.exp: right window box after shrink (ll corner)
...

In a minimal form, we run into an abort when issuing a winheight command:
...
$ gdb -tui -ex "winheight src - 5"
   <tui stuff>
Aborted (core dumped)
$
...
with this backtrace at the abort:
...
\#0  0x0000000000438db0 in std::char_traits<char>::length (__s=0x0)
     at /usr/include/c++/9/bits/char_traits.h:335
\#1  0x000000000043b72e in std::basic_string_view<char, \
   std::char_traits<char> >::basic_string_view (this=0x7fffffffd4f0, \
   __str=0x0) at /usr/include/c++/9/string_view:124
\#2  0x000000000094971b in tui_partial_win_by_name (name="src")
     at src/gdb/tui/tui-win.c:663
...
due to a NULL comparison which constructs a string_view object from NULL:
...
   657  /* Answer the window represented by name.  */
   658  static struct tui_win_info *
   659  tui_partial_win_by_name (gdb::string_view name)
   660  {
   661    struct tui_win_info *best = nullptr;
   662
   663    if (name != NULL)
...

In gdbsupport/gdb_string_view.h, we either use:
- gdb's copy of libstdc++-v3/include/experimental/string_view, or
- the standard implementation of string_view, when built with C++17 or later
  (which in gcc's case comes from libstdc++-v3/include/std/string_view)

In the first case, there's support for constructing a string_view from a NULL
pointer:
...
      /*constexpr*/ basic_string_view(const _CharT* __str)
      : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
        _M_str{__str}
      { }
...
but in the second case, there's not:
...
      __attribute__((__nonnull__)) constexpr
      basic_string_view(const _CharT* __str) noexcept
      : _M_len{traits_type::length(__str)},
        _M_str{__str}
      { }
...

Fix this by removing the NULL comparison altogether.

Build on x86_64-linux with CFLAGS=-std=gnu17 and CXXFLAGS=-std=gnu++17, and
tested.

gdb/ChangeLog:

2020-07-06  Tom de Vries  <tdevries@suse.de>

	PR tui/26205
	* tui/tui-win.c (tui_partial_win_by_name): Don't test for NULL name.
2020-07-06 09:54:43 +02:00
Tom Tromey
1cdf9e33ea Make tui_win_info::name pure virtual
It seemed cleaner to me for tui_win_info::name to be pure virtual.
This meant adding a name method to the locator window; but this too
seems like an improvement.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (struct tui_win_info) <name>: Now pure virtual.
	* tui/tui-stack.h (struct tui_locator_window) <name>: New method.
2020-07-01 21:21:17 -06:00
Tom Tromey
32c1e21009 Remove tui_gen_win_info
This merges the tui_gen_win_info base class with tui_win_info;
renaming the resulting class to tui_win_info.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.c (tui_win_info::refresh_window): Move from
	tui_gen_win_info.
	(tui_win_info::make_window): Merge with
	tui_gen_win_info::make_window.
	(tui_win_info::make_visible): Move from tui_gen_win_info.
	* tui/tui-win.c (tui_win_info::max_width): Move from
	tui_gen_win_info.
	* tui/tui-layout.h (class tui_layout_window) <m_window>: Change
	type.
	<window_factory>: Likewise.
	* tui/tui-layout.c (tui_win_info::resize): Move from
	tui_gen_win_info.
	(make_standard_window): Change return type.
	(get_locator_window, tui_get_window_by_name): Likewise.
	(tui_layout_window::apply): Remove a cast.
	* tui/tui-data.h (MIN_WIN_HEIGHT): Move earlier.
	(struct tui_win_info): Merge with tui_gen_win_info.
	(struct tui_gen_win_info): Remove.
2020-07-01 21:21:17 -06:00
Tom Tromey
a30cb6dabb Derive tui_locator_window from tui_win_info
tui_locator_window is the last remaining concrete child class of
tui_gen_win_info.  It seems a bit cleaner to me to flatten the
hierarchy a bit; this patch prepares for that by changing
tui_locator_window to derive from tui_win_info.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.h (struct tui_locator_window): Derive from
	tui_win_info.
	<do_scroll_horizontal, do_scroll_vertical>: New methods.
	<can_box>: New method.
2020-07-01 21:21:16 -06:00
Tom Tromey
1eb2161f83 Remove body of tui_locator_window constructor
The tui_locator_window constructor initializes the first character of
two of its members.  However, this is actually an error, since these
were changed to be std::string.  This removes the erroneous code.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.h (struct tui_locator_window): Remove body.
2020-07-01 21:21:16 -06:00
Tom Tromey
7134f2eb92 Don't derive tui_data_item_window from tui_gen_win_info
There's no deep reason that tui_data_item_window should derive from
tui_gen_win_info -- it currently uses a curses window to render, but
that isn't truly needed, and it adds some hacks to other parts of the
TUI.

This patch changes tui_data_item_window so that it doesn't have a base
class, and updates the register window.  This simplifies the code and
enables a subsequent cleanup.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::display_registers_from)
	(tui_data_window::display_registers_from)
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows): Update.
	(tui_data_window::refresh_window, tui_data_window::no_refresh):
	Remove.
	(tui_data_window::check_register_values): Update.
	(tui_data_item_window::rerender): Add parameters.  Update.
	(tui_data_item_window::refresh_window): Remove.
	* tui/tui-data.h (struct tui_gen_win_info) <no_refresh>: No longer
	virtual.
	* tui/tui-regs.h (struct tui_data_item_window): Don't derive from
	tui_gen_win_info.
	<refresh_window, max_height, min_height>: Remove.
	<rerender>: Add parameters.
	<x, y, visible>: New members.
	(struct tui_data_window) <refresh_window, no_refresh>: Remove.
	<m_item_width>: New member.
2020-07-01 21:21:15 -06:00
Tom Tromey
22b7b0412b Rename tui_data_item_window::item_no
tui_data_item_window::item_no is misnamed -- it only can be used for a
register, but it references a "display" number as well.  (Based on
other comments I've seen in the past -- most since deleted -- I think
there were plans at one point to display variables in this window as
well.  However, this was never implemented.)

This patch renames this member to be more correct.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::show_register_group)
	(tui_data_window::check_register_values): Update.
	* tui/tui-regs.h (struct tui_data_item_window) <regno>: Rename
	from item_no.
2020-07-01 21:21:15 -06:00
Tom Tromey
c9753adb01 Remove useless "if' from tui-regs.c
tui_data_window::show_register_group had a useless "if" -- the
condition could never be false.  This patch removes it.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::show_register_group): Remove
	useless "if".
2020-07-01 21:21:14 -06:00
Tom Tromey
9ab26b4a0f Remove tui_data_window::name
The "name" member of tui_data_window was set, but never used.  This
removes it.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_data_window::show_register_group): Update.
	* tui/tui-regs.h (struct tui_data_item_window) <name>: Remove.
2020-07-01 21:21:14 -06:00
Tom Tromey
e555083f95 Move some code out of tui-data.h
This moves some code out of tui-data.h, to more closely related
places.  Some unused forward declarations are also removed.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.c (SINGLE_KEY): Move from tui-data.h
	* tui/tui-winsource.h (enum tui_line_or_address_kind)
	(struct tui_line_or_address): Move from tui-data.h.
	* tui/tui-win.c (DEFAULT_TAB_LEN): Move from tui-data.h.
	* tui/tui-data.h (DEFAULT_TAB_LEN): Move to tui-win.c.
	(tui_cmd_window, tui_source_window_base, tui_source_window)
	(tui_disasm_window): Don't declare.
	(enum tui_line_or_address_kind, struct tui_line_or_address): Move
	to tui-winsource.h.
	(SINGLE_KEY): Move to tui-stack.c.
2020-07-01 21:21:13 -06:00
Tom Tromey
7a02bab704 Remove tui_expand_tabs
tui_expand_tabs only has a single caller.  This patch removes this
function, in favor of a tab-expanding variant of string_file.  This
simplifies the code somewhat.

gdb/ChangeLog
2020-07-01  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (struct tui_data_item_window) <content>: Now a
	std::string.
	* tui/tui-regs.c (class tab_expansion_file): New.
	(tab_expansion_file::write): New method.
	(tui_register_format): Change return type.  Use
	tab_expansion_file.
	(tui_get_register, tui_data_window::display_registers_from)
	(tui_data_item_window::rerender): Update.
	* tui/tui-io.h (tui_expand_tabs): Don't declare.
	* tui/tui-io.c (tui_expand_tabs): Remove.
2020-07-01 21:21:13 -06:00