gdb: display a symbol more often in multi-file list output

I noticed that when a command line 'list foo.c:10' displays multiple
files, the symbol would always be shown as "???", e.g.:

  file: "/tmp/foo.c", line number: 10, symbol: "???"

this is because, when the symtab_and_line is created for the
'foo.c:10', the pc and symbol are never filled in.

In this commit, I propose that, when we decide that the above header
line needs to be printed, we should attempt to lookup a symbol for the
relevant line, and if one is found, we can use that.

The symbol lookup is done by first calling find_pc_for_line, and then
using find_symbol_for_pc to find a suitable symbol.

Approved-By: Tom Tromey <tom@tromey.com>
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 43c1bc7..cf5571c 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2182,6 +2182,14 @@ print_sal_location (const symtab_and_line &sal)
   const char *sym_name = NULL;
   if (sal.symbol != NULL)
     sym_name = sal.symbol->print_name ();
+  else if (CORE_ADDR line_pc;
+	   find_pc_for_line (sal.symtab, sal.line, &line_pc))
+    {
+      struct symbol *sym = find_symbol_for_pc (line_pc);
+      if (sym != nullptr)
+	sym_name = sym->print_name ();
+    }
+
   gdb_printf (_("file: \"%ps\", line number: %ps, symbol: \"%s\"\n"),
 	      styled_string (file_name_style.style (),
 			     symtab_to_filename_for_display (sal.symtab)),
diff --git a/gdb/testsuite/gdb.base/list-multi-source.exp b/gdb/testsuite/gdb.base/list-multi-source.exp
index 66f6582..887ff96 100644
--- a/gdb/testsuite/gdb.base/list-multi-source.exp
+++ b/gdb/testsuite/gdb.base/list-multi-source.exp
@@ -97,13 +97,13 @@
 # List using FILE:LINE for a filename that is ambiguous.
 gdb_test "list foo.c:$linenum" \
     [multi_line \
-	 "file: \"\[^\r\n\]+/a/foo.c\", line number: $linenum, symbol: \"\[^\r\n\]+\"" \
+	 "file: \"\[^\r\n\]+/a/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \
 	 "$first_linenum\\s+\[^\r\n\]+" \
 	 ".*" \
 	 "$linenum\\s+[string_to_regexp {return 3;	/* List this line.  */}]" \
 	 ".*" \
 	 "$last_linenum\\s+\[^\r\n\]+" \
-	 "file: \"\[^\r\n\]+/b/foo.c\", line number: $linenum, symbol: \"\[^\r\n\]+\"" \
+	 "file: \"\[^\r\n\]+/b/foo.c\", line number: $linenum, symbol: \"get_value_common\"" \
 	 "$first_linenum\\s+\[^\r\n\]+" \
 	 ".*" \
 	 "$linenum\\s+[string_to_regexp {return -3;	/* List this line.  */}]" \