-
-
Notifications
You must be signed in to change notification settings - Fork 755
godot-cpp.natvis debug visualizers #1977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
van800
wants to merge
5
commits into
godotengine:master
Choose a base branch
from
van800:shakhov/natvis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d0ad91
copy of godot.natvis from master
van800 da3c4a3
Remove unused entries (godotengine original types)
van800 8a9a174
add support for evaluating godot::Variant, godot::Array and godot::Di…
van800 8648636
improve dictionary presentation
van800 4d1b17e
update developer notes and reformat file
van800 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> | ||
| <Type Name="godot::String"> | ||
| <DisplayString>{*reinterpret_cast<void**>(opaque),s32}</DisplayString> | ||
| <Expand> | ||
| <Item Name="opaque_ptr">*reinterpret_cast<void**>(opaque)</Item> | ||
| <Item Name="string">*reinterpret_cast<void**>(opaque),s32</Item> | ||
| </Expand> | ||
| </Type> | ||
|
|
||
| <Type Name="godot::StringName"> | ||
| <Intrinsic Name="get_data_ptr" Expression="(*reinterpret_cast<const char32_t***>(opaque))[1]" /> | ||
| <DisplayString Condition="get_data_ptr()">{get_data_ptr(),s32}</DisplayString> | ||
| <Expand> | ||
| <Item Name="opaque_ptr">*reinterpret_cast<void**>(opaque)</Item> | ||
| <Item Name="cname">get_data_ptr(),s32</Item> | ||
| </Expand> | ||
| </Type> | ||
|
|
||
| <!-- Development notes: At the current state no AI can directly generate a natvis entry for each `godot::` type. | ||
| The testdata used for evaluation https://github.com/JetBrains/godot-support/wiki/Developing-godot%E2%80%90cpp.natvis | ||
| The change of the memory layout would require adjustments of the natvis | ||
|
|
||
| Approach: | ||
| 1. For each type, inspect `opaque` bytes in LLDB using `memory read -size 8 -count N -format address` on | ||
| the address stored in opaque (e.g. `*(void**)demo_type.opaque`) to map the actual field layout. | ||
| 2. Verify specific field values match known test data (e.g. array size=1, int value=42, string content). | ||
| 3. Write natvis expressions only after the field offsets are confirmed. | ||
|
|
||
| Evaluator constraints (JetBrains natvis engine, I haven't checked anything else): | ||
|
van800 marked this conversation as resolved.
Outdated
|
||
| - Supports: reinterpret_cast, pointer arithmetic on built-in types, array indexing ([n]), Intrinsics | ||
| - Does NOT support: calling member functions (e.g. size()) | ||
| - Nested type visualizers work: `{*(godot::String*)(opaque+8)}` delegates to the String natvis entry | ||
|
|
||
| Patterns used: | ||
| - Opaque wrapper types (String, StringName, Array, Dictionary, ...): cast opaque slice to the | ||
| godot-cpp type pointer — `*(godot::TypeName*)(opaque+N)` — and let that type's natvis handle display | ||
| - Engine heap-allocated types stored as pointer (Transform2D, AABB, Basis, ...): double-deref — | ||
| `**(godot::TypeName**)(opaque+N)` | ||
| - Engine internals without a godot-cpp wrapper (ArrayPrivate, CowData, HashMap): use raw | ||
| reinterpret_cast + index arithmetic, document offsets with a comment verified by LLDB | ||
|
|
||
| Future upcomming improvements: | ||
| - JetBrains natvis support is going to become x-plat https://youtrack.jetbrains.com/issue/CPP-35297 | ||
|
van800 marked this conversation as resolved.
Outdated
|
||
| --> | ||
|
|
||
| <!-- opaque[0..7] holds ArrayPrivate*. Dereference as unsigned long long* to read ArrayPrivate | ||
| fields as 8-byte slots: [0]=refcount, [1]=unknown, [2]=_cowdata._ptr, [3]=read_only, ... | ||
| Index [2] reaches _cowdata._ptr at offset +16 (verified by LLDB memory dump). | ||
| Cast _ptr to unsigned long long* so [-1] reads the CowData element count 8 bytes before data. --> | ||
| <Type Name="godot::Array"> | ||
| <Intrinsic Name="_cow" Expression="(unsigned long long*)(*reinterpret_cast<unsigned long long**>(opaque))[2]" /> | ||
| <DisplayString Condition="!*reinterpret_cast<void**>(opaque) || !_cow()">{{empty}}</DisplayString> | ||
| <DisplayString>{{size={_cow()[-1]}}}</DisplayString> | ||
| <Expand> | ||
| <Item Name="[size]">_cow()[-1]</Item> | ||
| <ArrayItems> | ||
| <Size>_cow()[-1]</Size> | ||
| <ValuePointer>(godot::Variant*)_cow()</ValuePointer> | ||
| </ArrayItems> | ||
| </Expand> | ||
| </Type> | ||
|
|
||
| <!-- DictionaryPrivate layout (verified by LLDB console): | ||
| [refcount(4)][unknown(4)][read_only(8)][HashMap at +16] | ||
| HashMap: [_elements(8)][unknown(8)][_head(8)][_last(8)][_capacity_index(4)][_num_elements(4)] | ||
| HashMapElement: [next(8)][prev(8)][key:Variant(24)][value:Variant(24)] --> | ||
| <Type Name="godot::Dictionary"> | ||
| <Intrinsic Name="_p" Expression="*reinterpret_cast<unsigned char**>(opaque)" /> | ||
| <Intrinsic Name="_size" Expression="*(unsigned int*)(_p() + 52)" /> | ||
| <Intrinsic Name="_head" Expression="*reinterpret_cast<unsigned char**>(_p() + 32)" /> | ||
| <DisplayString Condition="!_p()">{{empty}}</DisplayString> | ||
| <DisplayString>{{size={_size()}}}</DisplayString> | ||
| <Expand> | ||
| <Item Name="[size]">_size()</Item> | ||
| <CustomListItems MaxItemsPerView="5000"> | ||
| <Variable Name="elem" InitialValue="(unsigned char*)_head()"/> | ||
| <Variable Name="idx" InitialValue="0"/> | ||
| <Loop Condition="elem != 0"> | ||
| <Item Name="[{idx}].key">*(godot::Variant*)(elem + 16)</Item> | ||
| <Item Name="[{idx}].value">*(godot::Variant*)(elem + 40)</Item> | ||
| <Exec>elem = *(unsigned char**)elem</Exec> | ||
| <Exec>idx++</Exec> | ||
| </Loop> | ||
| </CustomListItems> | ||
| </Expand> | ||
| </Type> | ||
|
|
||
| <!-- Variant::Type enum: | ||
| NIL=0 BOOL=1 INT=2 FLOAT=3 STRING=4 VECTOR2=5 VECTOR2I=6 RECT2=7 RECT2I=8 | ||
| VECTOR3=9 VECTOR3I=10 TRANSFORM2D=11 VECTOR4=12 VECTOR4I=13 PLANE=14 | ||
| QUATERNION=15 AABB=16 BASIS=17 TRANSFORM3D=18 PROJECTION=19 COLOR=20 | ||
| STRING_NAME=21 NODE_PATH=22 RID=23 OBJECT=24 CALLABLE=25 SIGNAL=26 | ||
| DICTIONARY=27 ARRAY=28 | ||
| Layout: opaque[0..3]=type(int32), opaque[4..7]=pad, opaque[8..23]=_data union --> | ||
| <Type Name="godot::Variant"> | ||
| <Intrinsic Name="_type" Expression="*reinterpret_cast<int*>(opaque)" /> | ||
| <DisplayString Condition="_type() == 0">nil</DisplayString> | ||
| <DisplayString Condition="_type() == 1">{*reinterpret_cast<bool*>(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 2">{*reinterpret_cast<long long*>(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 3">{*reinterpret_cast<double*>(opaque+8)}</DisplayString> | ||
| <!-- inline types: stored directly in _data._mem at opaque+8 --> | ||
| <DisplayString Condition="_type() == 4">{*(godot::String*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 5">{*(godot::Vector2*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 6">{*(godot::Vector2i*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 7">{*(godot::Rect2*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 8">{*(godot::Rect2i*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 9">{*(godot::Vector3*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 10">{*(godot::Vector3i*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 12">{*(godot::Vector4*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 13">{*(godot::Vector4i*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 14">{*(godot::Plane*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 15">{*(godot::Quaternion*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 20">{*(godot::Color*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 21">{*(godot::StringName*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 22">{*(godot::NodePath*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 23">{*(godot::RID*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 25">{*(godot::Callable*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 26">{*(godot::Signal*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 27">{*(godot::Dictionary*)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 28">{*(godot::Array*)(opaque+8)}</DisplayString> | ||
| <!-- heap-allocated types: opaque+8 holds a pointer, double-deref required --> | ||
| <DisplayString Condition="_type() == 11">{**(godot::Transform2D**)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 16">{**(godot::AABB**)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 17">{**(godot::Basis**)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 18">{**(godot::Transform3D**)(opaque+8)}</DisplayString> | ||
| <DisplayString Condition="_type() == 19">{**(godot::Projection**)(opaque+8)}</DisplayString> | ||
| <!-- OBJECT: opaque+8=ObjectID, opaque+16=Object* --> | ||
| <DisplayString Condition="_type() == 24">Object(id={*reinterpret_cast<unsigned long long*>(opaque+8)})</DisplayString> | ||
| <DisplayString>{{type={_type()}}}</DisplayString> | ||
| <Expand> | ||
| <Item Name="[type]">_type()</Item> | ||
| <ExpandedItem Condition="_type() == 4">*(godot::String*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 5">*(godot::Vector2*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 6">*(godot::Vector2i*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 7">*(godot::Rect2*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 8">*(godot::Rect2i*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 9">*(godot::Vector3*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 10">*(godot::Vector3i*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 11">**(godot::Transform2D**)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 12">*(godot::Vector4*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 13">*(godot::Vector4i*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 14">*(godot::Plane*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 15">*(godot::Quaternion*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 16">**(godot::AABB**)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 17">**(godot::Basis**)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 18">**(godot::Transform3D**)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 19">**(godot::Projection**)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 20">*(godot::Color*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 21">*(godot::StringName*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 22">*(godot::NodePath*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 23">*(godot::RID*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 25">*(godot::Callable*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 26">*(godot::Signal*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 27">*(godot::Dictionary*)(opaque+8)</ExpandedItem> | ||
| <ExpandedItem Condition="_type() == 28">*(godot::Array*)(opaque+8)</ExpandedItem> | ||
| </Expand> | ||
| </Type> | ||
| </AutoVisualizer> | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.