Skip to content

Commit 71bc541

Browse files
Rollup merge of #98137 - michaelwoerister:fix-unsized-rc-arc-natvis, r=wesleywiser
debuginfo: Fix NatVis for Rc and Arc with unsized pointees. Currently, the NatVis for `Rc<T>` and `Arc<T>` does not support unsized `T`. For both `Rc<T>` and `Rc<dyn SomeTrait>` the visualizers fail: ```txt [Reference count] : -> must be used on pointers and . on structures [Weak reference count] : -> must be used on pointers and . on structures ``` This PR fixes the visualizers. For slices we can even give show the elements, so one now gets something like: ```txt slice_rc : { len=3 } [Length] : 3 [Reference count] : 41 [Weak reference count] : 2 [0] : 1 [1] : 2 [2] : 3 ``` r? `@wesleywiser`
2 parents ed1d8b0 + 2b5efa4 commit 71bc541

File tree

2 files changed

+214
-56
lines changed

2 files changed

+214
-56
lines changed

Diff for: src/etc/natvis/liballoc.natvis

+110-16
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,133 @@
5959
</Expand>
6060
</Type>
6161

62+
<!--
63+
The display string for Rc, Arc, etc is optional because the expression cannot be evaluated
64+
if the pointee is unsized (i.e. if `ptr.pointer` is a fat pointer).
65+
66+
There are also two versions for the reference count fields, one for sized and one for
67+
dyn pointees.
68+
69+
Rc<[T]> and Arc<[T]> are handled separately altogether so we can actually show
70+
the slice values.
71+
-->
72+
<!-- alloc::rc::Rc<T> -->
6273
<Type Name="alloc::rc::Rc&lt;*&gt;">
63-
<DisplayString>{ptr.pointer->value}</DisplayString>
74+
<DisplayString Optional="true">{ptr.pointer->value}</DisplayString>
6475
<Expand>
65-
<ExpandedItem>ptr.pointer->value</ExpandedItem>
66-
<Item Name="[Reference count]">ptr.pointer->strong</Item>
67-
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
76+
<!-- thin -->
77+
<ExpandedItem Optional="true">ptr.pointer->value</ExpandedItem>
78+
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
79+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
80+
81+
<!-- dyn -->
82+
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
83+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
84+
</Expand>
85+
</Type>
86+
87+
<!-- alloc::rc::Rc<[T]> -->
88+
<Type Name="alloc::rc::Rc&lt;slice$&lt;*&gt; &gt;">
89+
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
90+
<Expand>
91+
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
92+
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
93+
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
94+
<ArrayItems>
95+
<Size>ptr.pointer.length</Size>
96+
<!-- We add +2 to the data_ptr in order to skip the ref count fields in the RcBox -->
97+
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
98+
</ArrayItems>
6899
</Expand>
69100
</Type>
101+
102+
<!-- alloc::rc::Weak<T> -->
70103
<Type Name="alloc::rc::Weak&lt;*&gt;">
71-
<DisplayString>{ptr.pointer->value}</DisplayString>
104+
<DisplayString Optional="true">{ptr.pointer->value}</DisplayString>
105+
<Expand>
106+
<!-- thin -->
107+
<ExpandedItem Optional="true">ptr.pointer->value</ExpandedItem>
108+
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
109+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
110+
111+
<!-- dyn -->
112+
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
113+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
114+
</Expand>
115+
</Type>
116+
117+
<!-- alloc::rc::Weak<[T]> -->
118+
<Type Name="alloc::rc::Weak&lt;slice$&lt;*&gt; &gt;">
119+
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
72120
<Expand>
73-
<ExpandedItem>ptr.pointer->value</ExpandedItem>
74-
<Item Name="[Reference count]">ptr.pointer->strong</Item>
75-
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
121+
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
122+
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
123+
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
124+
<ArrayItems>
125+
<Size>ptr.pointer.length</Size>
126+
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
127+
</ArrayItems>
76128
</Expand>
77129
</Type>
78130

