Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 2/2] gdb: display a symbol more often in multi-file list output
Date: Tue, 18 Nov 2025 10:28:53 +0000	[thread overview]
Message-ID: <b0d184d030ca111c6adb6a857f7184913ea1dc29.1763461561.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1763461561.git.aburgess@redhat.com>

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.
---
 gdb/cli/cli-cmds.c                           | 8 ++++++++
 gdb/testsuite/gdb.base/list-multi-source.exp | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 300b77dbafe..4534c670730 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2174,6 +2174,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: \"%s\", line number: %ps, symbol: \"%s\"\n"),
 	      symtab_to_filename_for_display (sal.symtab),
 	      styled_string (line_number_style.style (),
diff --git a/gdb/testsuite/gdb.base/list-multi-source.exp b/gdb/testsuite/gdb.base/list-multi-source.exp
index 7809167bd0f..33bd49ad14b 100644
--- a/gdb/testsuite/gdb.base/list-multi-source.exp
+++ b/gdb/testsuite/gdb.base/list-multi-source.exp
@@ -63,13 +63,13 @@ set last_linenum [expr {$linenum + 4}]
 # 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.  */}]" \
-- 
2.47.1


  parent reply	other threads:[~2025-11-18 10:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 10:28 [PATCH 0/2] Fix regression in 'list' command Andrew Burgess
2025-11-18 10:28 ` [PATCH 1/2] gdb: fix 'list' for multiple source file results Andrew Burgess
2025-11-18 10:42   ` Andreas Schwab
2025-11-18 14:28     ` Andrew Burgess
2025-11-18 10:28 ` Andrew Burgess [this message]
2025-11-19 10:32 ` [PATCHv2 0/2] Fix regression in 'list' command Andrew Burgess
2025-11-19 10:32   ` [PATCHv2 1/2] gdb: fix 'list' for multiple source file results Andrew Burgess
2025-12-04 16:48     ` Tom Tromey
2025-12-05 10:50       ` Andrew Burgess
2025-12-04 20:18     ` Kevin Buettner
2025-12-05  7:14       ` Eli Zaretskii
2025-11-19 10:32   ` [PATCHv2 2/2] gdb: display a symbol more often in multi-file list output Andrew Burgess
2025-12-04 16:53     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0d184d030ca111c6adb6a857f7184913ea1dc29.1763461561.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox