From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id C3EB83858C31 for ; Wed, 10 May 2023 06:20:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3EB83858C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 E08F121A8C; Wed, 10 May 2023 06:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683699616; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=0yfDHdV07l9+VZFiRhKmM0JND+QIS3k0x/TWXcIUkeo=; b=SE1XwwGKj9sr8r30LAcMvGMXA7ZwJmci/PRcExApdFotOygNr1nSaP23HZAn2F82XRX/v8 CfgaD3o6p78MszZc9WOMqRk6c7+SWH7Vx0IuC6CREginKAQ3q+pCvmC807nnWuqkRzhNcj wJaairQAbxc66lO98m2VN1cIMmb/0s4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683699616; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=0yfDHdV07l9+VZFiRhKmM0JND+QIS3k0x/TWXcIUkeo=; b=mg7HNRpZQIqiNC1BS1Vq2VYphkPy9keUXijvU6I79UzxkjdxErRyxegkTGwcRi+j83T4qA q6wlJEMYQAro7XBg== 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 997D713519; Wed, 10 May 2023 06:20:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zSUmIqA3W2Q0LAAAMHmgww (envelope-from ); Wed, 10 May 2023 06:20:16 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] [gdb/tui] Make tui compact-source more compact Date: Wed, 10 May 2023 08:20:15 +0200 Message-Id: <20230510062015.20974-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.4 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: I noticed with tui compact-source on, that when reducing the height of the src window we go from: ... |___09_ i++; | |___10_ i++; | +--------------------------------------+ ... to: ... |___09_ i++; | +--------------------------------------+ ... In other words, the digits used to print 9 remains 2, even though only 1 is needed. This is due to this line in tui_source_window::set_contents: ... int max_line_nr = std::max (lines_in_file, last_line_nr_in_window); ... which takes both the last line in the window and the total lines in the source file into account. Make "tui compact-source" more compact by just using: ... int max_line_nr = last_line_nr_in_window; ... such that we have: ... |___9_ i++; | +--------------------------------------+ ... Tested on x86_64-linux. --- gdb/testsuite/gdb.tui/compact-source-2.exp | 68 ++++++++++++++++++++++ gdb/tui/tui-source.c | 3 +- 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/compact-source-2.exp diff --git a/gdb/testsuite/gdb.tui/compact-source-2.exp b/gdb/testsuite/gdb.tui/compact-source-2.exp new file mode 100644 index 00000000000..416c76e1d26 --- /dev/null +++ b/gdb/testsuite/gdb.tui/compact-source-2.exp @@ -0,0 +1,68 @@ +# 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 . + +# Check that "set tui compact-source on" has the intended effect. + +require allow_tui_tests + +tuiterm_env + +standard_testfile + +# Let's generate the source file. We want a short file, with more than 10 +# lines, but with the first line in main below 10. +set src_list \ + [list \ + "int" \ + "main (void)" \ + "{" \ + " int i = 1;" \ + " i++;" \ + " i++;" \ + " i++;" \ + " i++;" \ + " i++;" \ + " return 0;" \ + "}"] +set line_four [lindex $src_list 3] +set src_txt [join $src_list "\n"] +set srcfile [standard_output_file $srcfile] +set fd [open $srcfile w] +puts $fd $src_txt +close $fd + +if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { + return -1 +} + +Term::clean_restart 17 80 $binfile + +gdb_test_no_output "maint set tui-left-margin-verbose on" +gdb_test_no_output "set tui compact-source on" + +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + +set re_border "\\|" +Term::check_contents "compact source format" \ + "${re_border}___04_$line_four *$re_border" + +with_test_prefix window-resize=1 { + Term::command "wh src -1" + Term::check_contents "compact source" \ + "${re_border}___4_$line_four *$re_border" +} diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 1233e945cab..bef3d3163dd 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -79,9 +79,8 @@ tui_source_window::set_contents (struct gdbarch *arch, { /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we cast to double to get the right one. */ - int lines_in_file = offsets->size (); int last_line_nr_in_window = line_no + nlines - 1; - int max_line_nr = std::max (lines_in_file, last_line_nr_in_window); + int max_line_nr = last_line_nr_in_window; int digits_needed = 1 + (int)log10 ((double) max_line_nr); int trailing_space = 1; m_digits = digits_needed + trailing_space; base-commit: 2093c2af3c58da1fe63807dfea07d56afc6e7a8a -- 2.35.3