From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fHM2A22Lz2lZTAUAWB0awg (envelope-from ) for ; Fri, 03 Apr 2026 05:42:05 -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=bDV7176F; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qd5WeJrQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bDV7176F; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qd5WeJrQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DFE071E04F; Fri, 03 Apr 2026 05:42:04 -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 688B11E04F for ; Fri, 03 Apr 2026 05:42:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id B2E174BA23CF for ; Fri, 3 Apr 2026 09:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2E174BA23CF 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=bDV7176F; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qd5WeJrQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bDV7176F; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qd5WeJrQ Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id BB4254BA23C9 for ; Fri, 3 Apr 2026 09:40:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB4254BA23C9 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 BB4254BA23C9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775209249; cv=none; b=o/+sESLegIRisZZeaMrNn5REUrE+StfWGVop3rnjdzkFl/K+hl6MgeIH4O5ACOAraqWU0+8lEmgxoxUDn/MyZMyvzpPjc0TGJSqvyCmBrTvaAxe0P2PxL+Dbyv+ZQocYrOmgbFhks9Hu8rC58HVhvVSX980xGK6TqdUgqU4pr04= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775209249; c=relaxed/simple; bh=AHVsTqrXiinOXHZJUzaygrFloDkiNqdNp/qKoY3CZrQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=phkKc3Z+f/iPMtMrJjWVJNAQ7zilI2CIiQisvnas3wrdWG+TnMXT00xJ1qqUnib4wqs/cQ7jBQPb/hxBTO+Edgy7/iqrQ72B0PWDzIgJNXXxmiy9UG3i9RuWh9kQ/4TKx94SGOqxHMPaoNfpdLD0vnAdSOC/FcGAD9JWOcvzYyM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB4254BA23C9 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 61F724D1D2 for ; Fri, 3 Apr 2026 09:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775209247; 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=q9d2CXHSybfZ/62mqR1pF0FM4uGl7c/y152dxknOcQw=; b=bDV7176FHwaccBmTM+YF8MjCfYog2jWEHm4RkAay2El6nUP7P33udd4P8kJTF815SlvYYz l1Sx1Zz6W7cTJ/vVuvz+S1j/g+lM5d+RcKVvbpy0VLT7h2+hStvlXXkeo1PQ2jcUzrvaDq IPLkzVeMuIGeDh8FCAgIL+g15LJfiE8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775209247; 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=q9d2CXHSybfZ/62mqR1pF0FM4uGl7c/y152dxknOcQw=; b=qd5WeJrQZilCOjRlMIdVB1GwephUpAX0esxWGzswaiup9hk6lYKlfCee82qrYy7UqZIrPe Apc/vi7lqxGlCGCQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=bDV7176F; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qd5WeJrQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775209247; 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=q9d2CXHSybfZ/62mqR1pF0FM4uGl7c/y152dxknOcQw=; b=bDV7176FHwaccBmTM+YF8MjCfYog2jWEHm4RkAay2El6nUP7P33udd4P8kJTF815SlvYYz l1Sx1Zz6W7cTJ/vVuvz+S1j/g+lM5d+RcKVvbpy0VLT7h2+hStvlXXkeo1PQ2jcUzrvaDq IPLkzVeMuIGeDh8FCAgIL+g15LJfiE8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775209247; 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=q9d2CXHSybfZ/62mqR1pF0FM4uGl7c/y152dxknOcQw=; b=qd5WeJrQZilCOjRlMIdVB1GwephUpAX0esxWGzswaiup9hk6lYKlfCee82qrYy7UqZIrPe Apc/vi7lqxGlCGCQ== 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 4E5964A0A6 for ; Fri, 3 Apr 2026 09:40:47 +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 Wl/nER+Lz2mmRwAAD6G6ig (envelope-from ) for ; Fri, 03 Apr 2026 09:40:47 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/tui] Handle tui disable in new ui Date: Fri, 3 Apr 2026 11:40:46 +0200 Message-ID: <20260403094046.2876515-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.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,suse.de:dkim,suse.de:mid,sourceware.org:url,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,gdb.base:url]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 61F724D1D2 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 I tried out the following scenario. First, I start a terminal to get a tty [1]. ... $ gnome-terminal -- bash -c "tty; sleep 999999999" & ... Then I start gdb, and start a new UI in the tty: ... $ gdb (gdb) new-ui console /dev/pts/3 New UI allocated (gdb) ... Now I have two terminals, each with a gdb prompt. I try in the new UI to enable TUI: ... (gdb) tui enable ❌️ Cannot enable the TUI when the interpreter is 'console' (gdb) ... but that is not allowed. So instead, I enable TUI in the main UI. So far so good. Now I disable TUI in the new UI. That leaves the new UI in this state: ... (gdb) tui disable ... So, no gdb prompt. The main UI does leave TUI, AFAICT. If I do "print 1" in the new UI, I get the result in the main UI, which is not supposed to happen. Fix this by instead throwing an error if we try to disable TUI in the new UI: ... (gdb) tui disable ❌️ Cannot enable or disablethe TUI when the interpreter is 'console' (gdb) ... We could try to fix this instead by allowing tui enable/disable from the new UI, using: ... scoped_restore restore_interpreter = make_scoped_restore (¤t_ui, main_ui); ... but with just that change, when doing "tui enable" in the new UI we do get a TUI layout in the main UI, but no gdb prompt. The prompt does appear after a new keystroke in the main UI though. A few more TUI commands (for instance "layout asm") have the same problem: - they work when entered in the new UI, - they have an effect in the main UI, but - they don't show a prompt in the main UI. I left that problem as is, and exercised some TUI commands in a new UI in the test-case. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34035 --- gdb/testsuite/gdb.tui/new-ui.exp | 93 ++++++++++++++++++++++++++++++++ gdb/tui/tui.c | 18 +++++-- 2 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/new-ui.exp diff --git a/gdb/testsuite/gdb.tui/new-ui.exp b/gdb/testsuite/gdb.tui/new-ui.exp new file mode 100644 index 00000000000..8fe3567077a --- /dev/null +++ b/gdb/testsuite/gdb.tui/new-ui.exp @@ -0,0 +1,93 @@ +# Copyright 2026 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 . + +# Test TUI in combination with a new UI. + +tuiterm_env + +# Creating a pty is done on build, and we use it with gdb on host, so we need +# build == host, in other words, local host. +require {!is_remote host} + +# Create a pty. +spawn -pty +set new_ui_spawn_id $spawn_id +set new_ui_tty_name $spawn_out(slave,name) + +set re_cannot_enable_disable_tui \ + "Cannot enable or disable the TUI when the interpreter is 'console'" + +with_test_prefix main-ui { + Term::clean_restart 24 80 + + # Check that we cannot setup a new tui UI. Also checked in + # gdb.base/new-ui.exp. + gdb_test "new-ui tui $new_ui_tty_name" \ + "interpreter 'tui' cannot be used with a new UI" \ + {new-ui tui $new_ui_tty_name} + + # Set up a new console UI. + gdb_test "new-ui console $new_ui_tty_name" \ + "New UI allocated" \ + {new-ui cli $new_ui_tty_name} +} + +with_test_prefix new-ui { + with_spawn_id $new_ui_spawn_id { + # Check that we cannot enable TUI in the new UI. + gdb_test "tui enable" $re_cannot_enable_disable_tui + } +} + +with_test_prefix main-ui { + if {![Term::enter_tui]} { + unsupported "TUI not supported" + return + } +} + +with_test_prefix new-ui { + with_spawn_id $new_ui_spawn_id { + # Check that we cannot disable TUI in the new UI. + # Regression test for PR34035. Without the fix, this test will timeout, + # because no prompt will appear. + gdb_test "tui disable" $re_cannot_enable_disable_tui + + gdb_test "print 1" \ + [quotemeta {$@DECIMAL = 1}] \ + "Check that UI is responsive" + } + + # Try out some TUI commands. We don't check for the effect in the main + # UI, we just check that the main UI is still responsive at the end. + with_spawn_id $new_ui_spawn_id { + gdb_test "info win" [quotemeta "@...(has focus)@..."] + + gdb_test "focus cmd" \ + [string_to_regexp "Focus set to cmd window."] + + # This command leaves a blinking cursor at the end of the status line. + gdb_test_no_output "layout asm" + + gdb_test "winheight asm +1" + gdb_test_no_output "tui refresh" + } +} + +with_test_prefix main-ui { + gdb_assert {[Term::command "print 1"]} \ + "Check that UI is responsive" + Term::dump_screen +} diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 9cf21f390c8..5e39eef71c6 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -394,6 +394,17 @@ gdb_getenv_term (void) return ""; } +/* Error out if the toplevel interpreter is not the TUI interpreter. */ + +static void +require_tui_interpreter () +{ + const char *interp = top_level_interpreter ()->name (); + if (!streq (interp, INTERP_TUI)) + error (_("Cannot enable or disable the TUI when the interpreter is '%s'"), + interp); +} + /* Enter in the tui mode (curses). When in normal mode, it installs the tui hooks in gdb, redirects the gdb output, configures the readline to work in tui mode. @@ -424,13 +435,10 @@ tui_enable (void) #ifndef __MINGW32__ const char *cap; #endif - const char *interp; /* If the top level interpreter is not the console/tui (e.g., MI), enabling curses will certainly lose. */ - interp = top_level_interpreter ()->name (); - if (!streq (interp, INTERP_TUI)) - error (_("Cannot enable the TUI when the interpreter is '%s'"), interp); + require_tui_interpreter (); /* Don't try to setup curses (and print funny control characters) if we're not outputting to a terminal. */ @@ -556,6 +564,8 @@ tui_disable (void) if (!tui_active) return; + require_tui_interpreter (); + /* Restore initial readline keymap. */ rl_set_keymap (tui_readline_standard_keymap); base-commit: 5ae26f34ef5ac863203d63fffc968d63e823172f -- 2.51.0