From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 63C973858D33 for ; Thu, 9 Nov 2023 12:03:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63C973858D33 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 63C973858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699531417; cv=none; b=dCXlEgj0pfg7IwEPyUuuYx66QAgF4o3oWuVRiun0axBypTf9lySv6cXDWBym/f1fagtxjIStEmyOJqec7QNg1kA+otEaYD30wZoipSi96hKtSLV6GDlIc+uLyejtRR4XmJBMTM/FvMF36Lbs7vU7mVBknKBbzLt+TJ8aWeP2xAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699531417; c=relaxed/simple; bh=osGH8fb1fnrdzyY8/rdyswK/onHhQ/oPnIN+X8+W0i0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=Qmj5/a47UURMy6CqMGisXwomRkhzfX+YdQQvtZXtwmq+BDp7J6bSY8kRU8//awRNMtDteviSExc8EDvKx3JumBDKql+2WL6Ph6NrgW4pjpEOnOZovwtxweg2xe2JfD6rvBsT7RbvNbTU+W00C3xyeq0gGyMaC1N/60GhzqH/vLo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 567372195D for ; Thu, 9 Nov 2023 12:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699531415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OaTNh06ehj1qRQJ4zGLtqcLZyOoPZGOD6Erm4nTNHPE=; b=oV9LK+c+dHq0i5i+xkriJ2awajOHOHLDE5VaEkoEIrNKWBTjukAtaLMTm+ui7S6n41Hv2D x4TYiGkKhjIYKhXUGTEk3G11jVdFFCusLP5aUE9En0sIl0SBtzoozpLvThCegYhh22bZ+k lFj60LQKEJkhJI4J9Lt5AhMejooB+9M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699531415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OaTNh06ehj1qRQJ4zGLtqcLZyOoPZGOD6Erm4nTNHPE=; b=Wv0KIt8v3YeGMTKDl2QmNgyJpeNxjL+q0ojl1TP16c+y4PeAu6lx+M1BWzIoBzs3I6DuFJ Iho/fy3MvA2h3sCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 36FDC138E5 for ; Thu, 9 Nov 2023 12:03:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rl49DJfKTGWcJgAAMHmgww (envelope-from ) for ; Thu, 09 Nov 2023 12:03:35 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [gdb/tui] Allow command window of 1 or 2 lines Date: Thu, 9 Nov 2023 13:04:54 +0100 Message-Id: <20231109120455.4741-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When starting TUI in a terminal with 2 lines (likewise with 1 line): ... $ echo $LINES 2 $ gdb -q -tui ... we run into this assert in tui_apply_current_layout: ... /* This should always be made visible by a layout. */ gdb_assert (TUI_CMD_WIN != nullptr); ... The problem is that for the command window: - the minimum height is 3 (the default), but - the maximum height is only 2 because there are only 2 lines. This discrepancy eventually leads to a call to newwin in make_window with: ... (gdb) p height $1 = 3 (gdb) p width $2 = 66 (gdb) p y $3 = -1 (gdb) p x $4 = 0 (gdb) ... which results in a nullptr, which eventually triggers the assert. The easiest way to fix this is to change the minimum height of the command window to 1. However, that would also change behaviour for the case that the screen size is 3 lines or more. For instance, in gdb.tui/winheight.exp the number of lines in the terminal is 24, and the test-case checks that the user cannot increase the source window height to the point that the command window height would be less than 3. Fix this by calculating the minimum height of the command window as follows: - the default (3) if max_height () allows it, and - max_height () otherwise. Tested on x86_64-linux. PR tui/31044 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31044 --- gdb/testsuite/gdb.tui/small-term.exp | 29 ++++++++++++++++++++++++++++ gdb/tui/tui-command.h | 12 ++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gdb/testsuite/gdb.tui/small-term.exp diff --git a/gdb/testsuite/gdb.tui/small-term.exp b/gdb/testsuite/gdb.tui/small-term.exp new file mode 100644 index 00000000000..c67c5cae1e0 --- /dev/null +++ b/gdb/testsuite/gdb.tui/small-term.exp @@ -0,0 +1,29 @@ +# 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 . + +# Test running TUI in a tuiterm with few lines. + +tuiterm_env + +foreach_with_prefix lines { 1 2 3 4 5 6 7 } { + Term::clean_restart $lines 80 + + if {![Term::enter_tui]} { + unsupported "TUI not supported" + return + } + + Term::check_region_contents "has prompt" 0 0 80 $lines "$gdb_prompt" +} diff --git a/gdb/tui/tui-command.h b/gdb/tui/tui-command.h index f6842880bb2..e8c96ecee30 100644 --- a/gdb/tui/tui-command.h +++ b/gdb/tui/tui-command.h @@ -57,6 +57,18 @@ struct tui_cmd_window : public tui_win_info /* The command window can't be made invisible. */ } + /* Compute the minimum height of this window. */ + virtual int min_height () const override + { + int preferred_min = tui_win_info::min_height (); + int max = max_height (); + /* If there is enough space to accommodate the preferred minimum height, + use it. Otherwise, use as much as possible. */ + return (preferred_min <= max + ? preferred_min + : max); + } + int start_line = 0; protected: base-commit: cf5f570bd002fac5bc820d220d5cf8584cbaed6d -- 2.35.3