From: Tom de Vries <tdevries@suse.de>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>, Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH] [gdb/tui] Fix tui compact-source a bit more
Date: Thu, 11 May 2023 19:45:59 +0200 [thread overview]
Message-ID: <99abb8c4-b4c0-337f-1319-48504bf0d14a@suse.de> (raw)
In-Reply-To: <ce09a70e-3579-f75a-4556-81c3a2b58786@simark.ca>
[-- Attachment #1: Type: text/plain, Size: 1769 bytes --]
On 5/11/23 16:55, Simon Marchi wrote:
> On 5/10/23 09:21, Tom de Vries via Gdb-patches wrote:
>> 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.
>
> Just wondering: it makes sense to let the user scroll down all the way,
> until the point where line 5 is the first line in the window. However,
> do we need to print line numbers for lines that are after the end of the
> source file? In other words, could we leave lines 6-11 blank, and
> therefore we could keep using just one digit?
This demonstrator patch implements that approach.
Thanks,
- Tom
[-- Attachment #2: 0001-gdb-tui-Don-t-show-line-number-for-lines-not-in-sour.patch --]
[-- Type: text/x-patch, Size: 2738 bytes --]
From 31b7ab1f107b36bf440f89f732e4b46d96d0faa2 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 11 May 2023 19:43:32 +0200
Subject: [PATCH] [gdb/tui] Don't show line number for lines not in source file
---
gdb/testsuite/gdb.tui/compact-source.exp | 2 +-
gdb/tui/tui-source.c | 20 +++++++++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/gdb/testsuite/gdb.tui/compact-source.exp b/gdb/testsuite/gdb.tui/compact-source.exp
index f972d961d72..59e858a503f 100644
--- a/gdb/testsuite/gdb.tui/compact-source.exp
+++ b/gdb/testsuite/gdb.tui/compact-source.exp
@@ -64,7 +64,7 @@ foreach_with_prefix src_window_size {7 8} {
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_"
+ set re_left_margin "___4_"
} else {
error "unhandled max_line_nr_in_source_window"
}
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 9d0376000de..57f9a62c659 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,8 @@ 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
+ cur_line_no = -1;
/* Set whether element is the execution point
and whether there is a break point on it. */
@@ -233,11 +235,19 @@ 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)
+ {
+ 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: 38b95a529385e32adc39428231c6fc8b0e8d6f21
--
2.35.3
next prev parent reply other threads:[~2023-05-11 17:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 13:21 Tom de Vries
2023-05-10 15:28 ` Tom Tromey
2023-05-11 14:55 ` Simon Marchi
2023-05-11 17:45 ` Tom de Vries [this message]
2023-05-12 18:40 ` Tom Tromey
2023-05-15 4:03 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99abb8c4-b4c0-337f-1319-48504bf0d14a@suse.de \
--to=tdevries@suse.de \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).