* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
tuiCommand.h, tuiIO.c, tuiIO.h, tuiData.h, tuiData.c: Likewise.
tuiDataWin.c, tuiDataWin.h, tuiDisassem.c, tuiDisassem.h: Likewise.
tuiGeneralWin.c, tuiGeneralWin.h, tuiLayout.c, tuiLayout.h: Likewise.
tuiRegs.c, tuiRegs.h, tuiSource.c, tuiSource.h: Likewise.
tuiSouceWin.c, tuiSourceWin.h, tuiStack.c, tuiStack.h: Likewise.
2001-07-14 19:01:25 +00:00
|
|
|
|
/* TUI layout window management.
|
2002-03-01 06:19:28 +00:00
|
|
|
|
|
2021-01-01 12:03:39 +04:00
|
|
|
|
Copyright (C) 1998-2021 Free Software Foundation, Inc.
|
2002-03-01 06:19:28 +00:00
|
|
|
|
|
* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
tuiCommand.h, tuiIO.c, tuiIO.h, tuiData.h, tuiData.c: Likewise.
tuiDataWin.c, tuiDataWin.h, tuiDisassem.c, tuiDisassem.h: Likewise.
tuiGeneralWin.c, tuiGeneralWin.h, tuiLayout.c, tuiLayout.h: Likewise.
tuiRegs.c, tuiRegs.h, tuiSource.c, tuiSource.h: Likewise.
tuiSouceWin.c, tuiSourceWin.h, tuiStack.c, tuiStack.h: Likewise.
2001-07-14 19:01:25 +00:00
|
|
|
|
Contributed by Hewlett-Packard Company.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
tuiCommand.h, tuiIO.c, tuiIO.h, tuiData.h, tuiData.c: Likewise.
tuiDataWin.c, tuiDataWin.h, tuiDisassem.c, tuiDisassem.h: Likewise.
tuiGeneralWin.c, tuiGeneralWin.h, tuiLayout.c, tuiLayout.h: Likewise.
tuiRegs.c, tuiRegs.h, tuiSource.c, tuiSource.h: Likewise.
tuiSouceWin.c, tuiSourceWin.h, tuiStack.c, tuiStack.h: Likewise.
2001-07-14 19:01:25 +00:00
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 18:08:50 +00:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
tuiCommand.h, tuiIO.c, tuiIO.h, tuiData.h, tuiData.c: Likewise.
tuiDataWin.c, tuiDataWin.h, tuiDisassem.c, tuiDisassem.h: Likewise.
tuiGeneralWin.c, tuiGeneralWin.h, tuiLayout.c, tuiLayout.h: Likewise.
tuiRegs.c, tuiRegs.h, tuiSource.c, tuiSource.h: Likewise.
tuiSouceWin.c, tuiSourceWin.h, tuiStack.c, tuiStack.h: Likewise.
2001-07-14 19:01:25 +00:00
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 18:08:50 +00:00
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
2010-03-20 05:17:10 +00:00
|
|
|
|
#include "arch-utils.h"
|
1999-04-16 01:35:26 +00:00
|
|
|
|
#include "command.h"
|
|
|
|
|
#include "symtab.h"
|
|
|
|
|
#include "frame.h"
|
2002-09-30 00:52:27 +00:00
|
|
|
|
#include "source.h"
|
2020-02-22 11:48:26 -07:00
|
|
|
|
#include "cli/cli-cmds.h"
|
|
|
|
|
#include "cli/cli-decode.h"
|
2020-02-22 11:48:26 -07:00
|
|
|
|
#include "cli/cli-utils.h"
|
2001-07-17 22:22:40 +00:00
|
|
|
|
#include <ctype.h>
|
2020-02-22 11:48:26 -07:00
|
|
|
|
#include <unordered_map>
|
2020-02-22 11:48:26 -07:00
|
|
|
|
#include <unordered_set>
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2004-01-19 04:31:53 +00:00
|
|
|
|
#include "tui/tui.h"
|
2019-07-02 15:48:59 -06:00
|
|
|
|
#include "tui/tui-command.h"
|
2004-01-19 04:31:53 +00:00
|
|
|
|
#include "tui/tui-data.h"
|
|
|
|
|
#include "tui/tui-wingeneral.h"
|
|
|
|
|
#include "tui/tui-stack.h"
|
|
|
|
|
#include "tui/tui-regs.h"
|
|
|
|
|
#include "tui/tui-win.h"
|
|
|
|
|
#include "tui/tui-winsource.h"
|
|
|
|
|
#include "tui/tui-disasm.h"
|
2008-02-21 Pedro Alves <pedro@codesorcery.com>
Silence a few -Wmissing-prototypes warnings.
PR build/9877:
* amd64-nat.c: Include "amd64-nat.h".
* fork-child.c (_initialize_fork_child): Ditto.
* gcore.c (_initialize_gcore): Ditto.
* inf-ptrace.c: Include "inf-ptrace.h".
(inf_ptrace_store_registers): Make it static.
* linux-nat.c (linux_nat_terminal_ours): Make it static.
(_initialize_linux_nat): Declare before definition.
* linux-tdep.c: Include "linux-tdep.h".
* linux-thread-db.c (_initialize_thread_db): Declare before
definition.
* proc-service.c (_initialize_proc_service): Ditto.
* remote.c (remote_send_printf): Make it static.
* solib.c: Include "solib.h".
* symfile-mem.c (_initialize_symfile_mem): Declare before
definition.
* ada-lang.c (ada_la_decode, ada_match_name)
(ada_suppress_symbol_printing, ada_is_array_type)
(ada_value_ptr_subscript, ada_array_length)
(ada_to_static_fixed_value): Make them static.
(_initialize_ada_language): Declare before definition.
* ada-tasks.c (ada_get_task_number, ada_get_environment_task)
(ada_task_list_changed, ada_new_objfile_observer): Make them
static.
(_initialize_tasks): Declare before definition.
* addrmap.c (_initialize_addrmap): Declare before definition.
* auxv.c (default_auxv_parse): Make it static.
* bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make
them static.
* breakpoint.c (remove_sal): Add line break.
(expand_line_sal_maybe): Make it static.
* cp-name-parser.y: Include "cp-support.h".
* cp-valprint.c (cp_find_class_member): Make it static.
* eval.c (value_f90_subarray): Ditto.
* exceptions.c (print_any_exception): Ditto.
* findcmd.c (_initialize_mem_search): Declare before definition.
* frame.c (frame_observer_target_changed): Make it static.
* gnu-v3-abi.c (gnuv3_find_method_in): Make it static.
* inf-child.c: Include "inf-child.h".
* inferior.h (valid_inferior_id): Rename to ...
(valid_gdb_inferior_id): ... this.
* infrun.c (infrun_thread_stop_requested, siginfo_make_value):
Make them static.
* jv-lang.c (java_language_arch_info): Make it static.
* m2-typeprint.c (m2_get_discrete_bounds): Ditto.
* osdata.c (info_osdata_command): Make it static.
* regcache.c (regcache_observer_target_changed): Make it static.
* reverse.c (_initialize_reverse): Declare before definition.
* stabsread.c (cleanup_undefined_types_noname)
(cleanup_undefined_types_1): Make them static.
* symfile.c (place_section): Make it static.
* symtab.c (find_pc_sect_psymtab_closer): Make it static.
* target-descriptions.c (_initialize_target_descriptions): Declare
before definition.
* target.c (default_get_ada_task_ptid, find_default_can_async_p)
(find_default_is_async_p, find_default_supports_non_stop): Make
them static.
(target_supports_non_stop): Add prototype.
(dummy_pid_to_str): Make it static.
* utils.c (_initialize_utils): Declare before definition.
* ada-exp.y (_initialize_ada_exp): Declare before definition.
* solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype.
* target.h (struct target_ops): Add a prototype to the
to_can_execute_reverse callback.
* macroscope.c (_initialize_macroscope): Declare before definition.
* cp-namespace.c (_initialize_cp_namespace): Declare before definition.
* python/python.c (_initialize_python): Declare before definition.
* tui/tui-command.c: Include "tui/tui-command.h".
* tui/tui-data.c (init_content_element, init_win_info): Make them
static.
* tui/tui-disasm.c: Include "tui/tui-disasm.h".
* tui/tui-interp.c (_initialize_tui_interp): Declare before
definition.
* tui/tui-layout.c: Include "tui/tui-layout.h".
(_initialize_tui_layout): Declare before definition.
* tui/tui-regs.c: Include "tui/tui-regs.h".
(tui_display_reg_element_at_line): Make it static.
(_initialize_tui_regs): Declare before definition.
* tui/tui-stack.c (_initialize_tui_stack): Declare before
definition.
* tui/tui-win.c: Include "tui/tui-win.h".
(_initialize_tui_win): Declare before definition.
(tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH.
* tui/tui-win.h (tui_sigwinch_handler): Delete declaration.
(tui_get_cmd_list): Add a prototype.
* tui/tui-windata.c: Include tui-windata.h.
* tui/tui-wingeneral.c (box_win): Make it static.
* cli/cli-logging.c (show_logging_command): Make it static.
(_initialize_cli_logging): Declare before definition.
* mi/mi-common.c (_initialize_gdb_mi_common): Declare before
definition.
2009-02-21 16:14:50 +00:00
|
|
|
|
#include "tui/tui-layout.h"
|
2019-07-02 15:55:01 -06:00
|
|
|
|
#include "tui/tui-source.h"
|
2004-02-10 Andrew Cagney <cagney@redhat.com>
* defs.h: Do not include "tui.h".
* gdb_curses.h: New file.
* tui/tui-hooks.h: New file.
* tui/tui.h (tui_update_all_exec_infos): Delete declaration.
(tui_install_hooks, tui_remove_hooks): Delete declarations.
(tui_initialize_io): Delete declaration.
(tui_initialize_readline: Delete redundant declaration.
(struct tui_point): Delete definition.
* tui/tui-data.h (struct tui_point): Define.
* cli/cli-decode.c [TUI]: Include "tui/tui.h".
* utils.c: Include "tui/tui.h".
* tui/tui-data.h: Include "tui/tui.h" and "gdb_curses.h".
* printcmd.c [TUI]: Include "tui/tui.h".
* cli/cli-cmds.c [TUI]: Include "tui/tui.h".
* tui/tui-command.c: Include "gdb_curses.h".
* tui/tui.c, tui/tui-winsource.c, tui/tui-wingeneral.c: Ditto.
* tui/tui-windata.c, tui/tui-win.c, tui/tui-stack.c: Ditto.
* tui/tui-source.c, tui/tui-regs.c, tui/tui-layout.c: Ditto.
* tui/tui-io.c, tui/tui-disasm.c, tui/tui-data.c: : Ditto.
* tui/tui-hooks.c: Include "tui-hooks.h" and "gdb_curses.h".
* Makefile.in: Update all dependencies.
(tui_hooks_h, gdb_curses_h): Define.
(SUBDIR_TUI_CFLAGS): Remove -I${srcdir}/tui.
2004-02-10 19:08:19 +00:00
|
|
|
|
#include "gdb_curses.h"
|
2003-06-22 15:21:39 +00:00
|
|
|
|
|
2009-07-02 17:17:42 +00:00
|
|
|
|
static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* The layouts. */
|
|
|
|
|
static std::vector<std::unique_ptr<tui_layout_split>> layouts;
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
|
|
|
|
/* The layout that is currently applied. */
|
|
|
|
|
static std::unique_ptr<tui_layout_base> applied_layout;
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* The "skeleton" version of the layout that is currently applied. */
|
|
|
|
|
static tui_layout_split *applied_skeleton;
|
2019-07-05 12:13:40 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* The two special "regs" layouts. Note that these aren't registered
|
|
|
|
|
as commands and so can never be deleted. */
|
|
|
|
|
static tui_layout_split *src_regs_layout;
|
|
|
|
|
static tui_layout_split *asm_regs_layout;
|
2019-07-05 12:13:40 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-data.h. */
|
|
|
|
|
std::vector<tui_win_info *> tui_windows;
|
|
|
|
|
|
2019-10-09 16:35:41 -06:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_apply_current_layout ()
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
struct gdbarch *gdbarch;
|
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
|
|
extract_display_start_addr (&gdbarch, &addr);
|
|
|
|
|
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
for (tui_win_info *win_info : tui_windows)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
win_info->make_visible (false);
|
|
|
|
|
|
2019-10-09 16:35:41 -06:00
|
|
|
|
applied_layout->apply (0, 0, tui_term_width (), tui_term_height ());
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
/* Keep the list of internal windows up-to-date. */
|
|
|
|
|
for (int win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
|
|
|
|
|
if (tui_win_list[win_type] != nullptr
|
|
|
|
|
&& !tui_win_list[win_type]->is_visible ())
|
|
|
|
|
tui_win_list[win_type] = nullptr;
|
|
|
|
|
|
|
|
|
|
/* This should always be made visible by a layout. */
|
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-01-15 10:31:19 +00:00
|
|
|
|
gdb_assert (TUI_CMD_WIN != nullptr);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
gdb_assert (TUI_CMD_WIN->is_visible ());
|
|
|
|
|
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
/* Get the new list of currently visible windows. */
|
|
|
|
|
std::vector<tui_win_info *> new_tui_windows;
|
|
|
|
|
applied_layout->get_windows (&new_tui_windows);
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Now delete any window that was not re-applied. */
|
|
|
|
|
tui_win_info *focus = tui_win_with_focus ();
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
for (tui_win_info *win_info : tui_windows)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
|
|
|
|
if (!win_info->is_visible ())
|
|
|
|
|
{
|
|
|
|
|
if (focus == win_info)
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
tui_set_win_focus_to (new_tui_windows[0]);
|
2021-02-08 11:11:24 +00:00
|
|
|
|
delete win_info;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
/* Replace the global list of active windows. */
|
|
|
|
|
tui_windows = std::move (new_tui_windows);
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr)
|
|
|
|
|
tui_get_begin_asm_address (&gdbarch, &addr);
|
|
|
|
|
tui_update_source_windows_with_addr (gdbarch, addr);
|
2019-10-09 16:35:41 -06:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2019-10-26 16:37:32 -06:00
|
|
|
|
/* See tui-layout. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_adjust_window_height (struct tui_win_info *win, int new_height)
|
|
|
|
|
{
|
|
|
|
|
applied_layout->adjust_size (win->name (), new_height);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Set the current layout to LAYOUT. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
static void
|
|
|
|
|
tui_set_layout (tui_layout_split *layout)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
applied_skeleton = layout;
|
|
|
|
|
applied_layout = layout->clone ();
|
|
|
|
|
tui_apply_current_layout ();
|
2002-08-24 12:28:33 +00:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
|
void
|
2004-01-23 23:25:17 +00:00
|
|
|
|
tui_add_win_to_layout (enum tui_win_type type)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* If the window already exists, no need to add it. */
|
|
|
|
|
if (tui_win_list[type] != nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* If the window we are trying to replace doesn't exist, we're
|
|
|
|
|
done. */
|
|
|
|
|
enum tui_win_type other = type == SRC_WIN ? DISASSEM_WIN : SRC_WIN;
|
|
|
|
|
if (tui_win_list[other] == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const char *name = type == SRC_WIN ? SRC_NAME : DISASSEM_NAME;
|
|
|
|
|
applied_layout->replace_window (tui_win_list[other]->name (), name);
|
|
|
|
|
tui_apply_current_layout ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find LAYOUT in the "layouts" global and return its index. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
static size_t
|
|
|
|
|
find_layout (tui_layout_split *layout)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < layouts.size (); ++i)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (layout == layouts[i].get ())
|
|
|
|
|
return i;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
}
|
2021-11-17 13:44:01 -05:00
|
|
|
|
gdb_assert_not_reached ("layout not found!?");
|
2004-02-08 00:05:16 +00:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Function to set the layout. */
|
2015-03-26 14:13:57 +00:00
|
|
|
|
|
Introduce class completion_tracker & rewrite completion<->readline interaction
This patch reworks the whole completion machinery, and prepares it
for later enhancements.
Adds a new "completion_tracker" class that is meant to hold everything
about the state of the current completion operation.
This class now has the responsibility of tracking the list of
completion matches, and checking whether the max completions limit has
been reached. You can look at this as this patch starting out by
C++fying the existing "completion_tracker" in symtab.c (it's just an
htab_t typedef currently), moving it to completer.h/c, and then making
it a class/generalizing/enhancing it.
Unlike with the current tracking, completion_tracker now checks
whether the limit has been reached on each completion match list
insertion. This both simplifies the max-completions handling code
(maybe_add_completion_enum is gone, for example), and is a
prerequisite for follow up patches.
The current completion_tracker is only used for symbol completions,
and the symbol code gets at the current instance via globals. This
patch cleans that up by adding a completion_tracker reference to the
signature of the completion functions, and passing the tracker around
everywhere necessary.
Then, the patch changes how the completion match list is handed over
to readline. Currently, we're using the rl_completion_entry_function
readline entry point, and the patch switches to
rl_attempted_completion_function. A following patch will want to let
GDB itself decide the common completion prefix between all matches
(what readline calls the "lowest common denominator"), instead of
having readline compute it, and that's not possible with the
rl_completion_entry_function entry point. Also,
rl_attempted_completion_function lets GDB hand over the match list to
readline as an array in one go instead of passing down matches one by
one, so from that angle it's a nicer entry point anyway.
Lastly, the patch catches exceptions around the readline entry points,
because we can't let C++ exceptions cross readline. We handle that in
the readline input entry point, but the completion entry point isn't
guarded, so GDB can abort if completion throws. E.g., in current
master:
(gdb) b -function "fun<tab>
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
Aborted (core dumped)
This patch fixes that. This will be exercised in the new tests added
later on in the series.
gdb/ChangeLog:
2017-07-17 Pedro Alves <palves@redhat.com>
* ada-lang.c (symbol_completion_match): Adjust comments.
(symbol_completion_add): Replace vector parameter with
completion_tracker parameter. Use it.
(ada_make_symbol_completion_list): Rename to...
(ada_collect_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it.
(ada_language_defn): Adjust.
* break-catch-syscall.c (catch_syscall_completer): Adjust
prototype and work with completion_tracker instead of VEC.
* breakpoint.c (condition_completer): Adjust prototype and work
with completion_tracker instead of VEC.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Adjust to renames.
* cli/cli-cmds.c (complete_command): Rework using
completion_tracker. Catch exceptions when completing.
* cli/cli-decode.c (integer_unlimited_completer)
(complete_on_cmdlist, complete_on_enum): Adjust prototype and work
with completion_tracker instead of VEC.
* command.h (struct completion_tracker): Forward declare.
(completer_ftype, completer_handle_brkchars_ftype): Change
types.
(complete_on_cmdlist, complete_on_enum): Adjust.
* completer.c: Include <algorithm>.
(struct gdb_completer_state): New.
(current_completion): New global.
(readline_line_completion_function): Delete.
(noop_completer, filename_completer)
(filename_completer_handle_brkchars, complete_files_symbols)
(linespec_location_completer): Adjust to work with a
completion_tracker instead of a VEC.
(string_or_empty): New.
(collect_explicit_location_matches): Adjust to work with a
completion_tracker instead of a VEC.
(explicit_location_completer): Rename to ...
(complete_explicit_location): ... this and adjust to work with a
completion_tracker instead of a VEC.
(location_completer): Adjust to work with a completion_tracker
instead of a VEC.
(add_struct_fields): Adjust to work with a completion_list instead
of VEC.
(expression_completer): Rename to ...
(complete_expression): ... this and adjust to work with a
completion_tracker instead of a VEC. Use complete_files_symbols.
(expression_completer): Reimplement on top of complete_expression.
(symbol_completer): Adjust to work with a completion_tracker
instead of a VEC.
(enum complete_line_internal_reason): Add describing comments.
(complete_line_internal_normal_command): Adjust to work with a
completion_tracker instead of a VEC.
(complete_line_internal): Rename to ...
(complete_line_internal_1): ... this and adjust to work with a
completion_tracker instead of a VEC. Assert TEXT is NULL in the
handle_brkchars phase.
(new_completion_tracker): Delete.
(complete_line_internal): Reimplement as TRY/CATCH wrapper around
complete_line_internal_1.
(free_completion_tracker): Delete.
(INITIAL_COMPLETION_HTAB_SIZE): New.
(completion_tracker::completion_tracker)
(completion_tracker::~completion_tracker): New.
(maybe_add_completion): Delete.
(completion_tracker::maybe_add_completion)
(completion_tracker::add_completion)
(completion_tracker::add_completions): New.
(throw_max_completions_reached_error): Delete.
(complete_line): Adjust to work with a completion_tracker instead
of a VEC. Don't create a completion_tracker_t or check for max
completions here.
(command_completer, command_completer_handle_brkchars)
(signal_completer, reg_or_group_completer_1)
(reg_or_group_completer, default_completer_handle_brkchars):
Adjust to work with a completion_tracker.
(gdb_completion_word_break_characters_throw): New.
(gdb_completion_word_break_characters): Reimplement.
(line_completion_function): Delete.
(completion_tracker::recompute_lowest_common_denominator)
(expand_preserving_ws)
(completion_tracker::build_completion_result)
(completion_result::completion_result)
(completion_result::completion_result)
(completion_result::~completion_result)
(completion_result::completion_result)
(completion_result::release_match_list, compare_cstrings)
(completion_result::sort_match_list)
(completion_result::reset_match_list)
(gdb_rl_attempted_completion_function_throw)
(gdb_rl_attempted_completion_function): New.
* completer.h (completion_list, struct completion_result)
(class completion_tracker): New.
(complete_line): Add completion_tracker parameter.
(readline_line_completion_function): Delete.
(gdb_rl_attempted_completion_function): New.
(noop_completer, filename_completer, expression_completer)
(location_completer, symbol_completer, command_completer)
(signal_completer, reg_or_group_completer): Update prototypes.
(completion_tracker_t, new_completion_tracker)
(make_cleanup_free_completion_tracker): Delete.
(enum maybe_add_completion_enum): Delete.
(maybe_add_completion): Delete.
(throw_max_completions_reached_error): Delete.
* corefile.c (complete_set_gnutarget): Adjust to work with a
completion_tracker instead of a VEC.
* cp-abi.c (cp_abi_completer): Adjust to work with a
completion_tracker instead of a VEC.
* d-lang.c (d_language_defn): Adjust.
* disasm.c (disassembler_options_completer): Adjust to work with a
completion_tracker instead of a VEC.
* f-lang.c (f_make_symbol_completion_list): Rename to ...
(f_collect_symbol_completion_matches): ... this. Adjust to work
with a completion_tracker instead of a VEC.
(f_language_defn): Adjust.
* go-lang.c (go_language_defn): Adjust.
* guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer):
Adjust to work with a completion_tracker instead of a VEC.
* infrun.c (handle_completer): Likewise.
* interps.c (interpreter_completer): Likewise.
* interps.h (interpreter_completer): Likewise.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Adjust.
* language.h (language_defn::la_make_symbol_completion_list):
Rename to ...
(language_defn::la_collect_symbol_completion_matches): ... this
and adjust to work with a completion_tracker instead of a VEC.
* m2-lang.c (m2_language_defn): Adjust.
* objc-lang.c (objc_language_defn): Adjust.
* opencl-lang.c (opencl_language_defn): Adjust.
* p-lang.c (pascal_language_defn): Adjust.
* python/py-cmd.c (cmdpy_completer_helper): Handle NULL word.
(cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work
with a completion_tracker.
* rust-lang.c (rust_language_defn): Adjust.
* symtab.c (free_completion_list, do_free_completion_list)
(return_val, completion_tracker): Delete.
(completion_list_add_name, completion_list_add_symbol)
(completion_list_add_msymbol, completion_list_objc_symbol)
(completion_list_add_fields, add_symtab_completions): Add
completion_tracker parameter and use it.
(default_make_symbol_completion_list_break_on_1): Rename to...
(default_collect_symbol_completion_matches_break_on): ... this.
Add completion_tracker parameter and use it instead of allocating
a completion tracker here.
(default_make_symbol_completion_list_break_on): Delete old
implementation.
(default_make_symbol_completion_list): Delete.
(default_collect_symbol_completion_matches): New.
(make_symbol_completion_list): Delete.
(collect_symbol_completion_matches): New.
(make_symbol_completion_type): Rename to ...
(collect_symbol_completion_matches_type): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list_1): Rename to...
(collect_file_symbol_completion_matches): ... this. Add
completion_tracker parameter and use it instead of VEC.
(make_file_symbol_completion_list): Delete.
(add_filename_to_list): Use completion_list instead of a VEC.
(add_partial_filename_data::list): Now a completion_list.
(make_source_files_completion_list): Work with a completion_list
instead of a VEC.
* symtab.h: Include "completer.h".
(default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list, make_symbol_completion_list)
(make_symbol_completion_type, make_file_symbol_completion_list)
(make_source_files_completion_list): Delete.
(default_collect_symbol_completion_matches_break_on)
(default_collect_symbol_completion_matches)
(collect_symbol_completion_matches)
(collect_symbol_completion_matches_type)
(collect_file_symbol_completion_matches)
(make_source_files_completion_list): New.
* top.c (init_main): Don't install a rl_completion_entry_function
hook. Install a rl_attempted_completion_function hook instead.
* tui/tui-layout.c (layout_completer): Adjust to work with a
completion_tracker.
* tui/tui-regs.c (tui_reggroup_completer):
* tui/tui-win.c (window_name_completer, focus_completer)
(winheight_completer): Adjust to work with a completion_tracker.
* value.c: Include "completer.h".
(complete_internalvar): Adjust to work with a completion_tracker.
* value.h (complete_internalvar): Likewise.
2017-07-17 14:45:59 +01:00
|
|
|
|
static void
|
2021-06-29 23:10:32 -04:00
|
|
|
|
tui_apply_layout (const char *args, int from_tty, cmd_list_element *command)
|
2015-03-26 14:13:57 +00:00
|
|
|
|
{
|
2021-06-25 21:35:40 -04:00
|
|
|
|
tui_layout_split *layout = (tui_layout_split *) command->context ();
|
2015-03-26 14:13:57 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Make sure the curses mode is enabled. */
|
|
|
|
|
tui_enable ();
|
|
|
|
|
tui_set_layout (layout);
|
2015-03-26 14:13:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_next_layout ()
|
|
|
|
|
{
|
|
|
|
|
size_t index = find_layout (applied_skeleton);
|
|
|
|
|
++index;
|
|
|
|
|
if (index == layouts.size ())
|
|
|
|
|
index = 0;
|
|
|
|
|
tui_set_layout (layouts[index].get ());
|
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Implement the "layout next" command. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
static void
|
|
|
|
|
tui_next_layout_command (const char *arg, int from_tty)
|
|
|
|
|
{
|
2019-06-30 20:43:32 -06:00
|
|
|
|
tui_enable ();
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_next_layout ();
|
2001-07-18 22:03:22 +00:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_set_initial_layout ()
|
|
|
|
|
{
|
|
|
|
|
tui_set_layout (layouts[0].get ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implement the "layout prev" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tui_prev_layout_command (const char *arg, int from_tty)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_enable ();
|
|
|
|
|
size_t index = find_layout (applied_skeleton);
|
|
|
|
|
if (index == 0)
|
|
|
|
|
index = layouts.size ();
|
|
|
|
|
--index;
|
|
|
|
|
tui_set_layout (layouts[index].get ());
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_regs_layout ()
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* If there's already a register window, we're done. */
|
|
|
|
|
if (TUI_DATA_WIN != nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tui_set_layout (TUI_DISASM_WIN != nullptr
|
|
|
|
|
? asm_regs_layout
|
|
|
|
|
: src_regs_layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implement the "layout regs" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tui_regs_layout_command (const char *arg, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
tui_enable ();
|
|
|
|
|
tui_regs_layout ();
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_remove_some_windows ()
|
|
|
|
|
{
|
|
|
|
|
tui_win_info *focus = tui_win_with_focus ();
|
|
|
|
|
|
2020-06-16 17:55:57 -06:00
|
|
|
|
if (strcmp (focus->name (), CMD_NAME) == 0)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
|
|
|
|
/* Try leaving the source or disassembly window. If neither
|
|
|
|
|
exists, just do nothing. */
|
|
|
|
|
focus = TUI_SRC_WIN;
|
|
|
|
|
if (focus == nullptr)
|
|
|
|
|
focus = TUI_DISASM_WIN;
|
|
|
|
|
if (focus == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applied_layout->remove_windows (focus->name ());
|
|
|
|
|
tui_apply_current_layout ();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-02 17:17:42 +00:00
|
|
|
|
static void
|
|
|
|
|
extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (TUI_SRC_WIN != nullptr)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
TUI_SRC_WIN->display_start_addr (gdbarch_p, addr_p);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
else if (TUI_DISASM_WIN != nullptr)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
TUI_DISASM_WIN->display_start_addr (gdbarch_p, addr_p);
|
|
|
|
|
else
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
*gdbarch_p = nullptr;
|
|
|
|
|
*addr_p = 0;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
}
|
2004-02-08 00:05:16 +00:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2019-06-17 14:08:44 -06:00
|
|
|
|
void
|
2020-07-01 21:21:12 -06:00
|
|
|
|
tui_win_info::resize (int height_, int width_,
|
|
|
|
|
int origin_x_, int origin_y_)
|
1999-04-16 01:35:26 +00:00
|
|
|
|
{
|
2019-07-15 15:28:56 -06:00
|
|
|
|
if (width == width_ && height == height_
|
2019-10-26 16:00:01 -06:00
|
|
|
|
&& x == origin_x_ && y == origin_y_
|
2019-07-15 15:28:56 -06:00
|
|
|
|
&& handle != nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-06-17 14:08:44 -06:00
|
|
|
|
width = width_;
|
2019-07-09 15:35:17 -06:00
|
|
|
|
height = height_;
|
2019-10-26 16:00:01 -06:00
|
|
|
|
x = origin_x_;
|
|
|
|
|
y = origin_y_;
|
2019-07-09 15:35:17 -06:00
|
|
|
|
|
|
|
|
|
if (handle != nullptr)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_WRESIZE
|
Make TUI window handle a unique_ptr
This changes tui_gen_win_info::handle to be a specialization of
unique_ptr. This is perhaps mildly uglier in some spots, due to the
proliferation of "get"; but on the other hand it cleans up some manual
management and it allows for the removal of tui_delete_win.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (tui_delete_win): Don't declare.
* tui/tui-stack.c (tui_locator_window::rerender): Update.
* tui/tui-command.c (tui_cmd_window::resize)
(tui_refresh_cmd_win): Update.
* tui/tui-win.c (tui_resize_all, tui_set_focus_command): Update.
* tui/tui.c (tui_rl_other_window, tui_enable): Update.
* tui/tui-data.c (~tui_gen_win_info): Remove.
* tui/tui-layout.c (tui_gen_win_info::resize): Update.
* tui/tui-io.c (update_cmdwin_start_line, tui_putc, tui_puts)
(tui_redisplay_readline, tui_mld_flush)
(tui_mld_erase_entire_line, tui_mld_getc, tui_getc): Update.
* tui/tui-regs.c (tui_data_window::delete_data_content_windows)
(tui_data_window::erase_data_content)
(tui_data_item_window::rerender)
(tui_data_item_window::refresh_window): Update.
* tui/tui-wingeneral.c (tui_gen_win_info::refresh_window)
(box_win, tui_gen_win_info::make_window)
(tui_gen_win_info::make_visible): Update.
(tui_delete_win): Remove.
* tui/tui-winsource.c
(tui_source_window_base::do_erase_source_content): Update.
(tui_show_source_line, tui_source_window_base::update_tab_width)
(tui_source_window_base::update_exec_info): Update.
* tui/tui-data.h (struct curses_deleter): New.
(struct tui_gen_win_info) <handle>: Now a unique_ptr.
(struct tui_gen_win_info) <~tui_gen_win_info>: Define.
2019-10-01 17:29:49 -06:00
|
|
|
|
wresize (handle.get (), height, width);
|
2019-10-26 16:00:01 -06:00
|
|
|
|
mvwin (handle.get (), y, x);
|
Make TUI window handle a unique_ptr
This changes tui_gen_win_info::handle to be a specialization of
unique_ptr. This is perhaps mildly uglier in some spots, due to the
proliferation of "get"; but on the other hand it cleans up some manual
management and it allows for the removal of tui_delete_win.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (tui_delete_win): Don't declare.
* tui/tui-stack.c (tui_locator_window::rerender): Update.
* tui/tui-command.c (tui_cmd_window::resize)
(tui_refresh_cmd_win): Update.
* tui/tui-win.c (tui_resize_all, tui_set_focus_command): Update.
* tui/tui.c (tui_rl_other_window, tui_enable): Update.
* tui/tui-data.c (~tui_gen_win_info): Remove.
* tui/tui-layout.c (tui_gen_win_info::resize): Update.
* tui/tui-io.c (update_cmdwin_start_line, tui_putc, tui_puts)
(tui_redisplay_readline, tui_mld_flush)
(tui_mld_erase_entire_line, tui_mld_getc, tui_getc): Update.
* tui/tui-regs.c (tui_data_window::delete_data_content_windows)
(tui_data_window::erase_data_content)
(tui_data_item_window::rerender)
(tui_data_item_window::refresh_window): Update.
* tui/tui-wingeneral.c (tui_gen_win_info::refresh_window)
(box_win, tui_gen_win_info::make_window)
(tui_gen_win_info::make_visible): Update.
(tui_delete_win): Remove.
* tui/tui-winsource.c
(tui_source_window_base::do_erase_source_content): Update.
(tui_show_source_line, tui_source_window_base::update_tab_width)
(tui_source_window_base::update_exec_info): Update.
* tui/tui-data.h (struct curses_deleter): New.
(struct tui_gen_win_info) <handle>: Now a unique_ptr.
(struct tui_gen_win_info) <~tui_gen_win_info>: Define.
2019-10-01 17:29:49 -06:00
|
|
|
|
wmove (handle.get (), 0, 0);
|
2019-07-09 15:35:17 -06:00
|
|
|
|
#else
|
Make TUI window handle a unique_ptr
This changes tui_gen_win_info::handle to be a specialization of
unique_ptr. This is perhaps mildly uglier in some spots, due to the
proliferation of "get"; but on the other hand it cleans up some manual
management and it allows for the removal of tui_delete_win.
gdb/ChangeLog
2019-10-09 Tom Tromey <tom@tromey.com>
* tui/tui-wingeneral.h (tui_delete_win): Don't declare.
* tui/tui-stack.c (tui_locator_window::rerender): Update.
* tui/tui-command.c (tui_cmd_window::resize)
(tui_refresh_cmd_win): Update.
* tui/tui-win.c (tui_resize_all, tui_set_focus_command): Update.
* tui/tui.c (tui_rl_other_window, tui_enable): Update.
* tui/tui-data.c (~tui_gen_win_info): Remove.
* tui/tui-layout.c (tui_gen_win_info::resize): Update.
* tui/tui-io.c (update_cmdwin_start_line, tui_putc, tui_puts)
(tui_redisplay_readline, tui_mld_flush)
(tui_mld_erase_entire_line, tui_mld_getc, tui_getc): Update.
* tui/tui-regs.c (tui_data_window::delete_data_content_windows)
(tui_data_window::erase_data_content)
(tui_data_item_window::rerender)
(tui_data_item_window::refresh_window): Update.
* tui/tui-wingeneral.c (tui_gen_win_info::refresh_window)
(box_win, tui_gen_win_info::make_window)
(tui_gen_win_info::make_visible): Update.
(tui_delete_win): Remove.
* tui/tui-winsource.c
(tui_source_window_base::do_erase_source_content): Update.
(tui_show_source_line, tui_source_window_base::update_tab_width)
(tui_source_window_base::update_exec_info): Update.
* tui/tui-data.h (struct curses_deleter): New.
(struct tui_gen_win_info) <handle>: Now a unique_ptr.
(struct tui_gen_win_info) <~tui_gen_win_info>: Define.
2019-10-01 17:29:49 -06:00
|
|
|
|
handle.reset (nullptr);
|
2019-07-09 15:35:17 -06:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handle == nullptr)
|
2019-07-13 16:47:31 -06:00
|
|
|
|
make_window ();
|
2019-07-09 17:29:13 -06:00
|
|
|
|
|
|
|
|
|
rerender ();
|
2019-06-17 14:08:44 -06:00
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
2019-10-08 15:44:18 -06:00
|
|
|
|
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Helper function to create one of the built-in (non-locator)
|
|
|
|
|
windows. */
|
|
|
|
|
|
|
|
|
|
template<enum tui_win_type V, class T>
|
2020-07-01 21:21:12 -06:00
|
|
|
|
static tui_win_info *
|
2020-02-22 11:48:26 -07:00
|
|
|
|
make_standard_window (const char *)
|
|
|
|
|
{
|
|
|
|
|
if (tui_win_list[V] == nullptr)
|
|
|
|
|
tui_win_list[V] = new T ();
|
|
|
|
|
return tui_win_list[V];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A map holding all the known window types, keyed by name. Note that
|
|
|
|
|
this is heap-allocated and "leaked" at gdb exit. This avoids
|
|
|
|
|
ordering issues with destroying elements in the map at shutdown.
|
|
|
|
|
In particular, destroying this map can occur after Python has been
|
|
|
|
|
shut down, causing crashes if any window destruction requires
|
|
|
|
|
running Python code. */
|
|
|
|
|
|
|
|
|
|
static std::unordered_map<std::string, window_factory> *known_window_types;
|
|
|
|
|
|
2019-10-07 18:03:02 -06:00
|
|
|
|
/* Helper function that returns a TUI window, given its name. */
|
|
|
|
|
|
2020-07-01 21:21:12 -06:00
|
|
|
|
static tui_win_info *
|
2019-10-07 18:03:02 -06:00
|
|
|
|
tui_get_window_by_name (const std::string &name)
|
|
|
|
|
{
|
gdb/tui: don't add windows to global list from tui_layout:window::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-01-25 15:46:58 +00:00
|
|
|
|
for (tui_win_info *window : tui_windows)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (name == window->name ())
|
|
|
|
|
return window;
|
|
|
|
|
|
|
|
|
|
auto iter = known_window_types->find (name);
|
|
|
|
|
if (iter == known_window_types->end ())
|
|
|
|
|
error (_("Unknown window type \"%s\""), name.c_str ());
|
|
|
|
|
|
2020-07-01 21:21:12 -06:00
|
|
|
|
tui_win_info *result = iter->second (name.c_str ());
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (result == nullptr)
|
|
|
|
|
error (_("Could not create window \"%s\""), name.c_str ());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the known window types. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
initialize_known_windows ()
|
|
|
|
|
{
|
|
|
|
|
known_window_types = new std::unordered_map<std::string, window_factory>;
|
|
|
|
|
|
2020-06-16 17:55:57 -06:00
|
|
|
|
known_window_types->emplace (SRC_NAME,
|
2020-02-22 11:48:26 -07:00
|
|
|
|
make_standard_window<SRC_WIN,
|
|
|
|
|
tui_source_window>);
|
2020-06-16 17:55:57 -06:00
|
|
|
|
known_window_types->emplace (CMD_NAME,
|
2020-02-22 11:48:26 -07:00
|
|
|
|
make_standard_window<CMD_WIN, tui_cmd_window>);
|
2020-06-16 17:55:57 -06:00
|
|
|
|
known_window_types->emplace (DATA_NAME,
|
2020-02-22 11:48:26 -07:00
|
|
|
|
make_standard_window<DATA_WIN,
|
|
|
|
|
tui_data_window>);
|
2020-06-16 17:55:57 -06:00
|
|
|
|
known_window_types->emplace (DISASSEM_NAME,
|
2020-02-22 11:48:26 -07:00
|
|
|
|
make_standard_window<DISASSEM_WIN,
|
|
|
|
|
tui_disasm_window>);
|
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-25 18:43:19 +00:00
|
|
|
|
known_window_types->emplace (STATUS_NAME,
|
|
|
|
|
make_standard_window<STATUS_WIN,
|
|
|
|
|
tui_locator_window>);
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_register_window (const char *name, window_factory &&factory)
|
|
|
|
|
{
|
|
|
|
|
std::string name_copy = name;
|
|
|
|
|
|
2020-06-16 17:55:57 -06:00
|
|
|
|
if (name_copy == SRC_NAME || name_copy == CMD_NAME || name_copy == DATA_NAME
|
|
|
|
|
|| name_copy == DISASSEM_NAME || name_copy == STATUS_NAME)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
error (_("Window type \"%s\" is built-in"), name);
|
|
|
|
|
|
|
|
|
|
known_window_types->emplace (std::move (name_copy),
|
|
|
|
|
std::move (factory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2019-10-07 18:03:02 -06:00
|
|
|
|
std::unique_ptr<tui_layout_base>
|
|
|
|
|
tui_layout_window::clone () const
|
|
|
|
|
{
|
|
|
|
|
tui_layout_window *result = new tui_layout_window (m_contents.c_str ());
|
|
|
|
|
return std::unique_ptr<tui_layout_base> (result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_window::apply (int x_, int y_, int width_, int height_)
|
|
|
|
|
{
|
|
|
|
|
x = x_;
|
|
|
|
|
y = y_;
|
|
|
|
|
width = width_;
|
|
|
|
|
height = height_;
|
|
|
|
|
gdb_assert (m_window != nullptr);
|
|
|
|
|
m_window->resize (height, width, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_layout_window::get_sizes (bool height, int *min_value, int *max_value)
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
|
|
|
|
if (m_window == nullptr)
|
|
|
|
|
m_window = tui_get_window_by_name (m_contents);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (height)
|
|
|
|
|
{
|
|
|
|
|
*min_value = m_window->min_height ();
|
|
|
|
|
*max_value = m_window->max_height ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*min_value = m_window->min_width ();
|
|
|
|
|
*max_value = m_window->max_width ();
|
|
|
|
|
}
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
tui_layout_window::top_boxed_p () const
|
|
|
|
|
{
|
|
|
|
|
gdb_assert (m_window != nullptr);
|
|
|
|
|
return m_window->can_box ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
tui_layout_window::bottom_boxed_p () const
|
|
|
|
|
{
|
|
|
|
|
gdb_assert (m_window != nullptr);
|
|
|
|
|
return m_window->can_box ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_layout_window::replace_window (const char *name, const char *new_window)
|
|
|
|
|
{
|
|
|
|
|
if (m_contents == name)
|
|
|
|
|
{
|
|
|
|
|
m_contents = new_window;
|
|
|
|
|
if (m_window != nullptr)
|
|
|
|
|
{
|
|
|
|
|
m_window->make_visible (false);
|
|
|
|
|
m_window = tui_get_window_by_name (m_contents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_layout_window::specification (ui_file *output, int depth)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
|
|
|
|
fputs_unfiltered (get_name (), output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
void
|
|
|
|
|
tui_layout_split::add_split (std::unique_ptr<tui_layout_split> &&layout,
|
|
|
|
|
int weight)
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
split s = {weight, std::move (layout)};
|
2019-10-07 18:03:02 -06:00
|
|
|
|
m_splits.push_back (std::move (s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_split::add_window (const char *name, int weight)
|
|
|
|
|
{
|
|
|
|
|
tui_layout_window *result = new tui_layout_window (name);
|
|
|
|
|
split s = {weight, std::unique_ptr<tui_layout_base> (result)};
|
|
|
|
|
m_splits.push_back (std::move (s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<tui_layout_base>
|
|
|
|
|
tui_layout_split::clone () const
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_layout_split *result = new tui_layout_split (m_vertical);
|
2019-10-07 18:03:02 -06:00
|
|
|
|
for (const split &item : m_splits)
|
|
|
|
|
{
|
|
|
|
|
std::unique_ptr<tui_layout_base> next = item.layout->clone ();
|
|
|
|
|
split s = {item.weight, std::move (next)};
|
|
|
|
|
result->m_splits.push_back (std::move (s));
|
|
|
|
|
}
|
|
|
|
|
return std::unique_ptr<tui_layout_base> (result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_layout_split::get_sizes (bool height, int *min_value, int *max_value)
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
*min_value = 0;
|
|
|
|
|
*max_value = 0;
|
|
|
|
|
bool first_time = true;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
for (const split &item : m_splits)
|
|
|
|
|
{
|
|
|
|
|
int new_min, new_max;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
item.layout->get_sizes (height, &new_min, &new_max);
|
|
|
|
|
/* For the mismatch case, the first time through we want to set
|
|
|
|
|
the min and max to the computed values -- the "first_time"
|
|
|
|
|
check here is just a funny way of doing that. */
|
|
|
|
|
if (height == m_vertical || first_time)
|
|
|
|
|
{
|
|
|
|
|
*min_value += new_min;
|
|
|
|
|
*max_value += new_max;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*min_value = std::max (*min_value, new_min);
|
|
|
|
|
*max_value = std::min (*max_value, new_max);
|
|
|
|
|
}
|
|
|
|
|
first_time = false;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
tui_layout_split::top_boxed_p () const
|
|
|
|
|
{
|
|
|
|
|
if (m_splits.empty ())
|
|
|
|
|
return false;
|
|
|
|
|
return m_splits[0].layout->top_boxed_p ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
tui_layout_split::bottom_boxed_p () const
|
|
|
|
|
{
|
|
|
|
|
if (m_splits.empty ())
|
|
|
|
|
return false;
|
|
|
|
|
return m_splits.back ().layout->top_boxed_p ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_split::set_weights_from_heights ()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
m_splits[i].weight = m_splits[i].layout->height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_adjust_result
|
2019-10-07 18:03:02 -06:00
|
|
|
|
tui_layout_split::adjust_size (const char *name, int new_height)
|
|
|
|
|
{
|
|
|
|
|
/* Look through the children. If one is a layout holding the named
|
|
|
|
|
window, we're done; or if one actually is the named window,
|
|
|
|
|
update it. */
|
|
|
|
|
int found_index = -1;
|
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_adjust_result adjusted
|
|
|
|
|
= m_splits[i].layout->adjust_size (name, new_height);
|
|
|
|
|
if (adjusted == HANDLED)
|
|
|
|
|
return HANDLED;
|
|
|
|
|
if (adjusted == FOUND)
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (!m_vertical)
|
|
|
|
|
return FOUND;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
found_index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found_index == -1)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
return NOT_FOUND;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
if (m_splits[found_index].layout->height == new_height)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
return HANDLED;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
|
|
|
|
set_weights_from_heights ();
|
|
|
|
|
int delta = m_splits[found_index].weight - new_height;
|
|
|
|
|
m_splits[found_index].weight = new_height;
|
|
|
|
|
|
|
|
|
|
/* Distribute the "delta" over the next window; but if the next
|
|
|
|
|
window cannot hold it all, keep going until we either find a
|
|
|
|
|
window that does, or until we loop all the way around. */
|
|
|
|
|
for (int i = 0; delta != 0 && i < m_splits.size () - 1; ++i)
|
|
|
|
|
{
|
|
|
|
|
int index = (found_index + 1 + i) % m_splits.size ();
|
|
|
|
|
|
|
|
|
|
int new_min, new_max;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
m_splits[index].layout->get_sizes (m_vertical, &new_min, &new_max);
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
|
|
|
|
if (delta < 0)
|
|
|
|
|
{
|
|
|
|
|
/* The primary window grew, so we are trying to shrink other
|
|
|
|
|
windows. */
|
|
|
|
|
int available = m_splits[index].weight - new_min;
|
|
|
|
|
int shrink_by = std::min (available, -delta);
|
|
|
|
|
m_splits[index].weight -= shrink_by;
|
|
|
|
|
delta += shrink_by;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* The primary window shrank, so we are trying to grow other
|
|
|
|
|
windows. */
|
|
|
|
|
int available = new_max - m_splits[index].weight;
|
|
|
|
|
int grow_by = std::min (available, delta);
|
|
|
|
|
m_splits[index].weight += grow_by;
|
|
|
|
|
delta -= grow_by;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (delta != 0)
|
|
|
|
|
{
|
|
|
|
|
warning (_("Invalid window height specified"));
|
|
|
|
|
/* Effectively undo any modifications made here. */
|
|
|
|
|
set_weights_from_heights ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Simply re-apply the updated layout. */
|
|
|
|
|
apply (x, y, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
return HANDLED;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_split::apply (int x_, int y_, int width_, int height_)
|
|
|
|
|
{
|
|
|
|
|
x = x_;
|
|
|
|
|
y = y_;
|
|
|
|
|
width = width_;
|
|
|
|
|
height = height_;
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
struct size_info
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
int size;
|
|
|
|
|
int min_size;
|
|
|
|
|
int max_size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
/* True if this window will share a box border with the previous
|
|
|
|
|
window in the list. */
|
|
|
|
|
bool share_box;
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
std::vector<size_info> info (m_splits.size ());
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Step 1: Find the min and max size of each sub-layout.
|
|
|
|
|
Fixed-sized layouts are given their desired size, and then the
|
2019-10-07 18:03:02 -06:00
|
|
|
|
remaining space is distributed among the remaining windows
|
|
|
|
|
according to the weights given. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
int available_size = m_vertical ? height : width;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
int last_index = -1;
|
|
|
|
|
int total_weight = 0;
|
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
{
|
|
|
|
|
bool cmd_win_already_exists = TUI_CMD_WIN != nullptr;
|
|
|
|
|
|
|
|
|
|
/* Always call get_sizes, to ensure that the window is
|
|
|
|
|
instantiated. This is a bit gross but less gross than adding
|
|
|
|
|
special cases for this in other places. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
m_splits[i].layout->get_sizes (m_vertical, &info[i].min_size,
|
|
|
|
|
&info[i].max_size);
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
|
|
|
|
if (!m_applied
|
|
|
|
|
&& cmd_win_already_exists
|
|
|
|
|
&& m_splits[i].layout->get_name () != nullptr
|
|
|
|
|
&& strcmp (m_splits[i].layout->get_name (), "cmd") == 0)
|
|
|
|
|
{
|
|
|
|
|
/* If this layout has never been applied, then it means the
|
|
|
|
|
user just changed the layout. In this situation, it's
|
|
|
|
|
desirable to keep the size of the command window the
|
2020-02-22 11:48:26 -07:00
|
|
|
|
same. Setting the min and max sizes this way ensures
|
2019-10-07 18:03:02 -06:00
|
|
|
|
that the resizing step, below, does the right thing with
|
|
|
|
|
this window. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
info[i].min_size = (m_vertical
|
|
|
|
|
? TUI_CMD_WIN->height
|
|
|
|
|
: TUI_CMD_WIN->width);
|
|
|
|
|
info[i].max_size = info[i].min_size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (info[i].min_size == info[i].max_size)
|
|
|
|
|
available_size -= info[i].min_size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
last_index = i;
|
|
|
|
|
total_weight += m_splits[i].weight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Two adjacent boxed windows will share a border, making a bit
|
2020-02-22 11:48:26 -07:00
|
|
|
|
more size available. */
|
2019-10-07 18:03:02 -06:00
|
|
|
|
if (i > 0
|
|
|
|
|
&& m_splits[i - 1].layout->bottom_boxed_p ()
|
|
|
|
|
&& m_splits[i].layout->top_boxed_p ())
|
|
|
|
|
info[i].share_box = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Step 2: Compute the size of each sub-layout. Fixed-sized items
|
2019-10-07 18:03:02 -06:00
|
|
|
|
are given their fixed size, while others are resized according to
|
|
|
|
|
their weight. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
int used_size = 0;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
{
|
|
|
|
|
/* Compute the height and clamp to the allowable range. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
info[i].size = available_size * m_splits[i].weight / total_weight;
|
|
|
|
|
if (info[i].size > info[i].max_size)
|
|
|
|
|
info[i].size = info[i].max_size;
|
|
|
|
|
if (info[i].size < info[i].min_size)
|
|
|
|
|
info[i].size = info[i].min_size;
|
|
|
|
|
/* If there is any leftover size, just redistribute it to the
|
2019-10-07 18:03:02 -06:00
|
|
|
|
last resizeable window, by dropping it from the allocated
|
2020-02-22 11:48:26 -07:00
|
|
|
|
size. We could try to be fancier here perhaps, by
|
|
|
|
|
redistributing this size among all windows, not just the
|
2019-10-07 18:03:02 -06:00
|
|
|
|
last window. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (info[i].min_size != info[i].max_size)
|
2019-10-07 18:03:02 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
used_size += info[i].size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
if (info[i].share_box)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
--used_size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Allocate any leftover size. */
|
|
|
|
|
if (available_size >= used_size && last_index != -1)
|
|
|
|
|
info[last_index].size += available_size - used_size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
|
|
|
|
/* Step 3: Resize. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
int size_accum = 0;
|
|
|
|
|
const int maximum = m_vertical ? height : width;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
{
|
|
|
|
|
/* If we fall off the bottom, just make allocations overlap.
|
|
|
|
|
GIGO. */
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (size_accum + info[i].size > maximum)
|
|
|
|
|
size_accum = maximum - info[i].size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
else if (info[i].share_box)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
--size_accum;
|
|
|
|
|
if (m_vertical)
|
|
|
|
|
m_splits[i].layout->apply (x, y + size_accum, width, info[i].size);
|
|
|
|
|
else
|
|
|
|
|
m_splits[i].layout->apply (x + size_accum, y, info[i].size, height);
|
|
|
|
|
size_accum += info[i].size;
|
2019-10-07 18:03:02 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_applied = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_split::remove_windows (const char *name)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_splits.size (); ++i)
|
|
|
|
|
{
|
|
|
|
|
const char *this_name = m_splits[i].layout->get_name ();
|
|
|
|
|
if (this_name == nullptr)
|
|
|
|
|
m_splits[i].layout->remove_windows (name);
|
2020-06-16 17:55:57 -06:00
|
|
|
|
else if (strcmp (this_name, name) == 0
|
2020-06-16 17:55:57 -06:00
|
|
|
|
|| strcmp (this_name, CMD_NAME) == 0
|
|
|
|
|
|| strcmp (this_name, STATUS_NAME) == 0)
|
2020-06-16 17:55:57 -06:00
|
|
|
|
{
|
|
|
|
|
/* Keep. */
|
|
|
|
|
}
|
2020-02-22 11:48:26 -07:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_splits.erase (m_splits.begin () + i);
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
tui_layout_split::replace_window (const char *name, const char *new_window)
|
|
|
|
|
{
|
|
|
|
|
for (auto &item : m_splits)
|
|
|
|
|
item.layout->replace_window (name, new_window);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* See tui-layout.h. */
|
|
|
|
|
|
|
|
|
|
void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
tui_layout_split::specification (ui_file *output, int depth)
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (depth > 0)
|
|
|
|
|
fputs_unfiltered ("{", output);
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (!m_vertical)
|
|
|
|
|
fputs_unfiltered ("-horizontal ", output);
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
bool first = true;
|
|
|
|
|
for (auto &item : m_splits)
|
|
|
|
|
{
|
|
|
|
|
if (!first)
|
|
|
|
|
fputs_unfiltered (" ", output);
|
|
|
|
|
first = false;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
item.layout->specification (output, depth + 1);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
fprintf_unfiltered (output, " %d", item.weight);
|
|
|
|
|
}
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
if (depth > 0)
|
|
|
|
|
fputs_unfiltered ("}", output);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Destroy the layout associated with SELF. */
|
|
|
|
|
|
2019-10-09 16:35:41 -06:00
|
|
|
|
static void
|
2020-02-22 11:48:26 -07:00
|
|
|
|
destroy_layout (struct cmd_list_element *self, void *context)
|
|
|
|
|
{
|
|
|
|
|
tui_layout_split *layout = (tui_layout_split *) context;
|
|
|
|
|
size_t index = find_layout (layout);
|
|
|
|
|
layouts.erase (layouts.begin () + index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* List holding the sub-commands of "layout". */
|
|
|
|
|
|
|
|
|
|
static struct cmd_list_element *layout_list;
|
|
|
|
|
|
|
|
|
|
/* Add a "layout" command with name NAME that switches to LAYOUT. */
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
static struct cmd_list_element *
|
2020-02-22 11:48:26 -07:00
|
|
|
|
add_layout_command (const char *name, tui_layout_split *layout)
|
2019-10-09 16:35:41 -06:00
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
struct cmd_list_element *cmd;
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
string_file spec;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
layout->specification (&spec, 0);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
gdb::unique_xmalloc_ptr<char> doc
|
2021-11-08 14:58:46 +00:00
|
|
|
|
= xstrprintf (_("Apply the \"%s\" layout.\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
This layout was created using:\n\
|
|
|
|
|
tui new-layout %s %s"),
|
2021-11-08 14:58:46 +00:00
|
|
|
|
name, name, spec.c_str ());
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
cmd = add_cmd (name, class_tui, nullptr, doc.get (), &layout_list);
|
2021-06-25 21:35:40 -04:00
|
|
|
|
cmd->set_context (layout);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* There is no API to set this. */
|
|
|
|
|
cmd->func = tui_apply_layout;
|
|
|
|
|
cmd->destroyer = destroy_layout;
|
|
|
|
|
cmd->doc_allocated = 1;
|
|
|
|
|
doc.release ();
|
|
|
|
|
layouts.emplace_back (layout);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
return cmd;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* Initialize the standard layouts. */
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
static void
|
|
|
|
|
initialize_layouts ()
|
|
|
|
|
{
|
|
|
|
|
tui_layout_split *layout;
|
|
|
|
|
|
|
|
|
|
layout = new tui_layout_split ();
|
2020-06-16 17:55:57 -06:00
|
|
|
|
layout->add_window (SRC_NAME, 2);
|
|
|
|
|
layout->add_window (STATUS_NAME, 0);
|
|
|
|
|
layout->add_window (CMD_NAME, 1);
|
|
|
|
|
add_layout_command (SRC_NAME, layout);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
layout = new tui_layout_split ();
|
2020-06-16 17:55:57 -06:00
|
|
|
|
layout->add_window (DISASSEM_NAME, 2);
|
|
|
|
|
layout->add_window (STATUS_NAME, 0);
|
|
|
|
|
layout->add_window (CMD_NAME, 1);
|
|
|
|
|
add_layout_command (DISASSEM_NAME, layout);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
layout = new tui_layout_split ();
|
2020-06-16 17:55:57 -06:00
|
|
|
|
layout->add_window (SRC_NAME, 1);
|
|
|
|
|
layout->add_window (DISASSEM_NAME, 1);
|
|
|
|
|
layout->add_window (STATUS_NAME, 0);
|
|
|
|
|
layout->add_window (CMD_NAME, 1);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
add_layout_command ("split", layout);
|
|
|
|
|
|
|
|
|
|
layout = new tui_layout_split ();
|
2020-06-16 17:55:57 -06:00
|
|
|
|
layout->add_window (DATA_NAME, 1);
|
|
|
|
|
layout->add_window (SRC_NAME, 1);
|
|
|
|
|
layout->add_window (STATUS_NAME, 0);
|
|
|
|
|
layout->add_window (CMD_NAME, 1);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
layouts.emplace_back (layout);
|
|
|
|
|
src_regs_layout = layout;
|
|
|
|
|
|
|
|
|
|
layout = new tui_layout_split ();
|
2020-06-16 17:55:57 -06:00
|
|
|
|
layout->add_window (DATA_NAME, 1);
|
|
|
|
|
layout->add_window (DISASSEM_NAME, 1);
|
|
|
|
|
layout->add_window (STATUS_NAME, 0);
|
|
|
|
|
layout->add_window (CMD_NAME, 1);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
layouts.emplace_back (layout);
|
|
|
|
|
asm_regs_layout = layout;
|
2019-10-09 16:35:41 -06:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 18:03:02 -06:00
|
|
|
|
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
/* A helper function that returns true if NAME is the name of an
|
|
|
|
|
available window. */
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
validate_window_name (const std::string &name)
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
auto iter = known_window_types->find (name);
|
|
|
|
|
return iter != known_window_types->end ();
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation of the "tui new-layout" command. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tui_new_layout_command (const char *spec, int from_tty)
|
|
|
|
|
{
|
|
|
|
|
std::string new_name = extract_arg (&spec);
|
|
|
|
|
if (new_name.empty ())
|
|
|
|
|
error (_("No layout name specified"));
|
|
|
|
|
if (new_name[0] == '-')
|
|
|
|
|
error (_("Layout name cannot start with '-'"));
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
bool is_vertical = true;
|
|
|
|
|
spec = skip_spaces (spec);
|
|
|
|
|
if (check_for_argument (&spec, "-horizontal"))
|
|
|
|
|
is_vertical = false;
|
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
std::vector<std::unique_ptr<tui_layout_split>> splits;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
splits.emplace_back (new tui_layout_split (is_vertical));
|
2020-02-22 11:48:26 -07:00
|
|
|
|
std::unordered_set<std::string> seen_windows;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
spec = skip_spaces (spec);
|
|
|
|
|
if (spec[0] == '\0')
|
2020-02-22 11:48:26 -07:00
|
|
|
|
break;
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
if (spec[0] == '{')
|
|
|
|
|
{
|
2020-02-22 11:48:26 -07:00
|
|
|
|
is_vertical = true;
|
|
|
|
|
spec = skip_spaces (spec + 1);
|
|
|
|
|
if (check_for_argument (&spec, "-horizontal"))
|
|
|
|
|
is_vertical = false;
|
|
|
|
|
splits.emplace_back (new tui_layout_split (is_vertical));
|
2020-02-22 11:48:26 -07:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_close = false;
|
|
|
|
|
std::string name;
|
|
|
|
|
if (spec[0] == '}')
|
|
|
|
|
{
|
|
|
|
|
is_close = true;
|
|
|
|
|
++spec;
|
|
|
|
|
if (splits.size () == 1)
|
|
|
|
|
error (_("Extra '}' in layout specification"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
name = extract_arg (&spec);
|
|
|
|
|
if (name.empty ())
|
|
|
|
|
break;
|
|
|
|
|
if (!validate_window_name (name))
|
|
|
|
|
error (_("Unknown window \"%s\""), name.c_str ());
|
|
|
|
|
if (seen_windows.find (name) != seen_windows.end ())
|
|
|
|
|
error (_("Window \"%s\" seen twice in layout"), name.c_str ());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ULONGEST weight = get_ulongest (&spec, '}');
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if ((int) weight != weight)
|
|
|
|
|
error (_("Weight out of range: %s"), pulongest (weight));
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (is_close)
|
|
|
|
|
{
|
|
|
|
|
std::unique_ptr<tui_layout_split> last_split
|
|
|
|
|
= std::move (splits.back ());
|
|
|
|
|
splits.pop_back ();
|
|
|
|
|
splits.back ()->add_split (std::move (last_split), weight);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
splits.back ()->add_window (name.c_str (), weight);
|
|
|
|
|
seen_windows.insert (name);
|
|
|
|
|
}
|
2020-02-22 11:48:26 -07:00
|
|
|
|
}
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (splits.size () > 1)
|
|
|
|
|
error (_("Missing '}' in layout specification"));
|
2020-02-22 11:48:26 -07:00
|
|
|
|
if (seen_windows.empty ())
|
|
|
|
|
error (_("New layout does not contain any windows"));
|
2020-06-16 17:55:57 -06:00
|
|
|
|
if (seen_windows.find (CMD_NAME) == seen_windows.end ())
|
|
|
|
|
error (_("New layout does not contain the \"" CMD_NAME "\" window"));
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
gdb::unique_xmalloc_ptr<char> cmd_name
|
|
|
|
|
= make_unique_xstrdup (new_name.c_str ());
|
2020-02-22 11:48:26 -07:00
|
|
|
|
std::unique_ptr<tui_layout_split> new_layout = std::move (splits.back ());
|
2020-02-22 11:48:26 -07:00
|
|
|
|
struct cmd_list_element *cmd
|
|
|
|
|
= add_layout_command (cmd_name.get (), new_layout.get ());
|
|
|
|
|
cmd->name_allocated = 1;
|
|
|
|
|
cmd_name.release ();
|
|
|
|
|
new_layout.release ();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 15:44:18 -06:00
|
|
|
|
/* Function to initialize gdb commands, for tui window layout
|
|
|
|
|
manipulation. */
|
|
|
|
|
|
2020-01-13 14:01:38 -05:00
|
|
|
|
void _initialize_tui_layout ();
|
2019-10-08 15:44:18 -06:00
|
|
|
|
void
|
2020-01-13 14:01:38 -05:00
|
|
|
|
_initialize_tui_layout ()
|
2019-10-08 15:44:18 -06:00
|
|
|
|
{
|
Replace most calls to help_list and cmd_show_list
Currently there are many prefix commands that do nothing but call
either help_list or cmd_show_list. I happened to notice that one such
call, for "set print type", used the wrong command list parameter,
causing incorrect output.
Rather than fix this bug in isolation, I decided to eliminate this
possibility by adding two new ways to add prefix commands, which
simply route the call to help_list or cmd_show_list, as appropriate.
This makes it impossible for a mismatch to occur.
In some cases, a bit of output was removed; however, I don't think
this output in general was very useful. It seemed redundant with
what's already printed by help_list. A representative example is this
hunk, removed from ada-lang.c:
- printf_unfiltered (_(\
-"\"set ada\" must be followed by the name of a setting.\n"));
This simplified the CLI style set/show commands quite a bit, and
allowed the deletion of a macro.
This also cleans up some unusual code in windows-tdep.c.
Tested on x86-64 Fedora 30. Note that I have no way to build the
go32-nat.c change.
gdb/ChangeLog
2020-04-17 Tom Tromey <tromey@adacore.com>
* auto-load.c (show_auto_load_cmd): Remove.
(auto_load_show_cmdlist_get): Use add_show_prefix_cmd.
* arc-tdep.c (_initialize_arc_tdep): Use add_show_prefix_cmd.
(maintenance_print_arc_command): Remove.
* tui/tui-win.c (tui_command): Remove.
(tui_get_cmd_list): Use add_basic_prefix_cmd.
* tui/tui-layout.c (tui_layout_command): Remove.
(_initialize_tui_layout): Use add_basic_prefix_cmd.
* python/python.c (user_set_python, user_show_python): Remove.
(_initialize_python): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* guile/guile.c (set_guile_command, show_guile_command): Remove.
(install_gdb_commands): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
(info_guile_command): Remove.
* dwarf2/read.c (set_dwarf_cmd, show_dwarf_cmd): Remove.
(_initialize_dwarf2_read): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* cli/cli-style.h (class cli_style_option) <add_setshow_commands>:
Remove do_set and do_show parameters.
* cli/cli-style.c (set_style, show_style): Remove.
(_initialize_cli_style): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
(cli_style_option::add_setshow_commands): Remove do_set and
do_show parameters.
(cli_style_option::add_setshow_commands): Use
add_basic_prefix_cmd, add_show_prefix_cmd.
(STYLE_ADD_SETSHOW_COMMANDS): Remove macro.
(set_style_name): Remove.
* cli/cli-dump.c (dump_command, append_command): Remove.
(srec_dump_command, ihex_dump_command, verilog_dump_command)
(tekhex_dump_command, binary_dump_command)
(binary_append_command): Remove.
(_initialize_cli_dump): Use add_basic_prefix_cmd.
* windows-tdep.c (w32_prefix_command_valid): Remove global.
(init_w32_command_list): Remove; move into ...
(_initialize_windows_tdep): ... here. Use add_basic_prefix_cmd.
* valprint.c (set_print, show_print, set_print_raw)
(show_print_raw): Remove.
(_initialize_valprint): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* typeprint.c (set_print_type, show_print_type): Remove.
(_initialize_typeprint): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* record.c (set_record_command, show_record_command): Remove.
(_initialize_record): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* cli/cli-cmds.c (_initialize_cli_cmds): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
(info_command, show_command, set_debug, show_debug): Remove.
* top.h (set_history, show_history): Don't declare.
* top.c (set_history, show_history): Remove.
* target-descriptions.c (set_tdesc_cmd, show_tdesc_cmd)
(unset_tdesc_cmd): Remove.
(_initialize_target_descriptions): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* symtab.c (info_module_command): Remove.
(_initialize_symtab): Use add_basic_prefix_cmd.
* symfile.c (overlay_command): Remove.
(_initialize_symfile): Use add_basic_prefix_cmd.
* sparc64-tdep.c (info_adi_command): Remove.
(_initialize_sparc64_adi_tdep): Use add_basic_prefix_cmd.
* sh-tdep.c (show_sh_command, set_sh_command): Remove.
(_initialize_sh_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* serial.c (serial_set_cmd, serial_show_cmd): Remove.
(_initialize_serial): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Remove.
(_initialize_ser_tcp): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* rs6000-tdep.c (set_powerpc_command, show_powerpc_command)
(_initialize_rs6000_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* riscv-tdep.c (show_riscv_command, set_riscv_command)
(show_debug_riscv_command, set_debug_riscv_command): Remove.
(_initialize_riscv_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* remote.c (remote_command, set_remote_cmd): Remove.
(_initialize_remote): Use add_basic_prefix_cmd.
* record-full.c (set_record_full_command)
(show_record_full_command): Remove.
(_initialize_record_full): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* record-btrace.c (cmd_set_record_btrace)
(cmd_show_record_btrace, cmd_set_record_btrace_bts)
(cmd_show_record_btrace_bts, cmd_set_record_btrace_pt)
(cmd_show_record_btrace_pt): Remove.
(_initialize_record_btrace): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* ravenscar-thread.c (set_ravenscar_command)
(show_ravenscar_command): Remove.
(_initialize_ravenscar): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* mips-tdep.c (show_mips_command, set_mips_command)
(_initialize_mips_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* maint.c (maintenance_command, maintenance_info_command)
(maintenance_check_command, maintenance_print_command)
(maintenance_set_cmd, maintenance_show_cmd): Remove.
(_initialize_maint_cmds): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
(show_per_command_cmd): Remove.
* maint-test-settings.c (maintenance_set_test_settings_cmd):
Remove.
(maintenance_show_test_settings_cmd): Remove.
(_initialize_maint_test_settings): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* maint-test-options.c (maintenance_test_options_command):
Remove.
(_initialize_maint_test_options): Use add_basic_prefix_cmd.
* macrocmd.c (macro_command): Remove
(_initialize_macrocmd): Use add_basic_prefix_cmd.
* language.c (set_check, show_check): Remove.
(_initialize_language): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* infcmd.c (unset_command): Remove.
(_initialize_infcmd): Use add_basic_prefix_cmd.
* i386-tdep.c (set_mpx_cmd, show_mpx_cmd): Remove.
(_initialize_i386_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* go32-nat.c (go32_info_dos_command): Remove.
(_initialize_go32_nat): Use add_basic_prefix_cmd.
* cli/cli-decode.c (do_prefix_cmd, add_basic_prefix_cmd)
(do_show_prefix_cmd, add_show_prefix_cmd): New functions.
* frame.c (set_backtrace_cmd, show_backtrace_cmd): Remove.
(_initialize_frame): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* dcache.c (set_dcache_command, show_dcache_command): Remove.
(_initialize_dcache): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* cp-support.c (maint_cplus_command): Remove.
(_initialize_cp_support): Use add_basic_prefix_cmd.
* btrace.c (maint_btrace_cmd, maint_btrace_set_cmd)
(maint_btrace_show_cmd, maint_btrace_pt_set_cmd)
(maint_btrace_pt_show_cmd, _initialize_btrace): Use
add_basic_prefix_cmd, add_show_prefix_cmd.
* breakpoint.c (save_command): Remove.
(_initialize_breakpoint): Use add_basic_prefix_cmd.
* arm-tdep.c (set_arm_command, show_arm_command): Remove.
(_initialize_arm_tdep): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* ada-lang.c (maint_set_ada_cmd, maint_show_ada_cmd)
(set_ada_command, show_ada_command): Remove.
(_initialize_ada_language): Use add_basic_prefix_cmd,
add_show_prefix_cmd.
* command.h (add_basic_prefix_cmd, add_show_prefix_cmd): Declare.
gdb/testsuite/ChangeLog
2020-04-17 Tom Tromey <tromey@adacore.com>
* gdb.cp/maint.exp (test_help): Simplify multiple_help_body.
Update tests.
* gdb.btrace/cpu.exp: Update tests.
* gdb.base/maint.exp: Update tests.
* gdb.base/default.exp: Update tests.
* gdb.base/completion.exp: Update tests.
2020-04-17 07:27:14 -06:00
|
|
|
|
add_basic_prefix_cmd ("layout", class_tui, _("\
|
2019-10-08 15:44:18 -06:00
|
|
|
|
Change the layout of windows.\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
Usage: layout prev | next | LAYOUT-NAME"),
|
2021-05-12 11:19:22 +01:00
|
|
|
|
&layout_list, 0, &cmdlist);
|
2020-02-22 11:48:26 -07:00
|
|
|
|
|
|
|
|
|
add_cmd ("next", class_tui, tui_next_layout_command,
|
2020-02-24 12:30:48 +01:00
|
|
|
|
_("Apply the next TUI layout."),
|
2020-02-22 11:48:26 -07:00
|
|
|
|
&layout_list);
|
|
|
|
|
add_cmd ("prev", class_tui, tui_prev_layout_command,
|
2020-02-24 12:30:48 +01:00
|
|
|
|
_("Apply the previous TUI layout."),
|
2020-02-22 11:48:26 -07:00
|
|
|
|
&layout_list);
|
|
|
|
|
add_cmd ("regs", class_tui, tui_regs_layout_command,
|
2020-02-24 12:30:48 +01:00
|
|
|
|
_("Apply the TUI register layout."),
|
2020-02-22 11:48:26 -07:00
|
|
|
|
&layout_list);
|
2019-10-09 16:35:41 -06:00
|
|
|
|
|
2020-02-22 11:48:26 -07:00
|
|
|
|
add_cmd ("new-layout", class_tui, tui_new_layout_command,
|
|
|
|
|
_("Create a new TUI layout.\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
Usage: tui new-layout [-horizontal] NAME WINDOW WEIGHT [WINDOW WEIGHT]...\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
Create a new TUI layout. The new layout will be named NAME,\n\
|
|
|
|
|
and can be accessed using \"layout NAME\".\n\
|
|
|
|
|
The windows will be displayed in the specified order.\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
A WINDOW can also be of the form:\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
{ [-horizontal] NAME WEIGHT [NAME WEIGHT]... }\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
This form indicates a sub-frame.\n\
|
2020-02-22 11:48:26 -07:00
|
|
|
|
Each WEIGHT is an integer, which holds the relative size\n\
|
|
|
|
|
to be allocated to the window."),
|
|
|
|
|
tui_get_cmd_list ());
|
|
|
|
|
|
2019-10-09 16:35:41 -06:00
|
|
|
|
initialize_layouts ();
|
2020-02-22 11:48:26 -07:00
|
|
|
|
initialize_known_windows ();
|
2019-10-08 15:44:18 -06:00
|
|
|
|
}
|