[3/3] Have TUI react to disassembly parameter changes
Commit Message
With this patch, changes to "print symbol-filename",
"filename-display", or "print max-symbolic-offset" will now cause the
TUI disassembly window to update.
tui_source_window_base::style_changed is renamed to reflect its use as
a way to force a refresh.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33249
---
gdb/testsuite/gdb.tui/tui-disasm-styling.exp | 23 +++++++++++++++++++++++
gdb/tui/tui-disasm.c | 23 +++++++++++++++++++++++
gdb/tui/tui-disasm.h | 10 +++++++++-
gdb/tui/tui-source.c | 2 +-
gdb/tui/tui-winsource.c | 4 ++--
gdb/tui/tui-winsource.h | 5 +++--
6 files changed, 61 insertions(+), 6 deletions(-)
@@ -66,3 +66,26 @@ check_asm_output true "asm output is styled once again"
Term::command "set style sources off"
check_asm_output true "asm output is styled when source styling is off"
+
+Term::command "set print max-symbolic-offset 1"
+set asm_output [Term::get_region 1 1 78 13 "\n"]
+# Look for a line that has a hex offset and some assembly, but that
+# does not have <main...>. We can't really check for the assembly
+# directly so we just look for any letter.
+gdb_assert {[regexp -- "$hex\[^<\]* \[a-z\]" $asm_output]} \
+ "reacted to change to max-symbolic-offset"
+
+# These next tests are a bit simpler to write without styling.
+Term::command "set style enabled off"
+Term::command "set filename-display absolute"
+Term::command "set print symbol-filename on"
+set asm_output [Term::get_region 1 1 78 13 "\n"]
+# We can't assume the final part of the filename will be visible, so
+# just look for any directory separator.
+gdb_assert {[regexp -- "<main at \[/\\\\]" $asm_output]} \
+ "reacted to change to symbol-filename"
+
+Term::command "set filename-display basename"
+set asm_output [Term::get_region 1 1 78 13 "\n"]
+gdb_assert {[regexp -- "<main at tui-layout\\.c" $asm_output]} \
+ "reacted to change to filename-display"
@@ -38,6 +38,7 @@
#include "tui/tui-location.h"
#include "gdbsupport/selftest.h"
#include "inferior.h"
+#include "observable.h"
struct tui_asm_line
{
@@ -526,6 +527,28 @@ tui_disasm_window::display_start_addr (struct gdbarch **gdbarch_p,
*addr_p = m_start_line_or_addr.u.addr;
}
+void
+tui_disasm_window::param_changed (const char *name, const char *value)
+{
+ if (strcmp (name, "print max-symbolic-offset") == 0
+ || strcmp (name, "print symbol-filename") == 0
+ || strcmp (name, "filename-display") == 0)
+ re_render ();
+}
+
+tui_disasm_window::tui_disasm_window ()
+{
+ using namespace std::placeholders;
+ gdb::observers::parameter_changed.attach
+ (std::bind (&tui_disasm_window::param_changed, this, _1, _2),
+ m_dis_observable, "tui-disasm");
+}
+
+tui_disasm_window::~tui_disasm_window ()
+{
+ gdb::observers::parameter_changed.detach (m_dis_observable);
+}
+
#if GDB_SELF_TEST
namespace selftests {
namespace tui {
@@ -31,7 +31,8 @@
struct tui_disasm_window : public tui_source_window_base
{
- tui_disasm_window () = default;
+ tui_disasm_window ();
+ ~tui_disasm_window ();
DISABLE_COPY_AND_ASSIGN (tui_disasm_window);
@@ -60,9 +61,16 @@ struct tui_disasm_window : public tui_source_window_base
const struct symtab_and_line &sal) override;
private:
+ /* Observer for the parameter changed event. This updates the
+ contents in response to certain parameter changes. */
+ void param_changed (const char *name, const char *value);
+
/* Answer whether a particular line number or address is displayed
in the current source window. */
bool addr_is_displayed (CORE_ADDR addr) const;
+
+ /* A token used to register and unregister an observer. */
+ gdb::observers::token m_dis_observable;
};
/* Return the instance of the disassembly windows. */
@@ -38,7 +38,7 @@
tui_source_window::tui_source_window ()
{
line_number_style.changed.attach
- (std::bind (&tui_source_window::style_changed, this),
+ (std::bind (&tui_source_window::re_render, this),
m_src_observable, "tui-source");
}
@@ -136,7 +136,7 @@ tui_copy_source_line (const char **ptr, int *length)
}
void
-tui_source_window_base::style_changed ()
+tui_source_window_base::re_render ()
{
if (tui_active && is_visible ())
refill ();
@@ -419,7 +419,7 @@ tui_source_window_base::tui_source_window_base ()
m_start_line_or_addr.u.addr = 0;
gdb::observers::styling_changed.attach
- (std::bind (&tui_source_window::style_changed, this),
+ (std::bind (&tui_source_window::re_render, this),
m_observable, "tui-winsource");
}
@@ -191,8 +191,9 @@ struct tui_source_window_base : public tui_win_info
protected:
- /* Called when a user style setting is changed. */
- void style_changed ();
+ /* Re-render the window from scratch. This is called in response to
+ a style change or similar event. */
+ void re_render ();
private: