From 01b1af321f804ef6dfd40d3054c8757f31096ea8 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 22 Feb 2020 11:48:26 -0700 Subject: Allow TUI windows in Python This patch adds support for writing new TUI windows in Python. 2020-02-22 Tom Tromey * NEWS: Add entry for gdb.register_window_type. * tui/tui-layout.h (window_factory): New typedef. (tui_register_window): Declare. * tui/tui-layout.c (saved_tui_windows): New global. (tui_apply_current_layout): Use it. (tui_register_window): New function. * python/python.c (do_start_initialization): Call gdbpy_initialize_tui. (python_GdbMethods): Add "register_window_type" function. * python/python-internal.h (gdbpy_register_tui_window) (gdbpy_initialize_tui): Declare. * python/py-tui.c: New file. * Makefile.in (SUBDIR_PYTHON_SRCS): Add py-tui.c. gdb/doc/ChangeLog 2020-02-22 Tom Tromey * python.texi (Python API): Add menu item. (TUI Windows In Python): New node. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey * gdb.python/tui-window.exp: New file. * gdb.python/tui-window.py: New file. Change-Id: I85fbfb923a1840450a00a7dce113a05d7f048baa --- gdb/tui/tui-layout.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'gdb/tui/tui-layout.c') diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 748a106..66c7449 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -65,6 +65,11 @@ static tui_layout_split *asm_regs_layout; /* See tui-data.h. */ std::vector tui_windows; +/* When applying a layout, this is the list of all windows that were + in the previous layout. This is used to re-use windows when + changing a layout. */ +static std::vector saved_tui_windows; + /* See tui-layout.h. */ void @@ -75,10 +80,10 @@ tui_apply_current_layout () extract_display_start_addr (&gdbarch, &addr); - std::vector saved_windows = std::move (tui_windows); + saved_tui_windows = std::move (tui_windows); tui_windows.clear (); - for (tui_win_info *win_info : saved_windows) + for (tui_win_info *win_info : saved_tui_windows) win_info->make_visible (false); applied_layout->apply (0, 0, tui_term_width (), tui_term_height ()); @@ -94,7 +99,7 @@ tui_apply_current_layout () /* Now delete any window that was not re-applied. */ tui_win_info *focus = tui_win_with_focus (); - for (tui_win_info *win_info : saved_windows) + for (tui_win_info *win_info : saved_tui_windows) { if (!win_info->is_visible ()) { @@ -107,6 +112,8 @@ tui_apply_current_layout () if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr) tui_get_begin_asm_address (&gdbarch, &addr); tui_update_source_windows_with_addr (gdbarch, addr); + + saved_tui_windows.clear (); } /* See tui-layout. */ @@ -395,6 +402,21 @@ initialize_known_windows () /* See tui-layout.h. */ +void +tui_register_window (const char *name, window_factory &&factory) +{ + std::string name_copy = name; + + if (name_copy == "src" || name_copy == "cmd" || name_copy == "regs" + || name_copy == "asm" || name_copy == "status") + error (_("Window type \"%s\" is built-in"), name); + + known_window_types->emplace (std::move (name_copy), + std::move (factory)); +} + +/* See tui-layout.h. */ + std::unique_ptr tui_layout_window::clone () const { -- cgit v1.1