Skip to content

Commit 88b198b

Browse files
authored
Rollup merge of #80311 - sivadeilra:natvis, r=petrochenkov
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. * The visualizers for `str` and `String` now place the character data array under a synthetic `[chars]` node. When expanding a `String` node, users rarely want to see an array of characters. This just places them behind one expansion node / level.
2 parents 00741b8 + 2f58422 commit 88b198b

File tree

6 files changed

+71
-49
lines changed

6 files changed

+71
-49
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

src/test/debuginfo/pretty-std-collections-hash.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// cdb-command: g
1111

1212
// cdb-command: dx hash_set,d
13-
// cdb-check:hash_set,d [...] : { size=15 } [Type: [...]::HashSet<u64, [...]>]
14-
// cdb-check: [size] : 15 [Type: [...]]
13+
// cdb-check:hash_set,d [...] : { len=15 } [Type: [...]::HashSet<u64, [...]>]
14+
// cdb-check: [len] : 15 [Type: [...]]
1515
// cdb-check: [capacity] : [...]
1616
// cdb-check: [[...]] [...] : 0 [Type: u64]
1717
// cdb-command: dx hash_set,d
@@ -44,8 +44,8 @@
4444
// cdb-check: [[...]] [...] : 14 [Type: u64]
4545

4646
// cdb-command: dx hash_map,d
47-
// cdb-check:hash_map,d [...] : { size=15 } [Type: [...]::HashMap<u64, u64, [...]>]
48-
// cdb-check: [size] : 15 [Type: [...]]
47+
// cdb-check:hash_map,d [...] : { len=15 } [Type: [...]::HashMap<u64, u64, [...]>]
48+
// cdb-check: [len] : 15 [Type: [...]]
4949
// cdb-check: [capacity] : [...]
5050
// cdb-check: ["0x0"] : 0 [Type: unsigned __int64]
5151
// cdb-command: dx hash_map,d

src/test/debuginfo/pretty-std.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
// NOTE: While slices have a .natvis entry that works in VS & VS Code, it fails in CDB 10.0.18362.1
7575

7676
// cdb-command: dx vec,d
77-
// cdb-check:vec,d [...] : { size=4 } [Type: [...]::Vec<u64, alloc::alloc::Global>]
78-
// cdb-check: [size] : 4 [Type: [...]]
77+
// cdb-check:vec,d [...] : { len=4 } [Type: [...]::Vec<u64, alloc::alloc::Global>]
78+
// cdb-check: [len] : 4 [Type: [...]]
7979
// cdb-check: [capacity] : [...] [Type: [...]]
8080
// cdb-check: [0] : 4 [Type: unsigned __int64]
8181
// cdb-check: [1] : 5 [Type: unsigned __int64]
@@ -89,8 +89,10 @@
8989
// cdb-command: dx string
9090
// cdb-check:string : "IAMA string!" [Type: [...]::String]
9191
// cdb-check: [<Raw View>] [Type: [...]::String]
92-
// cdb-check: [size] : 0xc [Type: [...]]
92+
// cdb-check: [len] : 0xc [Type: [...]]
9393
// cdb-check: [capacity] : 0xc [Type: [...]]
94+
95+
// cdb-command: dx -r2 string
9496
// cdb-check: [0] : 73 'I' [Type: char]
9597
// cdb-check: [1] : 65 'A' [Type: char]
9698
// cdb-check: [2] : 77 'M' [Type: char]
@@ -109,11 +111,11 @@
109111
// NOTE: OsString doesn't have a .natvis entry yet.
110112

111113
// cdb-command: dx some
112-
// cdb-check:some : { Some 8 } [Type: [...]::Option<i16>]
114+
// cdb-check:some : Some(8) [Type: [...]::Option<i16>]
113115
// cdb-command: dx none
114-
// cdb-check:none : { None } [Type: [...]::Option<i64>]
116+
// cdb-check:none : None [Type: [...]::Option<i64>]
115117
// cdb-command: dx some_string
116-
// cdb-check:some_string : { Some "IAMA optional string!" } [[...]::Option<[...]::String>]
118+
// cdb-check:some_string : Some("IAMA optional string!") [[...]::Option<[...]::String>]
117119

118120
#![allow(unused_variables)]
119121
use std::ffi::OsString;

0 commit comments

Comments
 (0)