]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/tui] Fix displaying main after resizing
authorTom de Vries <tdevries@suse.de>
Fri, 8 Dec 2023 16:36:35 +0000 (17:36 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 8 Dec 2023 16:36:35 +0000 (17:36 +0100)
A TUI src window is displaying either:
- the source for the current frame,
- the source for main, or
- the string "[ No Source Available ]".

Since commit 03893ce67b5 ("[gdb/tui] Fix resizing of terminal to 1 or 2 lines")
we're able to resize the TUI to 1 line without crashing.

I noticed that if TUI is displaying main, and we resize to 1 line (destroying
the src window) and then back to a larger terminal (reconstructing the src
window), the TUI displays "[ No Source Available ]" instead of main.

Fix this by moving the responsibility for showing main from tui_enable to
tui_source_window_base::rerender.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.tui/resize-one-line.exp [new file with mode: 0644]
gdb/tui/tui-layout.c
gdb/tui/tui-winsource.c
gdb/tui/tui-winsource.h
gdb/tui/tui.c

diff --git a/gdb/testsuite/gdb.tui/resize-one-line.exp b/gdb/testsuite/gdb.tui/resize-one-line.exp
new file mode 100644 (file)
index 0000000..5f8847c
--- /dev/null
@@ -0,0 +1,50 @@
+# Copyright 2023 Free Software Foundation, Inc.
+
+# 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
+# the Free Software Foundation; either version 3 of the License, or
+# (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
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that when showing main (because of lack of current frame) in the src
+# window, resizing to 1 line and back doesn't change the contents of the src
+# window.
+
+tuiterm_env
+
+standard_testfile main-one-line.c
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
+    return -1
+}
+
+Term::clean_restart 24 80 $testfile
+
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+# Check that we have a source box containing main.
+Term::check_box "source box" 0 0 80 15
+Term::check_region_contents "src window shows main" 0 0 80 15 "main"
+
+# Resize to a single line.
+Term::resize 1 80 0
+Term::wait_for ""
+
+# Resize back to the previous size.
+Term::resize 24 80 0
+
+# Check that we still have a source box containing main.
+with_test_prefix "after resizing" {
+    gdb_assert { [Term::wait_for_region_contents  0 0 80 15 "main"] } \
+       "src window shows main"
+}
index 85f4991c769d5c93f401873160d94f4cd8b4fe2f..a4cb5a8b7bf6ccd51ef70ade0964d3f24fdbcbc6 100644 (file)
@@ -45,8 +45,6 @@
 #include "gdb_curses.h"
 #include "gdbsupport/gdb-safe-ctype.h"
 
-static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
-
 /* The layouts.  */
 static std::vector<std::unique_ptr<tui_layout_split>> layouts;
 
@@ -69,11 +67,6 @@ std::vector<tui_win_info *> tui_windows;
 void
 tui_apply_current_layout (bool preserve_cmd_win_size_p)
 {
-  struct gdbarch *gdbarch;
-  CORE_ADDR addr;
-
-  extract_display_start_addr (&gdbarch, &addr);
-
   for (tui_win_info *win_info : tui_windows)
     win_info->make_visible (false);
 
@@ -108,10 +101,6 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p)
 
   /* Replace the global list of active windows.  */
   tui_windows = std::move (new_tui_windows);
-
-  if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr)
-    tui_get_begin_asm_address (&gdbarch, &addr);
-  tui_update_source_windows_with_addr (gdbarch, addr);
 }
 
 /* See tui-layout.  */
@@ -284,20 +273,6 @@ tui_remove_some_windows ()
   tui_apply_current_layout (true);
 }
 
-static void
-extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
-{
-  if (TUI_SRC_WIN != nullptr)
-    TUI_SRC_WIN->display_start_addr (gdbarch_p, addr_p);
-  else if (TUI_DISASM_WIN != nullptr)
-    TUI_DISASM_WIN->display_start_addr (gdbarch_p, addr_p);
-  else
-    {
-      *gdbarch_p = nullptr;
-      *addr_p = 0;
-    }
-}
-
 void
 tui_win_info::resize (int height_, int width_,
                      int origin_x_, int origin_y_)
index acbaef95e0c175a2893a2e6880a221223d747132..52c0b5b69a4d41e23c297f71b98187c2cbd2aa06 100644 (file)
@@ -178,6 +178,18 @@ tui_source_window_base::update_source_window_as_is
 }
 
 
+/* See tui-winsource.h.  */
+void
+tui_source_window_base::update_source_window_with_addr (struct gdbarch *gdbarch,
+                                                       CORE_ADDR addr)
+{
+  struct symtab_and_line sal {};
+  if (addr != 0)
+    sal = find_pc_line (addr, 0);
+
+  update_source_window (gdbarch, sal);
+}
+
 /* Function to ensure that the source and/or disassembly windows
    reflect the input address.  */
 void
@@ -473,7 +485,15 @@ tui_source_window_base::rerender ()
       update_source_window (gdbarch, cursal);
     }
   else
-    erase_source_content ();
+    {
+      CORE_ADDR addr;
+      struct gdbarch *gdbarch;
+      tui_get_begin_asm_address (&gdbarch, &addr);
+      if (addr == 0)
+       erase_source_content ();
+      else
+       update_source_window_with_addr (gdbarch, addr);
+    }
 }
 
 /* See tui-data.h.  */
index c2826165a10c35ecee63a3746341f5cc1aa657b8..523d0ea832b362736a78464feba3bef8477dfe90 100644 (file)
@@ -183,6 +183,11 @@ public:
   virtual void display_start_addr (struct gdbarch **gdbarch_p,
                                   CORE_ADDR *addr_p) = 0;
 
+  /* Function to ensure that the source or disassembly window
+     reflects the input address.  Single window variant of
+     update_source_windows_with_addr.  */
+  void update_source_window_with_addr (struct gdbarch *, CORE_ADDR);
+
 private:
 
   /* Used for horizontal scroll.  */
index 941c65c970f32d323e49886bea0c8e760517b559..33aced2e7e3301d2a44edc48e6b28e750275c7ef 100644 (file)
@@ -493,11 +493,6 @@ tui_enable (void)
       tui_resize_all ();
     }
 
-  if (deprecated_safe_get_selected_frame ())
-    tui_show_frame_info (deprecated_safe_get_selected_frame ());
-  else
-    tui_display_main ();
-
   /* Install the TUI specific hooks.  This must be done after the call to
      tui_display_main so that we don't detect the symtab changed event it
      can cause.  */