diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 2f5ce3e5fff..648005ffdfe 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1238,6 +1238,15 @@ list_command (const char *arg, int from_tty) { event_location_up location = string_to_event_location (&arg1, current_language); + + /* We know that the ARG string is not empty, yet the attempt to parse + a location from the string consumed no characters. This most + likely means that the first thing in ARG looks like a location + condition, and so the string_to_event_location call stopped + parsing. */ + if (arg1 == arg) + error (_("Junk at end of line specification.")); + sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE, NULL, NULL, 0); filter_sals (sals); @@ -1286,6 +1295,9 @@ list_command (const char *arg, int from_tty) event_location_up location = string_to_event_location (&arg1, current_language); + if (*arg1) + error (_("Junk at end of line specification.")); + std::vector sals_end = (dummy_beg ? decode_line_1 (location.get (), DECODE_LINE_LIST_MODE, diff --git a/gdb/testsuite/gdb.linespec/errors.exp b/gdb/testsuite/gdb.linespec/errors.exp index 0baef1891a7..e258f6bb98c 100644 --- a/gdb/testsuite/gdb.linespec/errors.exp +++ b/gdb/testsuite/gdb.linespec/errors.exp @@ -27,3 +27,15 @@ gdb_test "list c:/foo/bar/baz.c:1" "No source file named c:/foo/bar/baz.c." gdb_test "list c:/foo/bar/baz.c" "Function \"c:/foo/bar/baz.c\" not defined." gdb_test "list fooc:/foo/bar/baz.c:1" "No source file named fooc." gdb_test "list fooc:/foo/bar/baz.c" "No source file named fooc." + +# PR cli/28665, gdb/28797 +gdb_test "list task 123" \ + "Junk at end of line specification\\." +gdb_test "list if (0)" \ + "Junk at end of line specification\\." +gdb_test "list thread 1" \ + "Junk at end of line specification\\." +gdb_test "list -force-condition" \ + "Junk at end of line specification\\." +gdb_test "list ,," \ + "Junk at end of line specification\\."