Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions natvis/godot-cpp.natvis
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&lt;void**&gt;(opaque),s32}</DisplayString>
<Expand>
<Item Name="opaque_ptr">*reinterpret_cast&lt;void**&gt;(opaque)</Item>
<Item Name="string">*reinterpret_cast&lt;void**&gt;(opaque),s32</Item>
</Expand>
</Type>

<Type Name="godot::StringName">
<Intrinsic Name="get_data_ptr" Expression="(*reinterpret_cast&lt;const char32_t***&gt;(opaque))[1]" />
<DisplayString Condition="get_data_ptr()">{get_data_ptr(),s32}</DisplayString>
<Expand>
<Item Name="opaque_ptr">*reinterpret_cast&lt;void**&gt;(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.
Comment thread
van800 marked this conversation as resolved.
Outdated
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):
Comment thread
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
Comment thread
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&lt;unsigned long long**&gt;(opaque))[2]" />
<DisplayString Condition="!*reinterpret_cast&lt;void**&gt;(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&lt;unsigned char**&gt;(opaque)" />
<Intrinsic Name="_size" Expression="*(unsigned int*)(_p() + 52)" />
<Intrinsic Name="_head" Expression="*reinterpret_cast&lt;unsigned char**&gt;(_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&lt;int*&gt;(opaque)" />
<DisplayString Condition="_type() == 0">nil</DisplayString>
<DisplayString Condition="_type() == 1">{*reinterpret_cast&lt;bool*&gt;(opaque+8)}</DisplayString>
<DisplayString Condition="_type() == 2">{*reinterpret_cast&lt;long long*&gt;(opaque+8)}</DisplayString>
<DisplayString Condition="_type() == 3">{*reinterpret_cast&lt;double*&gt;(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&lt;unsigned long long*&gt;(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>
Loading