Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sendao Yan <yansendao@126.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>, Andrew Burgess <aburgess@redhat.com>,
	Keith Seitz <keiths@redhat.com>, Simon Marchi <simark@simark.ca>,
	yansendao@126.com
Subject: [PATCH v4 0/1] [gdb/symtab] Add canonical-name aliases for C++ template static members
Date: Mon, 23 Nov 2026 10:09:00 +0800	[thread overview]
Message-ID: <20261123020901.2794477-1-yansendao@126.com> (raw)
In-Reply-To: <20261122120312.52699-1-yansendao@126.com>

Hi Tom, Simon, Andrew, Keith,

This is v4 of the fix for PR symtab/33533 (GCC PR 128817).  v3 was sent
as [PATCH v3 0/1]; v4 supersedes it.  I sent v4 before any human review
of v3 because an automated review of v3 flagged that static member
functions have the same spelling mismatch, and I confirmed that
gdb.lookup_global_symbol("S<1l>::f") missed in v3.  Sorry for the extra
traffic; the delta is small and is the only change from v3.

Changes since v3:
- canonicalize_names() now also accepts DW_TAG_subprogram linkage
  entries, so static member functions get a canonical alias;
- functions are demangled without DMGL_PARAMS, so the alias is
  S<1l>::f rather than S<1l>::f() and matches the parameter-stripped
  lookup name;
- the test covers a class template with only a static member function
  (call and type lookup, .gdb_index reload, .debug_names emission).

Everything else is unchanged from v3.  Static member functions have the
same DWARF/canonical mismatch as data members: the index has S<1>::f
while the canonical lookup uses S<1l>::f.  In v3 the expression forms
happened to find the function through symtab expansion, but the quick
index returned no symbol for gdb.lookup_global_symbol("S<1l>::f").

Tom, thanks for the pointer to PR 30023/32421 and -gsimple-template-names.
I agree that rebuilding names from the DW_TAG_template_value_parameter
DIEs is the right general direction, and that it is needed anyway for
-gsimple-template-names.  This version does not attempt that general
reconstruction.  It is a targeted fix for the quick-lookup miss, and it
is not fuzzy matching (no strcmp_iw).

What v4 does: for a C++ static data member or static member function,
the cooked index contains the DW_AT_name spelling (with GCC, S<1>::v)
and a separate entry for the linkage name.  v4 adds one synthesized
index entry whose name is the demangled linkage name (S<1l>::v), so the
quick lookup finds the member without expanding symtabs.  Each alias is
derived from the symbol's own linkage name, so T<1> (int) and T<1L>
(long) get different names and are not conflated.  The alias is skipped
when the entry built from DW_AT_name already has the canonical spelling,
as with a clang-built binary.  Only entries whose parent is a type or
namespace are considered.  Only Itanium-mangled (_Z) names with an I...E
argument block are considered.  The alias name is produced with the v3
demangler directly (still through gdb_demangle's crash handler), so
index construction does not depend on the user's current demangle-style.
The demangling and filtering live in cp-support.c, so the index code
stays language-agnostic apart from the language_cplus check.

The comparison uses the DWARF spelling of the DW_AT_name entry (a new
FOR_DWARF_NAME flag) rather than its canonical spelling, because
canonicalize_names runs per shard concurrently and a deferred parent can
belong to a shard that has not been canonicalized yet.  If the DW_AT_name
entry is not adjacent (the index came from .debug_names), the alias is
skipped rather than added without these checks.

The aliases are written to a saved .gdb_index and .debug_names: the
synthesized entry does not carry IS_LINKAGE or IS_SYNTHESIZED, and an
entry is also added for the canonical spelling of each enclosing
template scope (S<1l> for S<1l>::v), because the .gdb_index reader
rebuilds qualified names from their components.  Those scope entries are
parentless and store the full prefix; they are only there for the reader,
which re-splits the name itself.

Why not reconstruct from the DIEs here: the cooked index is built by
scanning raw DWARF with cutu_reader, before die_info trees are created;
dwarf2_compute_name is only usable at symtab-expansion time.  Rebuilding
names in the indexer would mean parsing template parameter DIEs there and
printing values with their C++ literal type (the current
dwarf2_compute_name prints "1" rather than "1l"), which is the larger
-gsimple-template-names work.  I am happy to prototype that as a
follow-up, but it is a much bigger change than this bug fix.

If you would prefer to hold this patch until the general reconstruction
lands, please say so; otherwise I think the guarded alias is a small fix
that keeps the quick lookup authoritative and does not change lookup
semantics.

Testing (x86_64 and aarch64):
- new test gdb.cp/static-const-template.exp: 22 PASS on both; it checks
  the long data member, the canonical spelling, that T<1> (int) and
  T<1L> (long) remain distinct, a member of a template nested in a
  namespace, a static member function found by its canonical spelling,
  saving and reloading a .gdb_index, and alias emission in a DWARF-5
  .debug_names index;
- GCC libstdc++-prettyprinters/chrono.cc: 54/54 PASS on x86_64,
  including -flto (the aarch64 build has no Python, so the
  pretty-printer test was not run there);
- the six targeted .exp files: 248 PASS, 0 FAIL on both;
- gdb.dwarf2/debug-names*.exp: 27 PASS, 0 FAIL on both;
- full gdb.cp suite: x86_64 8783 PASS with 70 pre-existing failures in
  gdb.cp/step-and-next-inline.exp (also with unpatched gdb 16.3);
  aarch64 8914 PASS, 0 unexpected failures (2 unsupported because that
  build has no Python).

Sendao Yan (1):
  [gdb/symtab] Add canonical-name aliases for C++ template static
    members

 gdb/cp-support.c                              |  41 +++++-
 gdb/cp-support.h                              |  12 +-
 gdb/dwarf2/cooked-index-entry.c               |  14 +-
 gdb/dwarf2/cooked-index-entry.h               |   9 ++
 gdb/dwarf2/cooked-index-shard.c               | 125 +++++++++++++++++
 gdb/testsuite/gdb.cp/static-const-template.cc |  69 ++++++++++
 .../gdb.cp/static-const-template.exp          | 129 ++++++++++++++++++
 7 files changed, 389 insertions(+), 10 deletions(-)
 create mode 100644 gdb/testsuite/gdb.cp/static-const-template.cc
 create mode 100644 gdb/testsuite/gdb.cp/static-const-template.exp

--
2.34.1


  parent reply	other threads:[~2026-11-23  2:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:18 [PATCH] [gdb/symtab] Fall back to symtabs when the quick lookup misses 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
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           ` Sendao Yan [this message]
2026-11-23  2:09             ` [PATCH v4 " 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=20261123020901.2794477-1-yansendao@126.com \
    --to=yansendao@126.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    --cc=simark@simark.ca \
    --cc=tom@tromey.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