aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-02-22 11:48:26 -0700
committerTom Tromey <tom@tromey.com>2020-02-22 12:57:25 -0700
commit01b1af321f804ef6dfd40d3054c8757f31096ea8 (patch)
tree03c14bda00b71bb7322ff5d2bfc3e2355b37e932 /gdb/tui
parentfc96d20b2c6d7ff24349ad015119438077d3f1e9 (diff)
downloadgdb-01b1af321f804ef6dfd40d3054c8757f31096ea8.zip
gdb-01b1af321f804ef6dfd40d3054c8757f31096ea8.tar.gz
gdb-01b1af321f804ef6dfd40d3054c8757f31096ea8.tar.bz2
Allow TUI windows in Python
This patch adds support for writing new TUI windows in Python. 2020-02-22 Tom Tromey <tom@tromey.com> * 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 <tom@tromey.com> * python.texi (Python API): Add menu item. (TUI Windows In Python): New node. gdb/testsuite/ChangeLog 2020-02-22 Tom Tromey <tom@tromey.com> * gdb.python/tui-window.exp: New file. * gdb.python/tui-window.py: New file. Change-Id: I85fbfb923a1840450a00a7dce113a05d7f048baa
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-layout.c28
-rw-r--r--gdb/tui/tui-layout.h10
2 files changed, 35 insertions, 3 deletions
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_win_info *> 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<tui_win_info *> saved_tui_windows;
+
/* See tui-layout.h. */
void
@@ -75,10 +80,10 @@ tui_apply_current_layout ()
extract_display_start_addr (&gdbarch, &addr);
- std::vector<tui_win_info *> 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_base>
tui_layout_window::clone () const
{
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index 6607e8d..9061837 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -249,4 +249,14 @@ extern void tui_apply_current_layout ();
extern void tui_adjust_window_height (struct tui_win_info *win,
int new_height);
+/* The type of a function that is used to create a TUI window. */
+
+typedef std::function<tui_gen_win_info * (const char *name)> window_factory;
+
+/* Register a new TUI window type. NAME is the name of the window
+ type. FACTORY is a function that can be called to instantiate the
+ window. */
+
+extern void tui_register_window (const char *name, window_factory &&factory);
+
#endif /* TUI_TUI_LAYOUT_H */