[1/6] gdb/tui: convert a window handle `if` into an `assert`

Message ID 3846c3c560509b21e2e05efae618b3a9fe1ef6f8.1777645161.git.aburgess@redhat.com
State New
Headers
Series gdb/tui: fix debuginfod related crash |

Commit Message

Andrew Burgess May 1, 2026, 2:22 p.m. UTC
  It should only be possible to call tui_win_info::refresh_window on a
window with a valid tui_win_info::handle.  To do otherwise would
suggest we're trying to draw to the screen a window which GDB doesn't
think is part of the current layout.  Which is just wrong.

Currently tui_win_info::refresh_window guards its content with an
`if (handle != NULL)`, but this can be changed to an assert.

A similar assert can be added to
tui_source_window_base::refresh_window, there's no `if` in this
function, which only backs up the reasoning in the first paragraph.

There should be no user-visible changes after this commit.
---
 gdb/tui/tui-wingeneral.c | 13 ++++++-------
 gdb/tui/tui-winsource.c  |  2 ++
 2 files changed, 8 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 86f13d275b4..cd04876ad1b 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -55,13 +55,12 @@  tui_batch_rendering::~tui_batch_rendering ()
 void
 tui_win_info::refresh_window ()
 {
-  if (handle != NULL)
-    {
-      if (suppress_output)
-	wnoutrefresh (handle.get ());
-      else
-	wrefresh (handle.get ());
-    }
+  gdb_assert (handle != nullptr);
+
+  if (suppress_output)
+    wnoutrefresh (handle.get ());
+  else
+    wrefresh (handle.get ());
 }
 
 /* Draw a border around the window.  */
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 8609a7cd4fe..d040019563c 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -310,6 +310,8 @@  tui_source_window_base::refresh_window ()
 {
   TUI_SCOPED_DEBUG_START_END ("window `%s`", name ());
 
+  gdb_assert (handle != nullptr);
+
   /* tui_win_info::refresh_window would draw the empty background window to
      the screen, potentially creating a flicker.  */
   wnoutrefresh (handle.get ());