Skip to content

Commit 1a30823

Browse files
committed
Improvements to NatVis support
NatVis files describe how to display types in some Windows debuggers, such as Visual Studio, WinDbg, and VS Code. This commit makes several improvements: * Adds visualizers for Rc<T>, Weak<T>, and Arc<T>. * Changes [size] to [len], for consistency with the Rust API. Visualizers often use [size] to mirror the size() method on C++ STL collections. * Several visualizers used the PVOID and ULONG typedefs. These are part of the Windows API; they are not guaranteed to always be defined in a pure Rust DLL/EXE. I converted PVOID to `void*` and `ULONG` to `unsigned long`. * Cosmetic change: Removed {} braces around the visualized display for `Option` types. They now display simply as `Some(value)` or `None`, which reflects what is written in source code. * The visualizer for `alloc::string::String` makes assumptions about the layout of `String` (it casts `String*` to another type), rather than using symbolic expressions. This commit changes the visualizer so that it simply uses symbolic expressions to access the string data and string length.
1 parent 11c94a1 commit 1a30823

File tree

4 files changed

+59
-39
lines changed

4 files changed

+59
-39
lines changed

src/etc/natvis/intrinsic.natvis

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
<DisplayString>{data_ptr,[length]s8}</DisplayString>
55
<StringView>data_ptr,[length]s8</StringView>
66
<Expand>
7-
<Item Name="[size]" ExcludeView="simple">length</Item>
8-
<ArrayItems>
9-
<Size>length</Size>
10-
<ValuePointer>data_ptr</ValuePointer>
11-
</ArrayItems>
7+
<Item Name="[len]" ExcludeView="simple">length</Item>
8+
<Synthetic Name="[chars]">
9+
<Expand>
10+
<ArrayItems>
11+
<Size>length</Size>
12+
<ValuePointer>data_ptr</ValuePointer>
13+
</ArrayItems>
14+
</Expand>
15+
</Synthetic>
1216
</Expand>
1317
</Type>
1418
<Type Name="slice&lt;*&gt;">
15-
<DisplayString>{{ length={length} }}</DisplayString>
19+
<DisplayString>{{ len={length} }}</DisplayString>
1620
<Expand>
17-
<Item Name="[size]" ExcludeView="simple">length</Item>
21+
<Item Name="[len]" ExcludeView="simple">length</Item>
1822
<ArrayItems>
1923
<Size>length</Size>
2024
<ValuePointer>data_ptr</ValuePointer>

src/etc/natvis/liballoc.natvis

+34-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
33
<Type Name="alloc::vec::Vec&lt;*&gt;">
4-
<DisplayString>{{ size={len} }}</DisplayString>
4+
<DisplayString>{{ len={len} }}</DisplayString>
55
<Expand>
6-
<Item Name="[size]" ExcludeView="simple">len</Item>
6+
<Item Name="[len]" ExcludeView="simple">len</Item>
77
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
88
<ArrayItems>
99
<Size>len</Size>
@@ -12,9 +12,9 @@
1212
</Expand>
1313
</Type>
1414
<Type Name="alloc::collections::vec_deque::VecDeque&lt;*&gt;">
15-
<DisplayString>{{ size={tail &lt;= head ? head - tail : buf.cap - tail + head} }}</DisplayString>
15+
<DisplayString>{{ len={tail &lt;= head ? head - tail : buf.cap - tail + head} }}</DisplayString>
1616
<Expand>
17-
<Item Name="[size]" ExcludeView="simple">tail &lt;= head ? head - tail : buf.cap - tail + head</Item>
17+
<Item Name="[len]" ExcludeView="simple">tail &lt;= head ? head - tail : buf.cap - tail + head</Item>
1818
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
1919
<CustomListItems>
2020
<Variable Name="i" InitialValue="tail" />
@@ -31,7 +31,7 @@
3131
</Expand>
3232
</Type>
3333
<Type Name="alloc::collections::linked_list::LinkedList&lt;*&gt;">
34-
<DisplayString>{{ size={len} }}</DisplayString>
34+
<DisplayString>{{ len={len} }}</DisplayString>
3535
<Expand>
3636
<LinkedListItems>
3737
<Size>len</Size>
@@ -42,15 +42,37 @@
4242
</Expand>
4343
</Type>
4444
<Type Name="alloc::string::String">
45-
<DisplayString>{*(char**)this,[vec.len]s8}</DisplayString>
46-
<StringView>*(char**)this,[vec.len]s8</StringView>
45+
<DisplayString>{(char*)vec.buf.ptr.pointer,[vec.len]s8}</DisplayString>
46+
<StringView>(char*)vec.buf.ptr.pointer,[vec.len]s8</StringView>
4747
<Expand>
48-
<Item Name="[size]" ExcludeView="simple">vec.len</Item>
48+
<Item Name="[len]" ExcludeView="simple">vec.len</Item>
4949
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
50-
<ArrayItems>
51-
<Size>vec.len</Size>
52-
<ValuePointer>*(char**)this</ValuePointer>
53-
</ArrayItems>
50+
<Synthetic Name="[chars]">
51+
<Expand>
52+
<ArrayItems>
53+
<Size>vec.len</Size>
54+
<ValuePointer>(char*)vec.buf.ptr.pointer</ValuePointer>
55+
</ArrayItems>
56+
</Expand>
57+
</Synthetic>
58+
</Expand>
59+
</Type>
60+
<Type Name="alloc::rc::Rc&lt;*&gt;">
61+
<DisplayString>{ptr.pointer->value}</DisplayString>
62+
<Expand>
63+
<ExpandedItem>ptr.pointer->value</ExpandedItem>
64+
</Expand>
65+
</Type>
66+
<Type Name="alloc::sync::Arc&lt;*&gt;">
67+
<DisplayString>{ptr.pointer->data}</DisplayString>
68+
<Expand>
69+
<ExpandedItem>ptr.pointer->data</ExpandedItem>
70+
</Expand>
71+
</Type>
72+
<Type Name="alloc::sync::Weak&lt;*&gt;">
73+
<DisplayString>{ptr.pointer->data}</DisplayString>
74+
<Expand>
75+
<ExpandedItem>ptr.pointer->data</ExpandedItem>
5476
</Expand>
5577
</Type>
5678
</AutoVisualizer>

