Skip to content

Commit cad42e0

Browse files
committed
Add natvis for cell types
1 parent 9740dcc commit cad42e0

File tree

3 files changed

+102
-15
lines changed

3 files changed

+102
-15
lines changed

src/etc/natvis/libcore.natvis

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
3+
<Type Name="core::cell::Cell&lt;*&gt;">
4+
<DisplayString>{value.value}</DisplayString>
5+
<Expand>
6+
<ExpandedItem>value.value</ExpandedItem>
7+
</Expand>
8+
</Type>
9+
<Type Name="core::cell::Ref&lt;*&gt;">
10+
<DisplayString>{value}</DisplayString>
11+
<Expand>
12+
<ExpandedItem>value</ExpandedItem>
13+
</Expand>
14+
</Type>
15+
<Type Name="core::cell::RefMut&lt;*&gt;">
16+
<DisplayString>{value}</DisplayString>
17+
<Expand>
18+
<ExpandedItem>value</ExpandedItem>
19+
</Expand>
20+
</Type>
21+
<Type Name="core::cell::RefCell&lt;*&gt;">
22+
<DisplayString>{value.value}</DisplayString>
23+
<Expand>
24+
<Item Name="[Borrow state]" Condition="borrow.value.value == 0">"Unborrowed",sb</Item>
25+
<Item Name="[Borrow state]" Condition="borrow.value.value &gt; 0">"Immutably borrowed",sb</Item>
26+
<Item Name="[Borrow state]" Condition="borrow.value.value &lt; 0">"Mutably borrowed",sb</Item>
27+
<ExpandedItem>value.value</ExpandedItem>
28+
</Expand>
29+
</Type>
30+
<Type Name="core::cell::UnsafeCell&lt;*&gt;">
31+
<DisplayString>{value}</DisplayString>
32+
<Expand>
33+
<ExpandedItem>value</ExpandedItem>
34+
</Expand>
35+
</Type>
36+
337
<Type Name="core::num::nonzero::NonZeroI8">
438
<DisplayString>{__0}</DisplayString>
539
</Type>

src/test/debuginfo/mutable-locs.rs

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,64 @@
99
// cdb-command: g
1010

1111
// cdb-command:dx static_c,d
12-
// cdb-check:static_c,d [Type: core::cell::Cell<i32>]
13-
// cdb-check: [...] value [Type: core::cell::UnsafeCell<i32>]
12+
// cdb-check:static_c,d : 10 [Type: core::cell::Cell<i32>]
13+
// cdb-check: [<Raw View>] [Type: core::cell::Cell<i32>]
1414

1515
// cdb-command: dx static_c.value,d
16-
// cdb-check:static_c.value,d [Type: core::cell::UnsafeCell<i32>]
17-
// cdb-check: [...] value : 10 [Type: int]
16+
// cdb-check:static_c.value,d : 10 [Type: core::cell::UnsafeCell<i32>]
17+
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
1818

1919
// cdb-command: dx dynamic_c,d
20-
// cdb-check:dynamic_c,d [Type: core::cell::RefCell<i32>]
21-
// cdb-check: [...] borrow [Type: core::cell::Cell<isize>]
22-
// cdb-check: [...] value [Type: core::cell::UnsafeCell<i32>]
20+
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
21+
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
22+
// cdb-check: [Borrow state] : Unborrowed
2323

2424
// cdb-command: dx dynamic_c.value,d
25-
// cdb-check:dynamic_c.value,d [Type: core::cell::UnsafeCell<i32>]
26-
// cdb-check: [...] value : 15 [Type: int]
25+
// cdb-check:dynamic_c.value,d : 15 [Type: core::cell::UnsafeCell<i32>]
26+
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
2727

2828
// cdb-command: dx b,d
29-
// cdb-check:b,d [Type: core::cell::RefMut<i32>]
30-
// cdb-check: [...] value : [...] : 42 [Type: int *]
31-
// cdb-check: [...] borrow [Type: core::cell::BorrowRefMut]
29+
// cdb-check:b,d : 42 [Type: core::cell::RefMut<i32>]
30+
// cdb-check: [<Raw View>] [Type: core::cell::RefMut<i32>]
31+
// cdb-check: 42 [Type: int]
32+
33+
// cdb-command: g
34+
35+
// cdb-command: dx dynamic_c,d
36+
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
37+
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
38+
// cdb-check: [Borrow state] : Immutably borrowed
39+
40+
// cdb-command: dx r_borrow,d
41+
// cdb-check:r_borrow,d : 15 [Type: core::cell::Ref<i32>]
42+
// cdb-check: [<Raw View>] [Type: core::cell::Ref<i32>]
43+
// cdb-check: 15 [Type: int]
44+
45+
// cdb-command: g
46+
47+
// cdb-command: dx dynamic_c,d
48+
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
49+
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
50+
// cdb-check: [Borrow state] : Unborrowed
51+
52+
// cdb-command: g
53+
54+
// cdb-command: dx dynamic_c,d
55+
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
56+
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
57+
// cdb-check: [Borrow state] : Mutably borrowed
58+
59+
// cdb-command: dx r_borrow_mut,d
60+
// cdb-check:r_borrow_mut,d : 15 [Type: core::cell::RefMut<i32>]
61+
// cdb-check: [<Raw View>] [Type: core::cell::RefMut<i32>]
62+
// cdb-check: 15 [Type: int]
63+
64+
// cdb-command: g
65+
66+
// cdb-command: dx dynamic_c,d
67+
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
68+
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
69+
// cdb-check: [Borrow state] : Unborrowed
3270

3371
#![allow(unused_variables)]
3472

@@ -46,6 +84,21 @@ fn main() {
4684
*b = 42;
4785

4886
zzz(); // #break
87+
88+
// Check that `RefCell`'s borrow state visualizes correctly
89+
{
90+
let r_borrow = dynamic_c.borrow();
91+
zzz(); // #break
92+
}
93+
94+
zzz(); // #break
95+
96+
{
97+
let r_borrow_mut = dynamic_c.borrow_mut();
98+
zzz(); // #break
99+
}
100+
101+
zzz(); // #break
49102
}
50103

51104
fn zzz() {()}

src/test/debuginfo/rwlock-read.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
// cdb-command:dx l
1212
// cdb-check:l [Type: std::sync::rwlock::RwLock<i32>]
1313
// cdb-check: [...] poison [Type: std::sync::poison::Flag]
14-
// cdb-check: [...] data [Type: core::cell::UnsafeCell<i32>]
14+
// cdb-check: [...] data : 0 [Type: core::cell::UnsafeCell<i32>]
1515
//
1616
// cdb-command:dx r
1717
// cdb-check:r [Type: std::sync::rwlock::RwLockReadGuard<i32>]
1818
// cdb-check: [...] lock : [...] [Type: std::sync::rwlock::RwLock<i32> *]
1919
//
2020
// cdb-command:dx r.lock->data,d
21-
// cdb-check:r.lock->data,d [Type: core::cell::UnsafeCell<i32>]
22-
// cdb-check: [...] value : 0 [Type: int]
21+
// cdb-check:r.lock->data,d : 0 [Type: core::cell::UnsafeCell<i32>]
22+
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
2323

2424
#[allow(unused_variables)]
2525

0 commit comments

Comments
 (0)