131+
<!-- alloc::sync::Arc<T> -->
79132
<Type Name="alloc::sync::Arc&lt;*&gt;">
80-
<DisplayString>{ptr.pointer->data}</DisplayString>
133+
<DisplayString Optional="true">{ptr.pointer->data}</DisplayString>
81134
<Expand>
82-
<ExpandedItem>ptr.pointer->data</ExpandedItem>
83-
<Item Name="[Reference count]">ptr.pointer->strong</Item>
84-
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
135+
<!-- thin -->
136+
<ExpandedItem Optional="true">ptr.pointer->data</ExpandedItem>
137+
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
138+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
139+
140+
<!-- dyn -->
141+
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
142+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
143+
</Expand>
144+
</Type>
145+
146+
<!-- alloc::sync::Arc<[T]> -->
147+
<Type Name="alloc::sync::Arc&lt;slice$&lt;*&gt; &gt;">
148+
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
149+
<Expand>
150+
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
151+
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
152+
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
153+
<ArrayItems>
154+
<Size>ptr.pointer.length</Size>
155+
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
156+
</ArrayItems>
85157
</Expand>
86158
</Type>
159+
160+
<!-- alloc::sync::Weak<T> -->
87161
<Type Name="alloc::sync::Weak&lt;*&gt;">
88-
<DisplayString>{ptr.pointer->data}</DisplayString>
162+
<DisplayString Optional="true">{ptr.pointer->data}</DisplayString>
89163
<Expand>
90-
<ExpandedItem>ptr.pointer->data</ExpandedItem>
91-
<Item Name="[Reference count]">ptr.pointer->strong</Item>
92-
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
164+
<!-- thin -->
165+
<ExpandedItem Optional="true">ptr.pointer->data</ExpandedItem>
166+
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
167+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
168+
169+
<!-- dyn -->
170+
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
171+
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
172+
</Expand>
173+
</Type>
174+
175+
<!-- alloc::sync::Weak<[T]> -->
176+
<Type Name="alloc::sync::Weak&lt;slice$&lt;*&gt; &gt;">
177+
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
178+
<Expand>
179+
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
180+
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
181+
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
182+
<ArrayItems>
183+
<Size>ptr.pointer.length</Size>
184+
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
185+
</ArrayItems>
93186
</Expand>
94187
</Type>
188+
95189
<Type Name="alloc::borrow::Cow&lt;*&gt;">
96190
<DisplayString Condition="RUST$ENUM$DISR == 0x0">Borrowed({__0})</DisplayString>
97191
<DisplayString Condition="RUST$ENUM$DISR == 0x1">Owned({__0})</DisplayString>

Diff for: src/test/debuginfo/rc_arc.rs

+104-40
Original file line numberDiff line numberDiff line change
@@ -8,74 +8,138 @@
88

99
// gdb-command:run
1010

11-
// gdb-command:print r
12-
// gdb-check:[...]$1 = Rc(strong=2, weak=1) = {value = 42, strong = 2, weak = 1}
13-
// gdb-command:print a
14-
// gdb-check:[...]$2 = Arc(strong=2, weak=1) = {value = 42, strong = 2, weak = 1}
15-
11+
// gdb-command:print rc
12+
// gdb-check:[...]$1 = Rc(strong=11, weak=1) = {value = 111, strong = 11, weak = 1}
13+
// gdb-command:print arc
14+
// gdb-check:[...]$2 = Arc(strong=21, weak=1) = {value = 222, strong = 21, weak = 1}
1615

1716
// === LLDB TESTS ==================================================================================
1817

1918
// lldb-command:run
2019

21-
// lldb-command:print r
22-
// lldb-check:[...]$0 = strong=2, weak=1 { value = 42 }
23-
// lldb-command:print a
24-
// lldb-check:[...]$1 = strong=2, weak=1 { data = 42 }
20+
// lldb-command:print rc
21+
// lldb-check:[...]$0 = strong=11, weak=1 { value = 111 }
22+
// lldb-command:print arc
23+
// lldb-check:[...]$1 = strong=21, weak=1 { data = 222 }
2524

2625
// === CDB TESTS ==================================================================================
2726

2827
// cdb-command:g
2928

30-
// cdb-command:dx r,d
31-
// cdb-check:r,d : 42 [Type: alloc::rc::Rc<i32>]
32-
// cdb-check: [<Raw View>] [Type: alloc::rc::Rc<i32>]
33-
// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>]
29+
// cdb-command:dx rc,d
30+
// cdb-check:rc,d : 111 [Type: alloc::rc::Rc<i32>]
31+
// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>]
32+
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
33+
34+
// cdb-command:dx weak_rc,d
35+
// cdb-check:weak_rc,d : 111 [Type: alloc::rc::Weak<i32>]
36+
// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>]
37+
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
38+
39+
// cdb-command:dx arc,d
40+
// cdb-check:arc,d : 222 [Type: alloc::sync::Arc<i32>]
41+
// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
42+
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
43+
44+
// cdb-command:dx weak_arc,d
45+
// cdb-check:weak_arc,d : 222 [Type: alloc::sync::Weak<i32>]
46+
// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
47+
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
48+
49+
// cdb-command:dx dyn_rc,d
50+
// cdb-check:dyn_rc,d [Type: alloc::rc::Rc<dyn$<core::fmt::Debug> >]
51+
// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>]
3452
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
3553

36-
// cdb-command:dx r1,d
37-
// cdb-check:r1,d : 42 [Type: alloc::rc::Rc<i32>]
38-
// cdb-check: [<Raw View>] [Type: alloc::rc::Rc<i32>]
39-
// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>]
54+
// cdb-command:dx dyn_rc_weak,d
55+
// cdb-check:dyn_rc_weak,d [Type: alloc::rc::Weak<dyn$<core::fmt::Debug> >]
56+
// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>]
4057
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
4158

