+2017-09-04  Pedro Alves  <palves@redhat.com>
+
+       * cli/cli-cmds.c (edit_command): Pass message to
+       ambiguous_line_spec.
+       (list_command): Pass message to ambiguous_line_spec.  Say
+       "first"/"last" instead of "start" and "end" to be consistent with
+       the manual.
+       (ambiguous_line_spec): Add 'format' and vararg parameters.  Use
+       them to print formatted message.
+
 2017-09-04  Pedro Alves  <palves@redhat.com>
 
        * btrace.c (ftrace_add_pt): Pass btrace_insn to
 
 
 /* Prototypes for local utility functions */
 
-static void ambiguous_line_spec (struct symtabs_and_lines *);
+static void ambiguous_line_spec (struct symtabs_and_lines *,
+                                const char *format, ...)
+  ATTRIBUTE_PRINTF (2, 3);
 
 static void filter_sals (struct symtabs_and_lines *);
 
        }
       if (sals.nelts > 1)
        {
-         ambiguous_line_spec (&sals);
+         ambiguous_line_spec (&sals,
+                              _("Specified line is ambiguous:\n"));
          xfree (sals.sals);
          return;
        }
   for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
   linenum_beg = (p == arg1);
 
+  /* Save the range of the first argument, in case we need to let the
+     user know it was ambiguous.  */
+  const char *beg = arg;
+  size_t beg_len = arg1 - beg;
+
   while (*arg1 == ' ' || *arg1 == '\t')
     arg1++;
   if (*arg1 == ',')
       no_end = 0;
       if (sals.nelts > 1)
        {
-         ambiguous_line_spec (&sals);
+         ambiguous_line_spec (&sals,
+                              _("Specified first line '%.*s' is ambiguous:\n"),
+                              (int) beg_len, beg);
          xfree (sals.sals);
          return;
        }
        dummy_end = 1;
       else
        {
+         /* Save the last argument, in case we need to let the user
+            know it was ambiguous.  */
+         const char *end_arg = arg1;
+
          event_location_up location
            = string_to_event_location (&arg1, current_language);
          if (dummy_beg)
            }
          if (sals_end.nelts > 1)
            {
-             ambiguous_line_spec (&sals_end);
+             ambiguous_line_spec (&sals_end,
+                                  _("Specified last line '%s' is ambiguous:\n"),
+                                  end_arg);
              xfree (sals_end.sals);
              xfree (sals.sals);
              return;
 
   if (!no_end && !dummy_beg && !dummy_end
       && sal.symtab != sal_end.symtab)
-    error (_("Specified start and end are in different files."));
+    error (_("Specified first and last lines are in different files."));
   if (dummy_beg && dummy_end)
     error (_("Two empty args do not say what lines to list."));
 
 /* Print a list of files and line numbers which a user may choose from
    in order to list a function which was specified ambiguously (as
    with `list classname::overloadedfuncname', for example).  The
-   vector in SALS provides the filenames and line numbers.  */
+   vector in SALS provides the filenames and line numbers.  FORMAT is
+   a printf-style format string used to tell the user what was
+   ambiguous.  */
 
 static void
-ambiguous_line_spec (struct symtabs_and_lines *sals)
+ambiguous_line_spec (struct symtabs_and_lines *sals, const char *format, ...)
 {
   int i;
 
+  va_list ap;
+  va_start (ap, format);
+  vprintf_filtered (format, ap);
+  va_end (ap);
+
   for (i = 0; i < sals->nelts; ++i)
     printf_filtered (_("file: \"%s\", line number: %d\n"),
                     symtab_to_filename_for_display (sals->sals[i].symtab),
 
+2017-09-04  Pedro Alves  <palves@redhat.com>
+
+       * gdb.base/list-ambiguous.exp: New file.
+       * gdb.base/list-ambiguous0.c: New file.
+       * gdb.base/list-ambiguous1.c: New file.
+       * gdb.base/list.exp (test_list_range): Adjust expected output.
+
 2017-08-31  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        * gdb.base/share-env-with-gdbserver.c: New file.
 
--- /dev/null
+# Copyright 2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the "list" command with linespecs that expand to multiple
+# locations.
+
+standard_testfile list-ambiguous0.c list-ambiguous1.c
+
+if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
+        {debug}]} {
+    return -1
+}
+
+# Build source listing pattern based on an inclusive line range.
+
+proc line_range_pattern { range_start range_end } {
+    global line_re
+
+    for {set i $range_start} {$i <= $range_end} {incr i} {
+       append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
+    }
+
+    verbose -log "pattern $pattern"
+    return $pattern
+}
+
+# Test the "list" command with linespecs that expand to multiple
+# locations.
+
+proc test_list_ambiguous_function {} {
+    global srcfile srcfile2
+
+    set lineno0 [gdb_get_line_number "ambiguous (void)" $srcfile]
+    set lineno1 [gdb_get_line_number "ambiguous (void)" $srcfile2]
+    set lines0_re [line_range_pattern [expr $lineno0 - 5] [expr $lineno0 + 4]]
+    set lines1_re [line_range_pattern [expr $lineno1 - 5] [expr $lineno1 + 4]]
+
+    set any "\[^\r\n\]*"
+    set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0"
+    set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1"
+    gdb_test "list ambiguous" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}"
+
+    gdb_test "list main,ambiguous" \
+       "Specified last line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+    gdb_test "list ,ambiguous" \
+       "Specified last line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+    gdb_test "list ambiguous,main" \
+       "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+    gdb_test "list ambiguous,ambiguous" \
+       "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+    gdb_test "list ambiguous," \
+       "Specified first line 'ambiguous' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+
+    # While at it, test the "edit" command as well, since it shares
+    # code with "list".
+    gdb_test "edit ambiguous" \
+       "Specified line is ambiguous:\r\n${h0_re}\r\n${h1_re}"
+}
+
+gdb_test_no_output "set listsize 10"
+
+test_list_ambiguous_function
 
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2017 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+
+
+
+/* This function is defined in both
+   list-ambiguous0.c/list-ambiguous1.c files, in order to test
+   "list"'s behavior with ambiguous linespecs.  */
+
+static void __attribute__ ((used)) ambiguous (void) {}
+
+
+
+
+
+
+
+
+
+
+int
+main (void)
+{
+  return 0;
+}
 
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2017 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+
+
+
+
+
+
+
+
+/* This function is defined in both
+   list-ambiguous0.c/list-ambiguous1.c files, in order to test
+   "list"'s behavior with ambiguous linespecs.  */
+static void __attribute__ ((used)) ambiguous (void) {}
+
+
+
+
+
+
+
+
+
+
+/* last line */
 
 
     gdb_test "list ${past_end},${much_past_end}" "Line number ${past_end} out of range; .*list0.c has ${last_line} lines." "list range; both bounds past EOF"
 
-    gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
+    gdb_test "list list0.c:2,list1.c:17" "Specified first and last lines are in different files." "list range, must be same files"
 }
 
 #