Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, Andrew Burgess <aburgess@redhat.com>
Cc: Sendao Yan <yansendao@126.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb/symtab] Fall back to symtabs when the quick lookup misses
Date: Fri, 20 Nov 2026 22:53:16 -0500	[thread overview]
Message-ID: <111d5ee6-2113-408b-8880-e73f2cdf0865@simark.ca> (raw)
In-Reply-To: <87bj7jros1.fsf@tromey.com>

On 11/20/26 7:50 PM, Tom Tromey wrote:
>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
> 
>>> +      /* The cooked index does not necessarily contain every symbol that
>>> +	 the expanded symtabs do.  In particular, GCC emits a DWARF5
>>> +	 DW_TAG_variable for a static constexpr member using the DWARF
>>> +	 spelling of the enclosing template arguments (e.g.
>>> +	 std::ratio<1, 1>), while the C++ expression evaluator looks the
>>> +	 member up using the canonical spelling (std::ratio<1l, 1l>), so
>>> +	 the quick lookup misses it.  Fall back to walking the symtabs,
>>> +	 which was the behaviour before commit 86ac8c546235.
>>> +
>>> +	 PR symtab/33533.  */
>>> +      result = lookup_symbol_in_objfile_symtabs (objfile, block_index,
>>> +						 name, domain);
> 
> I don't think we want to go back to doing this.  I hate to NAK a patch
> but I think I will have to for this one.
> 
> Andrew> My concern here is that if you *rely* on finding symbols in the expanded
> Andrew> symtabs, then the lookup only works if something else first expands the
> Andrew> symtab.  This means we have random bugs where things don't work, then
> Andrew> they'll suddenly start working (once the symtab has expanded).
> 
> ... and this is why.  This was basically the reason for commit
> 86ac8c546235.
> 
> I think the fix has to involve the lookup succeeding in the cooked
> index.
> 
> One question I have is why the name isn't canonicalized in the cooked
> index, or to put it another way, why the C++ expression lookup and the
> cooked index disagree -- since the idea behind canonicalization is that
> there's a single spelling.

I don't know the whole story behind this particular bug, but the
std::ratio<1, 1> vs std::ratio<1l, 1l> thing is:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81932

Strictly speaking, S<1> and S<1l> mean two different types.  One has
an "int" template parameter and the other a "long int" template
parameter.  I don't think it would make sense for them to canonicalize
to the same thing, as (1) the conversion would be lossy and (2) the
type names would become ambiguous.  I think that what we want is... more
approximate/fuzzy matching.

To illustrate the problem again, using the type from the test:

    template<long N> struct S {};

    S<1> s;

 - gcc does not put the integer suffix, so gives it DW_AT_name "S<1>"
 - clang puts the integer suffix, so gives it DW_AT_name "S<1L>"

So the cooked index contains either "S<1>" or "S<1L>", depending on the
compiler.  Knowing this, we want lookups of either "S<1>" or "S<1L>" to
work, because they are both legitimate queries.  How do we achieve that?

It does sound tempting to just canonicalize everything to "S<1>" (i.e.
drop the suffixes), but then what if you have both "S<1>" and "S<1L>" in
your program, how do you differentiate them?  Perhaps it's fine for the
index to store "simplified" names that don't include the suffixes,
but I wouldn't call that a "canonical" name.

If the program contains both "S<1>" and "S<1L>", then I'd want a lookup
of "S<1>" to find the former and a lookup of "S<1L>" to find the latter.
To achieve this, it sounds like we need some ranking system ("this match
is better than this match"), a bit like when looking for the best
function overload to call.  We would therefore need a way to tell the
two types apart.

Admittedly, this is a bit of a corner case, but I believe that if we try
to fix the problem generally, we'll end up with a more robust solution
and less trouble in the long term.

Regarding the DW_AT_names given by gcc: given that they lack potentially
crucial information to know the type of the value parameters, maybe we
should consider rebuilding the names from the
DW_TAG_template_value_parameter DIEs.  Those DIEs point to the exact
type of each parameter, so we could reconstruct "S<1L>".  I think the
path already exists in the DWARF reader, we just don't take it because
it is more expensive and we trust that DW_AT_name is correct.

Simon

  reply	other threads:[~2026-11-21  3:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:18 Sendao Yan
2026-11-20 18:26 ` Andrew Burgess
2026-11-20 19:46   ` Keith Seitz
2026-11-21  0:50   ` Tom Tromey
2026-11-21  3:53     ` Simon Marchi [this message]
2026-11-21 16:31       ` Tom Tromey
2026-11-22 12:03         ` [PATCH v3 0/1] [gdb/symtab] Add canonical-name aliases for C++ template static members Sendao Yan
2026-11-22 12:03           ` [PATCH v3 1/1] " Sendao Yan
2026-11-23  2:09           ` [PATCH v4 0/1] " Sendao Yan
2026-11-23  2:09             ` [PATCH v4 1/1] " Sendao Yan
2026-11-21 14:59 ` [PATCH v2] " Sendao Yan
2026-11-21 15:07   ` Sendao Yan

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=111d5ee6-2113-408b-8880-e73f2cdf0865@simark.ca \
    --to=simark@simark.ca \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    --cc=yansendao@126.com \
    /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