Natvis: resolve typedef and base-class type names when rule lookup misses#1606
Open
lugerard wants to merge 3 commits into
Open
Natvis: resolve typedef and base-class type names when rule lookup misses#1606lugerard wants to merge 3 commits into
lugerard wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.