src/etc/natvis/libcore.natvis

+10-16
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,28 @@
66
<Item Name="[ptr]">pointer</Item>
77
</Expand>
88
</Type>
9+
910
<Type Name="core::ptr::Shared&lt;*&gt;">
1011
<DisplayString>{{ Shared {pointer} }}</DisplayString>
1112
<Expand>
1213
<Item Name="[ptr]">pointer</Item>
1314
</Expand>
1415
</Type>
16+
1517
<Type Name="core::option::Option&lt;*&gt;">
16-
<DisplayString Condition="RUST$ENUM$DISR == 0x0">{{ None }}</DisplayString>
17-
<DisplayString Condition="RUST$ENUM$DISR == 0x1">{{ Some {__0} }}</DisplayString>
18+
<DisplayString Condition="RUST$ENUM$DISR == 0x0">None</DisplayString>
19+
<DisplayString Condition="RUST$ENUM$DISR == 0x1">Some({__0})</DisplayString>
1820
<Expand>
19-
<Item Name="[size]" ExcludeView="simple">(ULONG)(RUST$ENUM$DISR != 0)</Item>
20-
<Item Name="[value]" ExcludeView="simple">__0</Item>
21-
<ArrayItems>
22-
<Size>(ULONG)(RUST$ENUM$DISR != 0)</Size>
23-
<ValuePointer>&amp;__0</ValuePointer>
24-
</ArrayItems>
21+
<Item Name="[value]" ExcludeView="simple" Condition="RUST$ENUM$DISR == 1">__0</Item>
2522
</Expand>
2623
</Type>
24+
2725
<Type Name="core::option::Option&lt;*&gt;" Priority="MediumLow">
28-
<DisplayString Condition="*(PVOID *)this == nullptr">{{ None }}</DisplayString>
29-
<DisplayString>{{ Some {($T1 *)this} }}</DisplayString>
26+
<DisplayString Condition="*(void**)this == nullptr">None</DisplayString>
27+
<DisplayString>Some({($T1 *)this})</DisplayString>
3028
<Expand>
31-
<Item Name="[size]" ExcludeView="simple">(ULONG)(*(PVOID *)this != nullptr)</Item>
32-
<Item Name="[value]" ExcludeView="simple" Condition="*(PVOID *)this != nullptr">($T1 *)this</Item>
33-
<ArrayItems>
34-
<Size>(ULONG)(*(PVOID *)this != nullptr)</Size>
35-
<ValuePointer>($T1 *)this</ValuePointer>
36-
</ArrayItems>
29+
<Item Name="Some" ExcludeView="simple" Condition="*(void**)this != nullptr">($T1 *)this</Item>
3730
</Expand>
3831
</Type>
32+
3933
</AutoVisualizer>

src/etc/natvis/libstd.natvis

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
-->
2727

2828
<Type Name="std::collections::hash::map::HashMap&lt;*,*,*&gt;">
29-
<DisplayString>{{ size={base.table.items} }}</DisplayString>
29+
<DisplayString>{{ len={base.table.items} }}</DisplayString>
3030
<Expand>
31-
<Item Name="[size]">base.table.items</Item>
31+
<Item Name="[len]">base.table.items</Item>
3232
<Item Name="[capacity]">base.table.items + base.table.growth_left</Item>
3333
<Item Name="[state]">base.hash_builder</Item>
3434

@@ -50,9 +50,9 @@
5050
</Type>
5151

5252
<Type Name="std::collections::hash::set::HashSet&lt;*,*&gt;">
53-
<DisplayString>{{ size={base.map.table.items} }}</DisplayString>
53+
<DisplayString>{{ len={base.map.table.items} }}</DisplayString>
5454
<Expand>
55-
<Item Name="[size]">base.map.table.items</Item>
55+
<Item Name="[len]">base.map.table.items</Item>
5656
<Item Name="[capacity]">base.map.table.items + base.map.table.growth_left</Item>
5757
<Item Name="[state]">base.map.hash_builder</Item>
5858

0 commit comments

Comments
 (0)