From patchwork Wed May 10 13:21:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 69049 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01E42385773E for ; Wed, 10 May 2023 13:21:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01E42385773E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683724905; bh=7eNW1/DATnHdpxx2sbtKg7S3WnDQhrv6nUWmq2bUlAc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nvAuqCKL8xO6nLv3a5kdp2ydZ3HLS8DxQDPHKtB3Bqi/PkSCEh76KoAqRfdv14On/ QVBdaU6LHufM5ZEF2FXxpypFDmZeWiW1MAJLW4vUGIAb5p9B8p0/PfKWRi6PJGuyKS IV2+dIMPcTfqQnemYcy6mnc5VN8JppaiLA3GZ8Kw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 07B553858414 for ; Wed, 10 May 2023 13:21:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07B553858414 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-out2.suse.de (Postfix) with ESMTPS id EEAD51F45E; Wed, 10 May 2023 13:21:20 +0000 (UTC) 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 6672913519; Wed, 10 May 2023 13:21:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id X9u9FFCaW2QZDgAAMHmgww (envelope-from ); Wed, 10 May 2023 13:21:20 +0000 To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] [gdb/tui] Fix tui compact-source a bit more Date: Wed, 10 May 2023 15:21:18 +0200 Message-Id: <20230510132118.13761-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Andrew pointed out that the behaviour as tested in gdb.tui/compact-source.exp is incorrect: ... 0 +-compact-source.c--------------------------------------------------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 |___6_ | 5 |___7_ | 6 |___8_ | 7 |___9_ | 8 +-------------------------------------------------------------------------+ ... The last line number in the source file is 5, and there are 7 lines to display source lines, so if we'd scroll all the way down, the first line number in the source window would be 5, and the last one would be 11. To represent 11 we'd need 2 digits, so we expect to see ___04_ here instead of ___4_, even though all line numbers currently in the src window (3-9) can be represented with only 1 digit. Fix this in tui_source_window::set_contents, by updating the computation of max_line_nr: ... - int max_line_nr = std::max (lines_in_file, last_line_nr_in_window); + int max_line_nr = lines_in_file + nlines - 1; ... Tested on x86_64-linux. Co-Authored-By: Andrew Burgess --- gdb/testsuite/gdb.tui/compact-source.exp | 43 +++++++++++++++--------- gdb/tui/tui-source.c | 3 +- 2 files changed, 29 insertions(+), 17 deletions(-) base-commit: 8b7b3b2bf4357781439e5434c4a5942ea29e983d diff --git a/gdb/testsuite/gdb.tui/compact-source.exp b/gdb/testsuite/gdb.tui/compact-source.exp index 71e6b7b0b0a..f972d961d72 100644 --- a/gdb/testsuite/gdb.tui/compact-source.exp +++ b/gdb/testsuite/gdb.tui/compact-source.exp @@ -23,14 +23,15 @@ standard_testfile # Let's generate the source file. We want a short file, with less than 10 # lines, and the copyright notice by itself is already more that that. -set src_txt \ - [join \ - [list \ - "int" \ - "main (void)" \ - "{" \ - " return 0;" \ - "}"] "\n"] +set src_list \ + [list \ + "int" \ + "main (void)" \ + "{" \ + " return 0;" \ + "}"] +set re_line_four [string_to_regexp [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 @@ -40,7 +41,7 @@ if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { return -1 } -Term::clean_restart 17 80 $binfile +Term::clean_restart 24 80 $binfile gdb_test_no_output "maint set tui-left-margin-verbose on" gdb_test_no_output "set tui compact-source on" @@ -51,11 +52,23 @@ if {![Term::enter_tui]} { } set re_border "\\|" -Term::check_contents "compact source format" \ - "${re_border}___04_ return 0; *$re_border" -with_test_prefix window-resize=1 { - Term::command "wh src -1" - Term::check_contents "compact source" \ - "${re_border}___4_ return 0; *$re_border" +foreach_with_prefix src_window_size {7 8} { + set src_window_lines [expr $src_window_size - 2] + set max_line_nr_in_source_file [llength $src_list] + set max_line_nr_in_source_window \ + [expr $max_line_nr_in_source_file + $src_window_lines - 1] + + Term::command "wh src $src_window_size" + + if { $max_line_nr_in_source_window == 9 } { + set re_left_margin "___4_" + } elseif { $max_line_nr_in_source_window == 10 } { + set re_left_margin "___04_" + } else { + error "unhandled max_line_nr_in_source_window" + } + + Term::check_contents "compact source format" \ + "$re_border$re_left_margin$re_line_four *$re_border" } diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 1233e945cab..9d0376000de 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -80,8 +80,7 @@ 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 = lines_in_file + nlines - 1; int digits_needed = 1 + (int)log10 ((double) max_line_nr); int trailing_space = 1; m_digits = digits_needed + trailing_space;