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 1A8F63858D32 for ; Mon, 15 May 2023 03:58:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A8F63858D32 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 268E321CD8; Mon, 15 May 2023 03:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684123105; 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=1PqGyCoexT3EFa9cWdQl/U7d9NAVc0iJ7gEqLDp2GKQ=; b=KnnS7pSwsfzGEur76cw/6IJ1a5H0T6Li/pg0FL1gYS0p7jPPJ/tShH0gptJpVe/9PqAhQf lkfP8HSJwFqEgcJXrlW+kN/+LHjoTZemL4ML3cKuE+0zcmxzsKpyGm1IQ4LzF26oYlW4in 0oNuc4y9XXznGtpqfIF122SlfKysyfc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684123105; 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=1PqGyCoexT3EFa9cWdQl/U7d9NAVc0iJ7gEqLDp2GKQ=; b=fduh8s1YgZBruKZkkYN3rQw0o18zs4aANbHh9mxZfDhQQW9R/6HkxRJbCDQbKfAufrpMf2 SFBfJkDybnFTyzBg== 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 0D1E113499; Mon, 15 May 2023 03:58:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id x479AeGtYWSUOgAAMHmgww (envelope-from ); Mon, 15 May 2023 03:58:25 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] [gdb/tui] Don't show line number for lines not in source file Date: Mon, 15 May 2023 05:58:24 +0200 Message-Id: <20230515035824.13645-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.5 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: Currently, for a source file containing only 5 lines, we also show line numbers 6 and 7 if they're in scope of the source window: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 |___6_ | 5 |___7_ | 6 +---------------------------------+ ... Fix this by not showing line numbers not in a source file, such that we have instead: ... 0 +-compact-source.c----------------+ 1 |___3_{ | 2 |___4_ return 0; | 3 |___5_} | 4 | | 5 | | 6 +---------------------------------+ ... Tested on x86_64-linux. --- gdb/testsuite/gdb.tui/compact-source.exp | 28 ++++++++++-------------- gdb/testsuite/lib/tuiterm.exp | 8 +++++++ gdb/tui/tui-source.c | 24 +++++++++++++++----- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/gdb/testsuite/gdb.tui/compact-source.exp b/gdb/testsuite/gdb.tui/compact-source.exp index f972d961d72..e9703b3c3d9 100644 --- a/gdb/testsuite/gdb.tui/compact-source.exp +++ b/gdb/testsuite/gdb.tui/compact-source.exp @@ -53,22 +53,18 @@ if {![Term::enter_tui]} { set 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] +set max_line_nr_in_source_file [llength $src_list] +# Ensure there are more lines in the window than in the source file. +set src_window_lines [expr $max_line_nr_in_source_file + 2] +# Account for border size. +set src_window_size [expr $src_window_lines + 2] +Term::command "wh src $src_window_size" - Term::command "wh src $src_window_size" +set re_left_margin "___4_" - 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" - Term::check_contents "compact source format" \ - "$re_border$re_left_margin$re_line_four *$re_border" -} +set re_left_margin "___0*[expr $max_line_nr_in_source_file + 1]_" +Term::check_contents_not "no surplus line number" \ + "$re_border$re_left_margin *$re_border" diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 5e4235da942..195f14666f4 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -1004,6 +1004,14 @@ namespace eval Term { gdb_assert {[regexp -- $regexp $contents]} $test_name } + # As check_contents, but check that the text contents of the terminal does + # not match the regular expression. + proc check_contents_not {test_name regexp} { + dump_screen + set contents [get_all_lines] + gdb_assert {![regexp -- $regexp $contents]} $test_name + } + # Get the region of the screen described by X, Y, WIDTH, # and HEIGHT, and separate the lines using SEP. proc get_region { x y width height sep } { diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 9d0376000de..55cde258882 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -80,7 +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 max_line_nr = lines_in_file + nlines - 1; + int max_line_nr = lines_in_file; int digits_needed = 1 + (int)log10 ((double) max_line_nr); int trailing_space = 1; m_digits = digits_needed + trailing_space; @@ -100,6 +100,11 @@ tui_source_window::set_contents (struct gdbarch *arch, text = tui_copy_source_line (&iter, &line_len); m_max_length = std::max (m_max_length, line_len); } + else + { + /* Line not in source file. */ + cur_line_no = -1; + } /* Set whether element is the execution point and whether there is a break point on it. */ @@ -233,11 +238,20 @@ tui_source_window::display_start_addr (struct gdbarch **gdbarch_p, void tui_source_window::show_line_number (int offset) const { - int lineno = m_content[0].line_or_addr.u.line_no + offset; + int lineno = m_content[offset].line_or_addr.u.line_no; char text[20]; char space = tui_left_margin_verbose ? '_' : ' '; - xsnprintf (text, sizeof (text), - tui_left_margin_verbose ? "%0*d%c" : "%*d%c", m_digits - 1, - lineno, space); + if (lineno == -1) + { + /* Line not in source file, don't show line number. */ + for (int i = 0; i <= m_digits; ++i) + text[i] = (i == m_digits) ? '\0' : space; + } + else + { + xsnprintf (text, sizeof (text), + tui_left_margin_verbose ? "%0*d%c" : "%*d%c", m_digits - 1, + lineno, space); + } waddstr (handle.get (), text); } base-commit: 0d5ffd658faf6920c99405b6b68d6046f10c845f -- 2.35.3