42-
// cdb-command:dx w1,d
43-
// cdb-check:w1,d : 42 [Type: alloc::rc::Weak<i32>]
44-
// cdb-check: [<Raw View>] [Type: alloc::rc::Weak<i32>]
45-
// cdb-check: [Reference count] : 2 [Type: core::cell::Cell<usize>]
59+
// cdb-command:dx slice_rc,d
60+
// cdb-check:slice_rc,d : { len=3 } [Type: alloc::rc::Rc<slice$<u32> >]
61+
// cdb-check: [Length] : 3 [Type: unsigned __int64]
62+
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
4663
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
64+
// cdb-check: [0] : 1 [Type: u32]
65+
// cdb-check: [1] : 2 [Type: u32]
66+
// cdb-check: [2] : 3 [Type: u32]
67+
68+
// cdb-command:dx slice_rc_weak,d
69+
// cdb-check:slice_rc_weak,d : { len=3 } [Type: alloc::rc::Weak<slice$<u32> >]
70+
// cdb-check: [Length] : 3 [Type: unsigned __int64]
71+
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
72+
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
73+
// cdb-check: [0] : 1 [Type: u32]
74+
// cdb-check: [1] : 2 [Type: u32]
75+
// cdb-check: [2] : 3 [Type: u32]
4776

48-
// cdb-command:dx a,d
49-
// cdb-check:a,d : 42 [Type: alloc::sync::Arc<i32>]
50-
// cdb-check: [<Raw View>] [Type: alloc::sync::Arc<i32>]
51-
// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
77+
// cdb-command:dx dyn_arc,d
78+
// cdb-check:dyn_arc,d [Type: alloc::sync::Arc<dyn$<core::fmt::Debug> >]
79+
// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
5280
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
5381

54-
// cdb-command:dx a1,d
55-
// cdb-check:a1,d : 42 [Type: alloc::sync::Arc<i32>]
56-
// cdb-check: [<Raw View>] [Type: alloc::sync::Arc<i32>]
57-
// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
82+
// cdb-command:dx dyn_arc_weak,d
83+
// cdb-check:dyn_arc_weak,d [Type: alloc::sync::Weak<dyn$<core::fmt::Debug> >]
84+
// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
5885
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
5986

60-
// cdb-command:dx w2,d
61-
// cdb-check:w2,d : 42 [Type: alloc::sync::Weak<i32>]
62-
// cdb-check: [<Raw View>] [Type: alloc::sync::Weak<i32>]
63-
// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
87+
// cdb-command:dx slice_arc,d
88+
// cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice$<u32> >]
89+
// cdb-check: [Length] : 3 [Type: unsigned __int64]
90+
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
91+
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
92+
// cdb-check: [0] : 4 [Type: u32]
93+
// cdb-check: [1] : 5 [Type: u32]
94+
// cdb-check: [2] : 6 [Type: u32]
95+
96+
// cdb-command:dx slice_arc_weak,d
97+
// cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice$<u32> >]
98+
// cdb-check: [Length] : 3 [Type: unsigned __int64]
99+
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
64100
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
101+
// cdb-check: [0] : 4 [Type: u32]
102+
// cdb-check: [1] : 5 [Type: u32]
103+
// cdb-check: [2] : 6 [Type: u32]
65104

105+
use std::fmt::Debug;
66106
use std::rc::Rc;
67107
use std::sync::Arc;
68108

69109
fn main() {
70-
let r = Rc::new(42);
71-
let r1 = Rc::clone(&r);
72-
let w1 = Rc::downgrade(&r);
110+
let rc = Rc::new(111);
111+
inc_ref_count(&rc, 10);
112+
let weak_rc = Rc::downgrade(&rc);
113+
114+
let arc = Arc::new(222);
115+
inc_ref_count(&arc, 20);
116+
let weak_arc = Arc::downgrade(&arc);
117+
118+
let dyn_rc: Rc<dyn Debug> = Rc::new(333);
119+
inc_ref_count(&dyn_rc, 30);
120+
let dyn_rc_weak = Rc::downgrade(&dyn_rc);
121+
122+
let slice_rc: Rc<[u32]> = Rc::from(vec![1, 2, 3]);
123+
inc_ref_count(&slice_rc, 40);
124+
let slice_rc_weak = Rc::downgrade(&slice_rc);
73125

74-
let a = Arc::new(42);
75-
let a1 = Arc::clone(&a);
76-
let w2 = Arc::downgrade(&a);
126+
let dyn_arc: Arc<dyn Debug> = Arc::new(444);
127+
inc_ref_count(&dyn_arc, 50);
128+
let dyn_arc_weak = Arc::downgrade(&dyn_arc);
129+
130+
let slice_arc: Arc<[u32]> = Arc::from(vec![4, 5, 6]);
131+
inc_ref_count(&slice_arc, 60);
132+
let slice_arc_weak = Arc::downgrade(&slice_arc);
77133

78134
zzz(); // #break
79135
}
80136

81-
fn zzz() { () }
137+
fn inc_ref_count<T: Clone>(rc: &T, count: usize) {
138+
for _ in 0..count {
139+
std::mem::forget(rc.clone());
140+
}
141+
}
142+
143+
fn zzz() {
144+
()
145+
}

0 commit comments

Comments
 (0)