gdb/cli: Improve UX when using list with no args

When using "list" with no arguments, GDB will first print the lines
around where the inferior is stopped, then print the next N lines until
reaching the end of file, at which point it warns the user "Line X out
of range, file Y only has X-1 lines.".  This is usually desirable, but
if the user can no longer see the original line, they may have forgotten
the current line or that a list command was used at all, making GDB's
error message look cryptic. It was reported in bugzilla as PR cli/30497.

This commit improves the user experience by changing the behavior of
"list" slightly when a user passes no arguments.  It now prints that the
end of the file has been reached and recommends that the user use the
command "list ." instead.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30497
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Bruno Larsen
2023-06-15 11:17:07 +02:00
parent 3e3a1874fc
commit f52625f1f2
6 changed files with 48 additions and 9 deletions

View File

@ -1484,6 +1484,22 @@ print_source_lines (struct symtab *s, source_lines_range line_range,
line_range.stopline (), flags);
}
/* See source.h. */
int
last_symtab_line (struct symtab *s)
{
const std::vector<off_t> *offsets;
/* Try to get the offsets for the start of each line. */
if (!g_source_cache.get_line_charpos (s, &offsets))
return false;
if (offsets == nullptr)
return false;
return offsets->size ();
}
/* Print info on range of pc's in a specified line. */