Skip to content

Commit 7d17424

Browse files
committed
update debuginfo visualizers and tests
1 parent eb42c0f commit 7d17424

5 files changed

Lines changed: 64 additions & 74 deletions

File tree

src/etc/gdb_providers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def unwrap_unique_or_non_null(unique_or_nonnull):
1818
return ptr if ptr.type.code == gdb.TYPE_CODE_PTR else ptr[ptr.type.fields()[0]]
1919

2020

21+
def unwrap_scalar_wrappers(wrapper):
22+
while not wrapper.type.is_scalar:
23+
wrapper = wrapper[wrapper.type.fields()[0]]
24+
return wrapper
25+
26+
2127
# GDB 14 has a tag class that indicates that extension methods are ok
2228
# to call. Use of this tag only requires that printers hide local
2329
# attributes and methods by prefixing them with "_".
@@ -197,8 +203,8 @@ def __init__(self, valobj, is_atomic=False):
197203
self._is_atomic = is_atomic
198204
self._ptr = unwrap_unique_or_non_null(valobj["ptr"])
199205
self._value = self._ptr["data" if is_atomic else "value"]
200-
self._strong = self._ptr["strong"]["v" if is_atomic else "value"]["value"]
201-
self._weak = self._ptr["weak"]["v" if is_atomic else "value"]["value"] - 1
206+
self._strong = unwrap_scalar_wrappers(self._ptr["strong"])
207+
self._weak = unwrap_scalar_wrappers(self._ptr["weak"]) - 1
202208

203209
def to_string(self):
204210
if self._is_atomic:

src/etc/lldb_providers.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
eBasicTypeUnsignedLong,
1010
eBasicTypeUnsignedChar,
1111
eFormatChar,
12+
eTypeIsInteger,
1213
)
1314

1415
from rust_types import is_tuple_fields
@@ -90,6 +91,12 @@ def unwrap_unique_or_non_null(unique_or_nonnull: SBValue) -> SBValue:
9091
return ptr if ptr.TypeIsPointerType() else ptr.GetChildAtIndex(0)
9192

9293

