Skip to content

Commit 9420ff4

Browse files
committed
Auto merge of #66597 - MaulingMonkey:pr-natvis-std-collections-hash, r=michaelwoerister
debuginfo: Support for std::collections::Hash* in windows debuggers. Okay, I finally needed to debug code involving a HashMap! Added support for HashSet s as well. r? @michaelwoerister ### Local Testing Verified these are passing locally: ```cmd :: cmd.exe python x.py test --stage 1 --build x86_64-pc-windows-msvc src/test/debuginfo python x.py test --stage 1 --build i686-pc-windows-msvc src/test/debuginfo python x.py test --stage 1 src/tools/tidy :: MinGW MSYS2 ./x.py test --stage 1 --build x86_64-pc-windows-gnu src/test/debuginfo ``` ### Related Issues * #36503 * #40460 * rust-gamedev/wg#20
2 parents d902539 + 839d58c commit 9420ff4

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

src/bootstrap/dist.rs

+1
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ impl Step for DebuggerScripts {
616616
cp_debugger_script("natvis/intrinsic.natvis");
617617
cp_debugger_script("natvis/liballoc.natvis");
618618
cp_debugger_script("natvis/libcore.natvis");
619+
cp_debugger_script("natvis/libstd.natvis");
619620
} else {
620621
cp_debugger_script("debugger_pretty_printers_common.py");
621622

src/etc/natvis/libstd.natvis

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
3+
<!--
4+
std::collection::Hash* container visualizers
5+
6+
Current std impls:
7+
std::collections::hash::set::HashSet<K, S> is implemented in terms of...
8+
std::collections::hash::map::HashMap<K, V, S> is implemented in terms of...
9+
hashbrown::map::HashMap<K, V, S> is implemented in terms of...
10+
hashbrown::raw::RawTable<(K, V)>
11+
12+
Ideally, we'd teach rustc to scan dependencies/crates for .natvis files so
13+
the bulk of this could live alongside the hashbrown crate implementation,
14+
and std would just forward using e.g. <ExpandedItem>base</ExpandedItem>.
15+
16+
However, Given that std...Hash*Set* is currently implemented in terms of
17+
hashbrown...Hash*Map*, which would visualize poorly, we want to customize the
18+
look/feel at the std type level *anyways*...
19+
20+
References:
21+
https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/map.rs
22+
https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/set.rs
23+
https://github.com/rust-lang/hashbrown/blob/master/src/map.rs
24+
https://github.com/rust-lang/hashbrown/blob/master/src/set.rs
25+
https://github.com/rust-lang/hashbrown/blob/master/src/raw/mod.rs
26+
-->
27+
28+
<Type Name="std::collections::hash::map::HashMap&lt;*,*,*&gt;">
29+
<DisplayString>{{ size={base.table.items} }}</DisplayString>
30+
<Expand>
31+
<Item Name="[size]">base.table.items</Item>
32+
<Item Name="[capacity]">base.table.items + base.table.growth_left</Item>
33+
34+
<CustomListItems>
35+
<Variable Name="i" InitialValue="0" />
36+
<Variable Name="n" InitialValue="base.table.items" />
37+
<Size>base.table.items</Size>
38+
<Loop>
39+
<Break Condition="n == 0" />
40+
<If Condition="(base.table.ctrl.pointer[i] &amp; 0x80) == 0">
41+
<!-- Bucket is populated -->
42+
<Exec>n--</Exec>
43+
<Item Name="{base.table.data.pointer[i].__0}">base.table.data.pointer[i].__1</Item>
44+
</If>
45+
<Exec>i++</Exec>
46+
</Loop>
47+
</CustomListItems>
48+
</Expand>
49+
</Type>
50+
51+
<Type Name="std::collections::hash::set::HashSet&lt;*,*&gt;">
52+
<DisplayString>{{ size={map.base.table.items} }}</DisplayString>
53+
<Expand>
54+
<Item Name="[size]">map.base.table.items</Item>
55+
<Item Name="[capacity]">map.base.table.items + map.base.table.growth_left</Item>
56+
57+
<CustomListItems>
58+
<Variable Name="i" InitialValue="0" />
59+
<Variable Name="n" InitialValue="map.base.table.items" />
60+
<Size>map.base.table.items</Size>
61+
<Loop>
62+
<Break Condition="n == 0" />
63+
<If Condition="(map.base.table.ctrl.pointer[i] &amp; 0x80) == 0">
64+
<!-- Bucket is populated -->
65+
<Exec>n--</Exec>
66+
<Item>map.base.table.data.pointer[i].__0</Item>
67+
</If>
68+
<Exec>i++</Exec>
69+
</Loop>
70+
</CustomListItems>
71+
</Expand>
72+
</Type>
73+
74+
<Type Name="hashbrown::raw::RawTable&lt;*&gt;">
75+
<!-- RawTable has a nice and simple layout.
76+
items Number of *populated* values in the RawTable (less than the size of ctrl.pointer / data.pointer)
77+
growth_left Remaining capacity before growth
78+
ctrl.pointer[i] & 0x80 Indicates the bucket is empty / should be skipped / doesn't count towards items.
79+
data.pointer[i] The (K,V) tuple, if not empty.
80+
-->
81+
<DisplayString>{{ size={items} }}</DisplayString>
82+
<Expand>
83+
<Item Name="[size]">items</Item>
84+
<Item Name="[capacity]">items + growth_left</Item>
85+
86+
<CustomListItems>
87+
<Variable Name="i" InitialValue="0" />
88+
<Variable Name="n" InitialValue="items" />
89+
<Size>items</Size>
90+
<Loop>
91+
<Break Condition="n == 0" />
92+
<If Condition="(ctrl.pointer[i] &amp; 0x80) == 0">
93+
<!-- Bucket is populated -->
94+
<Exec>n--</Exec>
95+
<Item>data.pointer[i]</Item>
96+
</If>
97+
<Exec>i++</Exec>
98+
</Loop>
99+
</CustomListItems>
100+
</Expand>
101+
</Type>
102+
</AutoVisualizer>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// cdb-only
2+
// compile-flags:-g
3+
4+
// === CDB TESTS ==================================================================================
5+
6+
// cdb-command: g
7+
8+
// cdb-command: dx hash_set,d
9+
// cdb-check:hash_set,d [...] : { size=15 } [Type: [...]::HashSet<u64, [...]>]
10+
// cdb-check: [size] : 15 [Type: [...]]
11+
// cdb-check: [capacity] : [...]
12+
// cdb-check: [[...]] [...] : 0 [Type: unsigned __int64]
13+
// cdb-command: dx hash_set,d
14+
// cdb-check: [[...]] [...] : 1 [Type: unsigned __int64]
15+
// cdb-command: dx hash_set,d
16+
// cdb-check: [[...]] [...] : 2 [Type: unsigned __int64]
17+
// cdb-command: dx hash_set,d
18+
// cdb-check: [[...]] [...] : 3 [Type: unsigned __int64]
19+
// cdb-command: dx hash_set,d
20+
// cdb-check: [[...]] [...] : 4 [Type: unsigned __int64]
21+
// cdb-command: dx hash_set,d
22+
// cdb-check: [[...]] [...] : 5 [Type: unsigned __int64]
23+
// cdb-command: dx hash_set,d
24+
// cdb-check: [[...]] [...] : 6 [Type: unsigned __int64]
25+
// cdb-command: dx hash_set,d
26+
// cdb-check: [[...]] [...] : 7 [Type: unsigned __int64]
27+
// cdb-command: dx hash_set,d
28+
// cdb-check: [[...]] [...] : 8 [Type: unsigned __int64]
29+
// cdb-command: dx hash_set,d
30+
// cdb-check: [[...]] [...] : 9 [Type: unsigned __int64]
31+
// cdb-command: dx hash_set,d
32+
// cdb-check: [[...]] [...] : 10 [Type: unsigned __int64]
33+
// cdb-command: dx hash_set,d
34+
// cdb-check: [[...]] [...] : 11 [Type: unsigned __int64]
35+
// cdb-command: dx hash_set,d
36+
// cdb-check: [[...]] [...] : 12 [Type: unsigned __int64]
37+
// cdb-command: dx hash_set,d
38+
// cdb-check: [[...]] [...] : 13 [Type: unsigned __int64]
39+
// cdb-command: dx hash_set,d
40+
// cdb-check: [[...]] [...] : 14 [Type: unsigned __int64]
41+
42+
// cdb-command: dx hash_map,d
43+
// cdb-check:hash_map,d [...] : { size=15 } [Type: [...]::HashMap<u64, u64, [...]>]
44+
// cdb-check: [size] : 15 [Type: [...]]
45+
// cdb-check: [capacity] : [...]
46+
// cdb-check: ["0x0"] : 0 [Type: unsigned __int64]
47+
// cdb-command: dx hash_map,d
48+
// cdb-check: ["0x1"] : 1 [Type: unsigned __int64]
49+
// cdb-command: dx hash_map,d
50+
// cdb-check: ["0x2"] : 2 [Type: unsigned __int64]
51+
// cdb-command: dx hash_map,d
52+
// cdb-check: ["0x3"] : 3 [Type: unsigned __int64]
53+
// cdb-command: dx hash_map,d
54+
// cdb-check: ["0x4"] : 4 [Type: unsigned __int64]
55+
// cdb-command: dx hash_map,d
56+
// cdb-check: ["0x5"] : 5 [Type: unsigned __int64]
57+
// cdb-command: dx hash_map,d
58+
// cdb-check: ["0x6"] : 6 [Type: unsigned __int64]
59+
// cdb-command: dx hash_map,d
60+
// cdb-check: ["0x7"] : 7 [Type: unsigned __int64]
61+
// cdb-command: dx hash_map,d
62+
// cdb-check: ["0x8"] : 8 [Type: unsigned __int64]
63+
// cdb-command: dx hash_map,d
64+
// cdb-check: ["0x9"] : 9 [Type: unsigned __int64]
65+
// cdb-command: dx hash_map,d
66+
// cdb-check: ["0xa"] : 10 [Type: unsigned __int64]
67+
// cdb-command: dx hash_map,d
68+
// cdb-check: ["0xb"] : 11 [Type: unsigned __int64]
69+
// cdb-command: dx hash_map,d
70+
// cdb-check: ["0xc"] : 12 [Type: unsigned __int64]
71+
// cdb-command: dx hash_map,d
72+
// cdb-check: ["0xd"] : 13 [Type: unsigned __int64]
73+
// cdb-command: dx hash_map,d
74+
// cdb-check: ["0xe"] : 14 [Type: unsigned __int64]
75+
76+
#![allow(unused_variables)]
77+
use std::collections::HashSet;
78+
use std::collections::HashMap;
79+
80+
81+
fn main() {
82+
// HashSet
83+
let mut hash_set = HashSet::new();
84+
for i in 0..15 {
85+
hash_set.insert(i as u64);
86+
}
87+
88+
// HashMap
89+
let mut hash_map = HashMap::new();
90+
for i in 0..15 {
91+
hash_map.insert(i as u64, i as u64);
92+
}
93+
94+
zzz(); // #break
95+
}
96+
97+
fn zzz() { () }

0 commit comments

Comments
 (0)