From 3b2464a8d39b8b787664438253b8fdf7625cac32 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Mon, 16 Nov 2015 09:39:43 +0000 Subject: [PATCH] gdb: Add an error when 'list -' reaches the start of a file. When a a user uses 'list +' to list forward through a source file they eventually reach the end of the source file. Subsequent uses of 'list +' result in an error message like this, that let the user know they are at the end of the source file: Line number XXX out of range; FILENAME has YYY lines. Compare this to the current behaviour of 'list -' which lists backwards through a source file. When the user reaches the beginning of the source file, subsequent uses of 'list -' result in the command silently returning. This can be confusing if the previous uses of 'list -' have scrolled off the users display, the user receives no reminder that the have already seen the start of the file. After this commit a use of 'list -' when the user has already seen the start of a file will receive the following error: Already at the start of FILENAME. gdb/ChangeLog: * cli/cli-cmds.c (list_command): Add an error when trying to use '-' to scan read off the start of the source file. gdb/testsuite/ChangeLog: * gdb.base/list.exp (test_list_forward): Add end of file error test. (test_repeat_list_command): Add end of file error test. (test_list_backwards): Add beginning of file error test. --- gdb/ChangeLog | 5 +++++ gdb/cli/cli-cmds.c | 13 +++++++++---- gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.base/list.exp | 12 ++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 970bea2cd5f..960a304917c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-12-11 Andrew Burgess + + * cli/cli-cmds.c (list_command): Add an error when trying to use + '-' to scan read off the start of the source file. + 2015-12-11 Andrew Burgess * cli/cli-cmds.c (list_command): Check that the argument string is diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 4557bfd66ac..a6935bf658c 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -940,10 +940,15 @@ list_command (char *arg, int from_tty) /* "l -" lists previous ten lines, the ones before the ten just listed. */ else if (arg[0] == '-') - print_source_lines (cursal.symtab, - max (get_first_line_listed () - - get_lines_to_list (), 1), - get_first_line_listed (), 0); + { + if (get_first_line_listed () == 1) + error (_("Already at the start of %s."), + symtab_to_filename_for_display (cursal.symtab)); + print_source_lines (cursal.symtab, + max (get_first_line_listed () + - get_lines_to_list (), 1), + get_first_line_listed (), 0); + } return; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8c7af55d8ff..df8c76833ad 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2015-12-11 Andrew Burgess + + * gdb.base/list.exp (test_list_forward): Add end of file error + test. + (test_repeat_list_command): Add end of file error test. + (test_list_backwards): Add beginning of file error test. + 2015-12-11 Andrew Burgess * gdb.base/list.exp (test_list_invalid_args): New function, diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp index cac3a626ad3..18b7d4f22e5 100644 --- a/gdb/testsuite/gdb.base/list.exp +++ b/gdb/testsuite/gdb.base/list.exp @@ -244,6 +244,10 @@ proc test_list_forward {} { } pass "successive list commands to page forward ($testcnt tests)" + + gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \ + "end of file error after \"list\" command" + gdb_stop_suppressing_tests } @@ -287,6 +291,10 @@ proc test_repeat_list_command {} { } pass "repeat list commands to page forward using 'return' ($testcnt tests)" + + gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \ + "end of file error after using 'return' to repeat the list command" + gdb_stop_suppressing_tests } @@ -324,6 +332,10 @@ proc test_list_backwards {} { } pass "$testcnt successive \"list -\" commands to page backwards" + + gdb_test "list -" "Already at the start of .*\." \ + "beginning of file error after \"list -\" command" + gdb_stop_suppressing_tests } -- 2.30.2