[gdb/tui] Fix tui compact-source a bit more
authorTom de Vries <tdevries@suse.de>
Wed, 10 May 2023 18:11:35 +0000 (20:11 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 10 May 2023 18:11:35 +0000 (20:11 +0200)
commit5a6ad5c775a5836709ee0f97180fd8eef96e9ed5
tree972349af12091f03fc440db5050e8813bec654fa
parent16c8122639ca0948f56fce125b3ad46e122d1edc
[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>
gdb/testsuite/gdb.tui/compact-source.exp
gdb/tui/tui-source.c