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 v3 0/1] [gdb/symtab] Add canonical-name aliases for C++ template static members
Date: Sun, 22 Nov 2026 20:03:11 +0800 [thread overview]
Message-ID: <20261122120312.52699-1-yansendao@126.com> (raw)
In-Reply-To: <874idarvrz.fsf@tromey.com>
Hi Tom, Simon, Andrew, Keith,
This is v3 of the fix for PR symtab/33533 (GCC PR 128817), where the
libstdc++ chrono pretty-printer reports a static constexpr member as
<optimized out>.
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 v3 does: for a C++ static data member, the cooked index contains the
DW_AT_name spelling (with GCC, S<1>::v) and a separate entry for the
linkage name. v3 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, which
excludes function-local statics. 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. 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.
The aliases are written to a saved .gdb_index: 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. Because the alias is not IS_SYNTHESIZED, it is also written by
save gdb-index -dwarf-5 and survives a .debug_names reload.
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:
- new test gdb.cp/static-const-template.exp: 18 PASS; it checks the long
member, the canonical spelling, that T<1> (int) and T<1L> (long)
remain distinct (whatis reports const int vs const long), a member of
a template nested in a namespace, that the canonical spellings survive
saving and reloading a .gdb_index, and that the alias is emitted in a
DWARF-5 .debug_names index;
- GCC libstdc++-prettyprinters/chrono.cc: 54/54 PASS, including -flto;
- gdb.cp/static-const-template.exp, gdb.dwarf2/static-const-member.exp,
gdb.dwarf2/forward-spec-inter-cu.exp, gdb.cp/m-static.exp,
gdb.cp/namespace.exp and gdb.base/condbreak-multi-context.exp:
244 PASS, 0 FAIL;
- gdb.dwarf2/debug-names*.exp: 27 PASS, 0 FAIL;
- full gdb.cp suite: 8779 PASS and 70 failures, all in
gdb.cp/step-and-next-inline.exp. Unpatched gdb 16.3 fails the same
way, so this is a testsuite/compiler environment issue.
Sendao Yan (1):
[gdb/symtab] Add canonical-name aliases for C++ template static
members
gdb/cp-support.c | 40 +++++-
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 | 124 ++++++++++++++++++
gdb/testsuite/gdb.cp/static-const-template.cc | 58 ++++++++
.../gdb.cp/static-const-template.exp | 118 +++++++++++++++++
7 files changed, 365 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
next prev parent reply other threads:[~2026-11-22 12:04 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 ` Sendao Yan [this message]
2026-11-22 12:03 ` [PATCH v3 1/1] [gdb/symtab] Add canonical-name aliases for C++ template static members 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=20261122120312.52699-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