diff options
author | Tom de Vries <tdevries@suse.de> | 2023-05-10 20:11:35 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-05-10 20:11:35 +0200 |
commit | 5a6ad5c775a5836709ee0f97180fd8eef96e9ed5 (patch) | |
tree | 972349af12091f03fc440db5050e8813bec654fa /gdb/tui | |
parent | 16c8122639ca0948f56fce125b3ad46e122d1edc (diff) | |
download | gdb-5a6ad5c775a5836709ee0f97180fd8eef96e9ed5.zip gdb-5a6ad5c775a5836709ee0f97180fd8eef96e9ed5.tar.gz gdb-5a6ad5c775a5836709ee0f97180fd8eef96e9ed5.tar.bz2 |
[gdb/tui] Fix tui compact-source a bit more
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 <aburgess@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/tui')
-rw-r--r-- | gdb/tui/tui-source.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 1233e94..9d03760 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; |