]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Update TUI register window when the inferior exits
authorTom Tromey <tom@tromey.com>
Sun, 17 Dec 2023 19:38:15 +0000 (12:38 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 8 Feb 2024 19:16:07 +0000 (12:16 -0700)
When the inferior exits, the TUI register window should clear.

Fixing this was mostly a matter of sticking an assignment into
tui_inferior_exit.  However, some changes to the register window
itself were also needed.

While working on this, I realized that the TUI register window would
not work correctly when moving between frames of different
architectures.  This patch attempts to fix this as well, though I have
no way to test it.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28600
Tested-By: Tom de Vries <tdevries@suse.de>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/testsuite/gdb.tui/regs.exp
gdb/tui/tui-hooks.c
gdb/tui/tui-regs.c
gdb/tui/tui-regs.h

index c325952185f1ef06701602031d10fb94f85e6b9b..ea78b57d1a72c103907a7a8199b49de40af184e2 100644 (file)
@@ -30,6 +30,9 @@ if {![runto_main]} {
     return
 }
 
+# This is convenient later on.
+gdb_test_no_output "set confirm off"
+
 if {![Term::enter_tui]} {
     unsupported "TUI not supported"
     return
@@ -48,6 +51,11 @@ gdb_assert \
     { ![Term::check_region_contents_p 0 0 80 8 $re_reg_vals_unavailable] } \
     "Register values available"
 
+Term::command "kill"
+gdb_assert \
+    { [Term::check_region_contents_p 0 0 80 8 $re_reg_vals_unavailable] } \
+    "Register values no longer available"
+
 # Check that we can successfully cause the register window to appear
 # using the 'tui reg next' and 'tui reg prev' commands.
 foreach_with_prefix cmd { next prev } {
index fc7ffb4f202e6ef3d44e932ea6e67dbe2cc4ee73..28d0b742ed7607e32a7fb4fa1b8e2d27a6ebeb0c 100644 (file)
@@ -126,19 +126,23 @@ tui_refresh_frame_and_register_information ()
   target_terminal::scoped_restore_terminal_state term_state;
   target_terminal::ours_for_output ();
 
-  if (from_stack && has_stack_frames ())
+  if (from_stack)
     {
-      frame_info_ptr fi = get_selected_frame (NULL);
+      frame_info_ptr fi;
+      if (has_stack_frames ())
+       {
+         fi = get_selected_frame (NULL);
 
-      /* Display the frame position (even if there is no symbols or
-        the PC is not known).  */
-      tui_show_frame_info (fi);
+         /* Display the frame position (even if there is no symbols or
+            the PC is not known).  */
+         tui_show_frame_info (fi);
+       }
 
       /* Refresh the register window if it's visible.  */
       if (tui_is_window_visible (DATA_WIN))
        TUI_DATA_WIN->check_register_values (fi);
     }
-  else if (!from_stack)
+  else
     {
       /* Make sure that the source window is displayed.  */
       tui_add_win_to_layout (SRC_WIN);
@@ -169,6 +173,7 @@ tui_inferior_exit (struct inferior *inf)
   tui_set_key_mode (TUI_COMMAND_MODE);
   tui_show_frame_info (0);
   tui_display_main ();
+  from_stack = true;
 }
 
 /* Observer for the before_prompt notification.  */
index fa4d10d1039f06a4eef215caf0ec6e0a8e6b9a72..504aed4b81f90fca34acde97e617827948e10628 100644 (file)
@@ -107,12 +107,9 @@ tui_register_format (frame_info_ptr frame, int regnum)
 void
 tui_register_info::update (const frame_info_ptr &frame)
 {
-  if (target_has_registers ())
-    {
-      std::string new_content = tui_register_format (frame, m_regno);
-      highlight = content != new_content;
-      content = std::move (new_content);
-    }
+  std::string new_content = tui_register_format (frame, m_regno);
+  highlight = content != new_content;
+  content = std::move (new_content);
 }
 
 /* See tui-regs.h.  */
@@ -185,13 +182,22 @@ tui_data_window::update_register_data (const reggroup *group)
     {
       set_title (_("Registers"));
       m_current_group = nullptr;
+      m_gdbarch = nullptr;
       m_regs_content.clear ();
       return;
     }
 
   frame_info_ptr frame = get_selected_frame (nullptr);
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+
+  if (m_current_group == group && m_gdbarch == gdbarch)
+    {
+      /* Nothing to do here.  */
+      return;
+    }
 
   m_current_group = group;
+  m_gdbarch = gdbarch;
 
   /* Make a new title showing which group we display.  */
   this->set_title (string_printf ("Register group: %s", group->name ()));
@@ -199,7 +205,6 @@ tui_data_window::update_register_data (const reggroup *group)
   /* Create the registers.  */
   m_regs_content.clear ();
 
-  struct gdbarch *gdbarch = get_frame_arch (frame);
   for (int regnum = 0;
        regnum < gdbarch_num_cooked_regs (gdbarch);
        regnum++)
@@ -403,24 +408,31 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
 void
 tui_data_window::check_register_values (frame_info_ptr frame)
 {
-  if (m_regs_content.empty ())
-    set_register_group (m_current_group);
+  if (frame == nullptr)
+    set_register_group (nullptr);
   else
     {
-      for (tui_register_info &data_item_win : m_regs_content)
+      /* If the frame architecture changed, we need to reset the
+        register group.  */
+      struct gdbarch *gdbarch = get_frame_arch (frame);
+      if (gdbarch != m_gdbarch)
+       set_register_group (nullptr);
+      else
        {
-         bool was_hilighted = data_item_win.highlight;
+         for (tui_register_info &data_item_win : m_regs_content)
+           {
+             bool was_hilighted = data_item_win.highlight;
 
-         data_item_win.update (frame);
+             data_item_win.update (frame);
 
-         /* Register windows whose y == 0 are outside the visible area.  */
-         if ((data_item_win.highlight || was_hilighted)
-             && data_item_win.visible ())
-           data_item_win.rerender (handle.get (), m_item_width);
+             /* Register windows whose y == 0 are outside the visible area.  */
+             if ((data_item_win.highlight || was_hilighted)
+                 && data_item_win.visible ())
+               data_item_win.rerender (handle.get (), m_item_width);
+           }
        }
+      tui_wrefresh (handle.get ());
     }
-
-  tui_wrefresh (handle.get ());
 }
 
 /* Display a register in a window.  If hilite is TRUE, then the value
index caa9d395becebe0f230ae4cd2641ca655beacefa..9d9cae40fe07a51b7939100e713bf4397b18d090 100644 (file)
@@ -139,6 +139,10 @@ private:
 
   /* Width of each register's display area.  */
   int m_item_width = 0;
+
+  /* Architecture of frame whose registers are being displayed, or
+     nullptr if the display is empty (i.e., there is no frame).  */
+  gdbarch *m_gdbarch = nullptr;
 };
 
 #endif /* TUI_TUI_REGS_H */