From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AA4VFTWR62lI7TgAWB0awg (envelope-from ) for ; Fri, 24 Apr 2026 11:50:13 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=js90JDVd; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8CO2/R8w; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=js90JDVd; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8CO2/R8w; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 428E21E067; Fri, 24 Apr 2026 11:50:13 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BC9B81E067 for ; Fri, 24 Apr 2026 11:50:11 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 7391D4BB58E4 for ; Fri, 24 Apr 2026 15:50:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7391D4BB58E4 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=js90JDVd; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8CO2/R8w; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=js90JDVd; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8CO2/R8w Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 02E854BB3BD0 for ; Fri, 24 Apr 2026 15:49:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02E854BB3BD0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02E854BB3BD0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777045785; cv=none; b=AHVrv4rGONghfkyHUuyl2V4kYheMglywkytJGn/HRv15IS3agvPPaEQ/y6Q35YFIwVBm5ghdwASF/t+wBBvE1lRZxa5bKedV/HjsnoLWCIUHMtKoFwuMwT5rRGVIb1CdP6rrPOslnaPk0htYJzIp8JXA4K2X5CUYYpXVCDagWKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777045785; c=relaxed/simple; bh=SkI5jgBfPbzpvw8DhUAxGz+o4ByKgLTnO7E4N3+FlyY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=idOpdLkgzbsZSNV/iMOHPxJ8dTsb05E31zvTVwHUPnfE8OXnpQhHSD+1QKVjK4Uk+2+WLGCNGyaqSABaxY7LLt9Z822NxlM0gNwOLvHRO1C4bCib0yG/JaZrec2yZFxwOo3cjIgncg7O5amRuTrc78VnMaO7hG4/S5/Qw2IiCL8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02E854BB3BD0 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 75C626A8A7 for ; Fri, 24 Apr 2026 15:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777045783; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kC5SbTirktRtWJd4hrYccQ7i5ldIAyWokiu+F+g0t8c=; b=js90JDVd0qP6eH8SHNwybsqpGr4S5VKeD2edVlLf7aw5U4hSg14a3W6VhDNCw1oxFxqJzr i4Z+ELuMx55cwg0O8JH7VYTEllYlBGo7iUVAV/e1MkR4bN487cOjS6BQjzZN8TLRRm9Ej+ 47v/H9v7x3SrlUW/YWV2bLg82qxqu/I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777045783; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kC5SbTirktRtWJd4hrYccQ7i5ldIAyWokiu+F+g0t8c=; b=8CO2/R8w0G5DeL9ddiux8EpZ9IgygftzckS0fOSrhfcgPOcvFADvebvqKeoe6475Ax66cj ovd0eiBonl/B/HDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777045783; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kC5SbTirktRtWJd4hrYccQ7i5ldIAyWokiu+F+g0t8c=; b=js90JDVd0qP6eH8SHNwybsqpGr4S5VKeD2edVlLf7aw5U4hSg14a3W6VhDNCw1oxFxqJzr i4Z+ELuMx55cwg0O8JH7VYTEllYlBGo7iUVAV/e1MkR4bN487cOjS6BQjzZN8TLRRm9Ej+ 47v/H9v7x3SrlUW/YWV2bLg82qxqu/I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777045783; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kC5SbTirktRtWJd4hrYccQ7i5ldIAyWokiu+F+g0t8c=; b=8CO2/R8w0G5DeL9ddiux8EpZ9IgygftzckS0fOSrhfcgPOcvFADvebvqKeoe6475Ax66cj ovd0eiBonl/B/HDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6015B593A4 for ; Fri, 24 Apr 2026 15:49:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id IWkUFheR62n8QwAAD6G6ig (envelope-from ) for ; Fri, 24 Apr 2026 15:49:43 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/tui] Handle error in tui_enable Date: Fri, 24 Apr 2026 17:49:42 +0200 Message-ID: <20260424154942.50673-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Say we simulate an error: ... static void error_once () { static int v = 0; if (v == 1) return; v = 1; error (_("Oh no!!!")); } ... in the call to tui_set_initial_layout in tui_enable: ... tui_show_frame_info (deprecated_safe_get_selected_frame ()); + error_once (); tui_set_initial_layout (); ... After doing "tui enable" ... $ gdb (gdb) tui enable ... the screen is cleared, and we have: ... ❌️ Oh no!!! (gdb) ... After typing "apropos tui" (which is not echoed) and pressing enter, I run into a segmentation violation here in tui_inject_newline_into_command_window: ... at /data/vries/gdb/leap-16-0/build/../../src/gdb/tui/tui-io.c:1084 1084 WINDOW *w = tui_cmd_win ()->handle.get (); ... because: ... $2 = (tui_cmd_window *) 0x0 (gdb) p tui_cmd_win () ... The problem is that tui_active is true, and so tui_inject_newline_into_command_window get called: ... static void tui_command_line_handler (gdb::unique_xmalloc_ptr &&rl) { ... if (tui_active) tui_inject_newline_into_command_window (); ... } ... Fix this by catching the error in tui_enable, and resetting tui_active back to false. While this fixes the segmentation fault, and does allow "apropos tui" to run, still the command is not echoed, and the output of the command is garbled by runaway indentation. Fix this by using endwin / delscreen, as borrowed from earlier in tui_enable: ... if (cap == NULL || cap == (char *) -1 || *cap == '\0') { endwin (); delscreen (s); error (_("Cannot enable the TUI: " "terminal doesn't support cursor addressing [TERM=%s]"), gdb_getenv_term ()); } ... Note that this doesn't allow a second attempt: ... $ gdb -q (gdb) tui enable ❌️ Oh no!!! (gdb) tui enable ❌️ Cannot enable the TUI (gdb) ... because tui_finish_init is stuck at TRIBOOL_UNKNOWN. IWBN to fix this in a way that allows the second "tui enable" to succeed. I tried this for a bit, but didn't get it to work. Tested on x86_64-linux. Suggested-By: Tom Tromey [1] Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34100 [1] https://sourceware.org/pipermail/gdb-patches/2025-May/217660.html --- gdb/tui/tui.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 5e39eef71c6..9fef7feffe5 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -490,22 +490,31 @@ tui_enable (void) rely on this flag being true in order to know that the window they are creating is currently valid. */ tui_active = true; + 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; + throw; + } - 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 ()); tui_finish_init = TRIBOOL_FALSE; } else base-commit: 4308969628943757f972e766c70352c4828cb4d2 -- 2.51.0