Skip to content

Natvis: resolve typedef and base-class type names when rule lookup misses#1606

Open
lugerard wants to merge 3 commits into
microsoft:mainfrom
lugerard:natvis-type-name-resolution
Open

Natvis: resolve typedef and base-class type names when rule lookup misses#1606
lugerard wants to merge 3 commits into
microsoft:mainfrom
lugerard:natvis-type-name-resolution

Conversation

@lugerard

@lugerard lugerard commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

GDB/LLDB report a variable's type under its declared name, so a typedef
alias or a subclass of a visualized type misses the wildcard rule of its
underlying type and falls back to raw struct display.
Commit 1 adds a fallback to FindType: on a miss, ask the debugger to
resolve the name (gdb: whatis/ptype; lldb: type lookup) and retry the
rule lookup. Results are cached per session, and names are validated
before entering a console command.
Commit 2 fixes base-class child classification for lldb, which
reports base-class children with a value where detection expected none;
without it, rules matched through a base class fail to evaluate
inherited members.
Commit 3 adds an end-to-end test: a typedef alias and a subclass in
the natvis debuggee, verified to display through the underlying type's
visualizer.
Verified live on macOS/LLDB; the reply parser is unit-tested against
real gdb 16.3 output.

lugerard added 3 commits July 7, 2026 10:50
GDB/LLDB report a variable's type under its declared name, so a typedef
alias or a subclass of a visualized type misses the wildcard rule of its
underlying type and falls back to raw struct display, even though a
matching rule exists and the debugger may expose no base-class child for
FindType's existing walk.

Add a fallback to FindType: on a miss, ask the debugger to resolve the
name (gdb: whatis/ptype; lldb: type lookup) and retry with the result —
the head type name when the debugger expanded an alias, or the first
base class when the reply names the queried type itself. Results are
cached per session, so each unmatched name costs at most one round of
queries. Extracted names are validated before entering a console
command, the cache or the log.

Add unit tests for the reply parser and the decoration stripper.
Base-class detection required the child to have no value — a gdb
convention. lldb reports base-class children with an aggregate value
("{...}"), so they were classified as plain fields: name substitution
did not search them for inherited members, and their full name produced
an invalid expression. Natvis rules matched through a base class
therefore failed to evaluate on subclass variables.

Fix: additionally classify a child as a base class when its expression
string is identical to its type name and contains '<', ':' or a space,
regardless of the value. Those characters can occur in a type name but
never in a data member's name, which is an identifier — so only
base-class children can match, and no real member can be misclassified.

Known gap: a base whose name is a plain identifier (Derived : Base),
reported by lldb with a value, is still classified as a field —
accepting it would risk misclassifying a member named after its type.
Add a typedef alias and a subclass of a visualized template type to the
natvis debuggee, and verify both display through the underlying type's
visualizer, exercising the full debugger round-trip of the type-name
resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant