From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR29573, addr2line doesn't display file/line for local symbols
Date: Wed, 21 Sep 2022 16:11:04 +0930 [thread overview]
Message-ID: <YyqyAIVdwe+Ips8K@squeak.grove.modra.org> (raw)
The DWARF standard is clear that DW_AT_linkage_name is optional.
Compilers may not provide the attribute on functions and variables,
even though the language mangles names. g++ does not for local
variables and functions. Without DW_AT_linkage_name, mangled object
file symbols can't be directly matched against the source-level
DW_AT_name in DWARF info. One possibility is demangling the object
file symbols, but that comes with its own set of problems:
1) A demangler might not be available for the compiler/language.
2) Demangling doesn't give the source function name as stored in
DW_AT_name. Class and template parameters must be stripped at
least.
So this patch takes a simpler approach. A symbol matches DWARF info
if the DWARF address matches the symbol address, and if the symbol
name contains the DWARF name as a sub-string. Very likely the name
matching is entirely superfluous.
PR 29573
* dwarf.c (lookup_symbol_in_function_table): Match a symbol
containing the DWARF source name as a substring.
(lookup_symbol_in_variable_table): Likewise.
(_bfd_dwarf2_find_nearest_line_with_alt): If stash_find_line_fast
returns false, fall back to comp_unit_find_line.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index b8dad5cb3f4..4a6a1e40185 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -3379,7 +3379,7 @@ lookup_symbol_in_function_table (struct comp_unit *unit,
&& arange->high - arange->low < best_fit_len
&& each->file
&& each->name
- && strcmp (name, each->name) == 0)
+ && strstr (name, each->name) != NULL)
{
best_fit = each;
best_fit_len = arange->high - arange->low;
@@ -3415,7 +3415,7 @@ lookup_symbol_in_variable_table (struct comp_unit *unit,
&& !each->stack
&& each->file != NULL
&& each->name != NULL
- && strcmp (name, each->name) == 0)
+ && strstr (name, each->name) != NULL)
break;
if (each)
@@ -5867,25 +5867,23 @@ _bfd_dwarf2_find_nearest_line_with_alt
if (stash->info_hash_status == STASH_INFO_HASH_ON)
{
- found = stash_find_line_fast (stash, symbol, addr, filename_ptr,
- linenumber_ptr);
+ found = stash_find_line_fast (stash, symbol, addr,
+ filename_ptr, linenumber_ptr);
if (found)
goto done;
}
- else
- {
- /* Check the previously read comp. units first. */
- for (each = stash->f.all_comp_units; each; each = each->next_unit)
- if ((symbol->flags & BSF_FUNCTION) == 0
- || each->arange.high == 0
- || comp_unit_contains_address (each, addr))
- {
- found = comp_unit_find_line (each, symbol, addr, filename_ptr,
- linenumber_ptr);
- if (found)
- goto done;
- }
- }
+
+ /* Check the previously read comp. units first. */
+ for (each = stash->f.all_comp_units; each; each = each->next_unit)
+ if ((symbol->flags & BSF_FUNCTION) == 0
+ || each->arange.high == 0
+ || comp_unit_contains_address (each, addr))
+ {
+ found = comp_unit_find_line (each, symbol, addr, filename_ptr,
+ linenumber_ptr);
+ if (found)
+ goto done;
+ }
}
else
{
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2022-09-21 6:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=YyqyAIVdwe+Ips8K@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).