[Bug tui/34100] [gdb/tui] Handle error in tui_set_initial_layout

vries at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Thu Apr 23 16:21:14 GMT 2026


https://sourceware.org/bugzilla/show_bug.cgi?id=34100

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
In tui_enable I tried this trigger patch:
...
          tui_set_initial_layout ();
+
+         {
+           static int v = 0;
+           if (v == 0)
+             {
+               v = 1;
+               error (_("Oh no!!!"));
+             }
+         }
...
in combination with this patch:
...
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 5e39eef71c6..dfd24dfa0b8 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -491,21 +491,43 @@ tui_enable (void)
         they are creating is currently valid.  */
       tui_active = true;

-      cbreak ();
-      noecho ();
-      /* timeout (1); */
-      nodelay(w, FALSE);
-      nl();
-      keypad (w, TRUE);
-      tui_set_term_height_to (LINES);
-      tui_set_term_width_to (COLS);
-      def_prog_mode ();
-
-      tui_show_frame_info (deprecated_safe_get_selected_frame ());
-      tui_set_initial_layout ();
-      tui_set_win_focus_to (tui_src_win ());
-      keypad (tui_cmd_win ()->handle.get (), TRUE);
-      wrefresh (tui_cmd_win ()->handle.get ());
+      try
+       {
+         cbreak ();
+         noecho ();
+         /* timeout (1); */
+         nodelay(w, FALSE);
+         nl();
+         keypad (w, TRUE);
+         tui_set_term_height_to (LINES);
+         tui_set_term_width_to (COLS);
+         def_prog_mode ();
+
+         tui_show_frame_info (deprecated_safe_get_selected_frame ());
+         tui_set_initial_layout ();
+         tui_set_win_focus_to (tui_src_win ());
+         keypad (tui_cmd_win ()->handle.get (), TRUE);
+         wrefresh (tui_cmd_win ()->handle.get ());
+       }
+      catch (const gdb_exception &)
+       {
+         endwin ();
+         delscreen (s);
+         tui_active = false;
+         tui_finish_init = TRIBOOL_TRUE;
+         throw;
+       }
+
       tui_finish_init = TRIBOOL_FALSE;
     }
   else
...

Unfortunately, the second tui enable runs into:
...
(gdb) bt
#0  0x00007ffff7eccf04 in wnoutrefresh () from /lib64/libncursesw.so.6
#1  0x00000000010724d5 in tui_source_window_base::refresh_window
(this=0x34494c0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-winsource.c:315
#2  0x00000000010710db in tui_unhighlight_win (win_info=0x34494c0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-wingeneral.c:121
#3  0x0000000001071216 in tui_win_info::check_and_display_highlight_if_needed
(this=0x34494c0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-wingeneral.c:148
#4  0x000000000103acf4 in tui_win_info::center_string (this=0x34494c0,
str=0x1c8ded8 "[ No Source Available ]") at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-data.c:172
#5  0x0000000001071f6f in tui_source_window_base::do_erase_source_content
(this=0x34494c0, str=0x1c8ded8 "[ No Source Available ]")
    at /data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-winsource.c:224
#6  0x000000000106aa73 in tui_source_window::erase_source_content
(this=0x34494c0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-source.h:53
#7  0x0000000001073450 in tui_source_window_base::rerender (this=0x34494c0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-winsource.c:476
#8  0x000000000105322b in tui_win_info::resize (this=0x34494c0, height_=22,
width_=137, origin_x_=0, origin_y_=0) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:299
#9  0x0000000001053ae0 in tui_layout_window::apply (this=0x332c670, x_=0, y_=0,
width_=137, height_=22, preserve_cmd_win_size_p=true)
    at /data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:432
#10 0x00000000010562f6 in tui_layout_split::apply (this=0x34fecc0, x_=0, y_=0,
width_=137, height_=34, preserve_cmd_win_size_p=true)
    at /data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:1026
#11 0x0000000001052616 in tui_apply_current_layout
(preserve_cmd_win_size_p=true) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:68
#12 0x0000000001052ae6 in tui_set_layout (layout=0x3139910) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:133
#13 0x0000000001052ea4 in tui_set_initial_layout () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-layout.c:209
#14 0x000000000107634d in tui_enable () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui.c:507
#15 0x0000000001076724 in tui_enable_command (args=0x0, from_tty=1) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui.c:624
#16 0x00000000006cff38 in do_simple_func (args=0x0, from_tty=1, c=0x313ad70) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/cli/cli-decode.c:86
#17 0x00000000006d6804 in cmd_func (cmd=0x313ad70, args=0x0, from_tty=1) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/cli/cli-decode.c:2810
#18 0x0000000001010ddf in execute_command (p=0x2fe697a "", from_tty=1) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/top.c:632
#19 0x000000000095cbce in command_handler (command=0x2fe6970 "tui enable") at
/data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:611
#20 0x000000000095d180 in command_line_handler (rl=...) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:844
#21 0x000000000104650b in tui_command_line_handler (rl=...) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-interp.c:101
#22 0x000000000095c273 in gdb_rl_callback_handler (rl=0x33d39f0 "tui enable")
at /data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:288
#23 0x00000000011a17ff in rl_callback_read_char () at
/data/vries/gdb/leap-16-0/build/../../src/readline/readline/callback.c:302
#24 0x000000000095bf47 in gdb_rl_callback_read_char_wrapper_sjlj () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:197
#25 0x000000000095c058 in gdb_rl_callback_read_char_wrapper_noexcept () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:240
#26 0x000000000095c0d6 in gdb_rl_callback_read_char_wrapper
(client_data=0x2fe5110) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/event-top.c:252
#27 0x000000000108a2b3 in stdin_event_handler (error=0, client_data=0x2fe5110)
at /data/vries/gdb/leap-16-0/build/../../src/gdb/ui.c:161
#28 0x0000000001a3fa87 in handle_file_event (file_ptr=0x34466b0, ready_mask=1)
at /data/vries/gdb/leap-16-0/build/../../src/gdbsupport/event-loop.cc:551
#29 0x0000000001a400ca in gdb_wait_for_event (block=1) at
/data/vries/gdb/leap-16-0/build/../../src/gdbsupport/event-loop.cc:672
#30 0x0000000001a3efa7 in gdb_do_one_event (mstimeout=-1) at
/data/vries/gdb/leap-16-0/build/../../src/gdbsupport/event-loop.cc:263
#31 0x00000000006df104 in interp::do_one_event (this=0x3497300, mstimeout=-1)
at /data/vries/gdb/leap-16-0/build/../../src/gdb/interps.h:90
#32 0x0000000000b93eae in start_event_loop () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/main.c:400
#33 0x0000000000b94099 in captured_command_loop () at
/data/vries/gdb/leap-16-0/build/../../src/gdb/main.c:465
#34 0x0000000000b95fe2 in captured_main (context=0x7fffffffd670) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/main.c:1373
#35 0x0000000000b960de in gdb_main (args=0x7fffffffd670) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/main.c:1392
#36 0x000000000041a765 in main (argc=4, argv=0x7fffffffd7a8) at
/data/vries/gdb/leap-16-0/build/../../src/gdb/gdb.c:38
(gdb) 
...

Leaving tui_finish_init at TRIBOOL_UNKNOWN fixes that, but it means that tui is
disabled the rest of the session:
...
$ gdb -q
(gdb) tui enable
❌️ Oh no!!!
(gdb) tui enable
❌️ Cannot enable the TUI
(gdb) 
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list