94+
def unwrap_scalar_wrappers(wrapper: SBValue) -> SBValue:
95+
while (wrapper.type.GetTypeFlags() & eTypeIsInteger) == 0:
96+
wrapper = wrapper.GetChildAtIndex(0)
97+
return wrapper
98+
99+
93100
class DefaultSyntheticProvider:
94101
def __init__(self, valobj: SBValue, _dict: LLDBOpaque):
95102
# logger = Logger.Logger()
@@ -1246,12 +1253,9 @@ class StdRcSyntheticProvider:
12461253
rust 1.33.0: struct NonNull<T> { pointer: *const T }
12471254
struct NonZero<T>(T)
12481255
struct RcInner<T> { strong: Cell<usize>, weak: Cell<usize>, value: T }
1249-
struct Cell<T> { value: UnsafeCell<T> }
1250-
struct UnsafeCell<T> { value: T }
12511256
12521257
struct Arc<T> { ptr: NonNull<ArcInner<T>>, ... }
1253-
struct ArcInner<T> { strong: atomic::AtomicUsize, weak: atomic::AtomicUsize, data: T }
1254-
struct AtomicUsize { v: UnsafeCell<usize> }
1258+
struct ArcInner<T> { strong: atomic::Atomic<usize>, weak: atomic::Atomic<usize>, data: T }
12551259
"""
12561260

12571261
def __init__(self, valobj: SBValue, _dict: LLDBOpaque, is_atomic: bool = False):
@@ -1261,16 +1265,8 @@ def __init__(self, valobj: SBValue, _dict: LLDBOpaque, is_atomic: bool = False):
12611265

12621266
self.value = self.ptr.GetChildMemberWithName("data" if is_atomic else "value")
12631267

1264-
self.strong = (
1265-
self.ptr.GetChildMemberWithName("strong")
1266-
.GetChildAtIndex(0)
1267-
.GetChildMemberWithName("value")
1268-
)
1269-
self.weak = (
1270-
self.ptr.GetChildMemberWithName("weak")
1271-
.GetChildAtIndex(0)
1272-
.GetChildMemberWithName("value")
1273-
)
1268+
self.strong = unwrap_scalar_wrappers(self.ptr.GetChildMemberWithName("strong"))
1269+
self.weak = unwrap_scalar_wrappers(self.ptr.GetChildMemberWithName("weak"))
12741270

12751271
self.value_builder = ValueBuilder(valobj)
12761272

src/etc/natvis/libcore.natvis

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,38 @@
8989
</Expand>
9090
</Type>
9191

92-
<Type Name="core::sync::atomic::AtomicBool">
93-
<DisplayString>{(bool)v.value}</DisplayString>
92+
<Type Name="core::sync::atomic::Atomic<bool>">
93+
<DisplayString>{(bool)v.value.__0}</DisplayString>
9494
</Type>
95-
<Type Name="core::sync::atomic::AtomicI8">
96-
<DisplayString>{v.value}</DisplayString>
95+
<Type Name="core::sync::atomic::Atomic<i8>">
96+
<DisplayString>{v.value.__0}</DisplayString>
9797
</Type>
98-
<Type Name="core::sync::atomic::AtomicI16">
99-
<DisplayString>{v.value}</DisplayString>
98+
<Type Name="core::sync::atomic::Atomic<i16">
99+
<DisplayString>{v.value.__0}</DisplayString>
100100
</Type>
101-
<Type Name="core::sync::atomic::AtomicI32">
102-
<DisplayString>{v.value}</DisplayString>
101+
<Type Name="core::sync::atomic::Atomic<i32>">
102+
<DisplayString>{v.value.__0}</DisplayString>
103103
</Type>
104-
<Type Name="core::sync::atomic::AtomicI64">
105-
<DisplayString>{v.value}</DisplayString>
104+
<Type Name="core::sync::atomic::Atomic<i64>">
105+
<DisplayString>{v.value.__0}</DisplayString>
106106
</Type>
107-
<Type Name="core::sync::atomic::AtomicIsize">
108-
<DisplayString>{v.value}</DisplayString>
107+
<Type Name="core::sync::atomic::Atomic<isize>">
108+
<DisplayString>{v.value.__0}</DisplayString>
109109
</Type>
110-
<Type Name="core::sync::atomic::AtomicU8">
111-
<DisplayString>{v.value}</DisplayString>
110+
<Type Name="core::sync::atomic::Atomic<u8>">
111+
<DisplayString>{v.value.__0}</DisplayString>
112112
</Type>
113-
<Type Name="core::sync::atomic::AtomicU16">
114-
<DisplayString>{v.value}</DisplayString>
113+
<Type Name="core::sync::atomic::Atomic<u16>">
114+
<DisplayString>{v.value.__0}</DisplayString>
115115
</Type>
116-
<Type Name="core::sync::atomic::AtomicU32">
117-
<DisplayString>{v.value}</DisplayString>
116+
<Type Name="core::sync::atomic::Atomic<u32>">
117+
<DisplayString>{v.value.__0}</DisplayString>
118118
</Type>
119-
<Type Name="core::sync::atomic::AtomicU64">
120-
<DisplayString>{v.value}</DisplayString>
119+
<Type Name="core::sync::atomic::Atomic<u64>">
120+
<DisplayString>{v.value.__0}</DisplayString>
121121
</Type>
122-
<Type Name="core::sync::atomic::AtomicUsize">
123-
<DisplayString>{v.value}</DisplayString>
122+
<Type Name="core::sync::atomic::Atomic<usize>">
123+
<DisplayString>{v.value.__0}</DisplayString>
124124
</Type>
125125

126126
<Type Name="core::time::Duration">

tests/debuginfo/numeric-types.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,52 +114,40 @@
114114
//@ cdb-check: [+0x000] __0 : 0x78 [Type: unsigned __int64]
115115

116116
//@ cdb-command: dx a_bool_t
117-
//@ cdb-check:a_bool_t : true [Type: core::sync::atomic::AtomicBool]
118-
//@ cdb-check: [+0x000] v : 0x1 [Type: core::cell::UnsafeCell<u8>]
117+
//@ cdb-check:a_bool_t : true [Type: core::sync::atomic::Atomic<bool>]
119118

120119
//@ cdb-command: dx a_bool_f
121-
//@ cdb-check:a_bool_f : false [Type: core::sync::atomic::AtomicBool]
122-
//@ cdb-check: [+0x000] v : 0x0 [Type: core::cell::UnsafeCell<u8>]
120+
//@ cdb-check:a_bool_f : false [Type: core::sync::atomic::Atomic<bool>]
123121

124122
//@ cdb-command: dx a_i8
125-
//@ cdb-check:a_i8 : 2 [Type: core::sync::atomic::AtomicI8]
126-
//@ cdb-check: [+0x000] v : 2 [Type: core::cell::UnsafeCell<i8>]
123+
//@ cdb-check:a_i8 : 2 [Type: core::sync::atomic::Atomic<i8>]
127124

128125
//@ cdb-command: dx a_i16
129-
//@ cdb-check:a_i16 : 4 [Type: core::sync::atomic::AtomicI16]
130-
//@ cdb-check: [+0x000] v : 4 [Type: core::cell::UnsafeCell<i16>]
126+
//@ cdb-check:a_i16 : 4 [Type: core::sync::atomic::Atomic<i16>]
131127

132128
//@ cdb-command: dx a_i32
133-
//@ cdb-check:a_i32 : 8 [Type: core::sync::atomic::AtomicI32]
134-
//@ cdb-check: [+0x000] v : 8 [Type: core::cell::UnsafeCell<i32>]
129+
//@ cdb-check:a_i32 : 8 [Type: core::sync::atomic::Atomic<i32>]
135130

136131
//@ cdb-command: dx a_i64
137-
//@ cdb-check:a_i64 : 16 [Type: core::sync::atomic::AtomicI64]
138-
//@ cdb-check: [+0x000] v : 16 [Type: core::cell::UnsafeCell<i64>]
132+
//@ cdb-check:a_i64 : 16 [Type: core::sync::atomic::Atomic<i64>]
139133

140134
//@ cdb-command: dx a_isize
141-
//@ cdb-check:a_isize : 32 [Type: core::sync::atomic::AtomicIsize]
142-
//@ cdb-check: [+0x000] v : 32 [Type: core::cell::UnsafeCell<isize>]
135+
//@ cdb-check:a_isize : 32 [Type: core::sync::atomic::Atomic<isize>]
143136

144137
//@ cdb-command: dx a_u8
145-
//@ cdb-check:a_u8 : 0x40 [Type: core::sync::atomic::AtomicU8]
146-
//@ cdb-check: [+0x000] v : 0x40 [Type: core::cell::UnsafeCell<u8>]
138+
//@ cdb-check:a_u8 : 0x40 [Type: core::sync::atomic::Atomic<u8>]
147139

148140
//@ cdb-command: dx a_u16
149-
//@ cdb-check:a_u16 : 0x80 [Type: core::sync::atomic::AtomicU16]
150-
//@ cdb-check: [+0x000] v : 0x80 [Type: core::cell::UnsafeCell<u16>]
141+
//@ cdb-check:a_u16 : 0x80 [Type: core::sync::atomic::Atomic<u16>]
151142

152143
//@ cdb-command: dx a_u32
153-
//@ cdb-check:a_u32 : 0x100 [Type: core::sync::atomic::AtomicU32]
154-
//@ cdb-check: [+0x000] v : 0x100 [Type: core::cell::UnsafeCell<u32>]
144+
//@ cdb-check:a_u32 : 0x100 [Type: core::sync::atomic::Atomic<u32>]
155145

156146
//@ cdb-command: dx a_u64
157-
//@ cdb-check:a_u64 : 0x200 [Type: core::sync::atomic::AtomicU64]
158-
//@ cdb-check: [+0x000] v : 0x200 [Type: core::cell::UnsafeCell<u64>]
147+
//@ cdb-check:a_u64 : 0x200 [Type: core::sync::atomic::Atomic<u64>]
159148

160149
//@ cdb-command: dx a_usize
161-
//@ cdb-check:a_usize : 0x400 [Type: core::sync::atomic::AtomicUsize]
162-
//@ cdb-check: [+0x000] v : 0x400 [Type: core::cell::UnsafeCell<usize>]
150+
//@ cdb-check:a_usize : 0x400 [Type: core::sync::atomic::Atomic<usize>]
163151

164152

165153
// === GDB TESTS ===================================================================================

tests/debuginfo/rc_arc.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838

3939
//@ cdb-command:dx arc,d
4040
//@ cdb-check:arc,d : 222 [Type: alloc::sync::Arc<i32,alloc::alloc::Global>]
41-
//@ cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
42-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
41+
//@ cdb-check: [Reference count] : 21 [Type: core::sync::atomic::Atomic<usize>]
42+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
4343

4444
//@ cdb-command:dx weak_arc,d
4545
//@ cdb-check:weak_arc,d : 222 [Type: alloc::sync::Weak<i32,alloc::alloc::Global>]
46-
//@ cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
47-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
46+
//@ cdb-check: [Reference count] : 21 [Type: core::sync::atomic::Atomic<usize>]
47+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
4848

4949
//@ cdb-command:dx dyn_rc,d
5050
//@ cdb-check:dyn_rc,d [Type: alloc::rc::Rc<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
@@ -76,28 +76,28 @@
7676

7777
//@ cdb-command:dx dyn_arc,d
7878
//@ cdb-check:dyn_arc,d [Type: alloc::sync::Arc<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
79-
//@ cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
80-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
79+
//@ cdb-check: [Reference count] : 51 [Type: core::sync::atomic::Atomic<usize>]
80+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
8181

8282
//@ cdb-command:dx dyn_arc_weak,d
8383
//@ cdb-check:dyn_arc_weak,d [Type: alloc::sync::Weak<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
84-
//@ cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
85-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
84+
//@ cdb-check: [Reference count] : 51 [Type: core::sync::atomic::Atomic<usize>]
85+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
8686

8787
//@ cdb-command:dx slice_arc,d
8888
//@ cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice2$<u32>,alloc::alloc::Global>]
8989
//@ cdb-check: [Length] : 3 [Type: [...]]
90-
//@ cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
91-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
90+
//@ cdb-check: [Reference count] : 61 [Type: core::sync::atomic::Atomic<usize>]
91+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
9292
//@ cdb-check: [0] : 4 [Type: u32]
9393
//@ cdb-check: [1] : 5 [Type: u32]
9494
//@ cdb-check: [2] : 6 [Type: u32]
9595

9696
//@ cdb-command:dx slice_arc_weak,d
9797
//@ cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice2$<u32>,alloc::alloc::Global>]
9898
//@ cdb-check: [Length] : 3 [Type: [...]]
99-
//@ cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
100-
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
99+
//@ cdb-check: [Reference count] : 61 [Type: core::sync::atomic::Atomic<usize>]
100+
//@ cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::Atomic<usize>]
101101
//@ cdb-check: [0] : 4 [Type: u32]
102102
//@ cdb-check: [1] : 5 [Type: u32]
103103
//@ cdb-check: [2] : 6 [Type: u32]

0 commit comments

Comments
 (0)