Skip to content

Commit 874cac1

Browse files
committed
Update debuginfo tests
1 parent c0d77af commit 874cac1

File tree

6 files changed

+84
-33
lines changed

6 files changed

+84
-33
lines changed

library/alloc/src/raw_rc.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub struct RefCounts {
3838
pub strong: UnsafeCell<usize>,
3939
}
4040

41+
impl RefCounts {
42+
const fn new(strong_cont: usize) -> Self {
43+
Self { weak: UnsafeCell::new(1), strong: UnsafeCell::new(strong_cont) }
44+
}
45+
}
46+
4147
struct RcLayout {
4248
allocation_layout: Layout,
4349
allocation_offset_bytes: usize,
@@ -74,12 +80,12 @@ impl RcLayout {
7480
}
7581
}
7682

77-
trait RcLayoutExt<T> {
83+
trait RcLayoutExt {
7884
const RC_LAYOUT: RcLayout;
7985
}
8086

81-
impl<T> RcLayoutExt<T> for T {
82-
const RC_LAYOUT: RcLayout = match RcLayout::of::<T>() {
87+
impl<T> RcLayoutExt for T {
88+
const RC_LAYOUT: RcLayout = match RcLayout::of::<Self>() {
8389
Ok(rc_layout) => rc_layout,
8490
Err(_) => panic!("layout size is too large"),
8591
};
@@ -111,9 +117,7 @@ unsafe fn write_rc_allocation<const STRONG_COUNT: usize>(
111117
) -> NonNull<()> {
112118
let allocation_ptr = ptr.cast::<()>();
113119
let value_ptr = unsafe { allocation_ptr.byte_add(rc_layout.allocation_offset_bytes) };
114-
115-
let ref_counts =
116-
const { RefCounts { weak: UnsafeCell::new(1), strong: UnsafeCell::new(STRONG_COUNT) } };
120+
let ref_counts = const { RefCounts::new(STRONG_COUNT) };
117121

118122
unsafe { ref_counts_ptr_from_value_ptr(value_ptr).write(ref_counts) };
119123

@@ -271,7 +275,7 @@ impl<T, A> RawWeak<T, A>
271275
where
272276
T: ?Sized,
273277
{
274-
pub unsafe fn from_raw_parts(ptr: NonNull<T>, alloc: A) -> Self {
278+
pub const unsafe fn from_raw_parts(ptr: NonNull<T>, alloc: A) -> Self {
275279
Self { ptr, alloc }
276280
}
277281

@@ -295,7 +299,7 @@ where
295299
U: ?Sized,
296300
F: FnOnce(NonNull<T>) -> NonNull<U>,
297301
{
298-
RawWeak { ptr: f(self.ptr), alloc: self.alloc }
302+
unsafe { RawWeak::from_raw_parts(f(self.ptr), self.alloc) }
299303
}
300304

301305
pub unsafe fn cast<U>(self) -> RawWeak<U, A> {
@@ -453,9 +457,11 @@ where
453457

454458
impl<T, A> RawWeak<T, A> {
455459
pub const fn new_dangling_in(alloc: A) -> Self {
456-
Self {
457-
ptr: unsafe { NonNull::new_unchecked(ptr::without_provenance_mut::<T>(usize::MAX)) },
458-
alloc,
460+
unsafe {
461+
Self::from_raw_parts(
462+
NonNull::new_unchecked(ptr::without_provenance_mut::<T>(usize::MAX)),
463+
alloc,
464+
)
459465
}
460466
}
461467

@@ -1648,6 +1654,13 @@ where
16481654
{
16491655
}
16501656

1657+
impl<T, U> DispatchFromDyn<RawUniqueRc<U, Global>> for RawUniqueRc<T, Global>
1658+
where
1659+
T: ?Sized + Unsize<U>,
1660+
U: ?Sized,
1661+
{
1662+
}
1663+
16511664
impl<T, A> Debug for RawUniqueRc<T, A>
16521665
where
16531666
T: Debug + ?Sized,

src/etc/gdb_providers.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,29 @@ def display_hint():
182182
return "array"
183183

184184

185+
_REF_COUNTS_TYPE = None
186+
187+
188+
def _get_ref_counts_ptr_type():
189+
global _REF_COUNTS_TYPE
190+
191+
if _REF_COUNTS_TYPE is None:
192+
_REF_COUNTS_TYPE = gdb.lookup_type("alloc::raw_rc::RefCounts").pointer()
193+
194+
return _REF_COUNTS_TYPE
195+
196+
185197
class StdRcProvider(printer_base):
186198
def __init__(self, valobj, is_atomic=False):
187199
self._valobj = valobj
188200
self._is_atomic = is_atomic
189-
self._ptr = unwrap_unique_or_non_null(valobj["ptr"])
190-
self._value = self._ptr["data" if is_atomic else "value"]
191-
self._strong = self._ptr["strong"]["v" if is_atomic else "value"]["value"]
192-
self._weak = self._ptr["weak"]["v" if is_atomic else "value"]["value"] - 1
201+
self._ptr = unwrap_unique_or_non_null(valobj["raw_rc"]["weak"]["ptr"])
202+
self._value = self._ptr.dereference()
203+
204+
ref_counts_ptr = self._ptr.reinterpret_cast(_get_ref_counts_ptr_type()) - 1
205+
206+
self._strong = ref_counts_ptr["strong"]["value"]
207+
self._weak = ref_counts_ptr["weak"]["value"] - 1
193208

194209
def to_string(self):
195210
if self._is_atomic:

src/etc/lldb_providers.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
from lldb import (
4+
SBAddress,
45
SBData,
56
SBError,
67
eBasicTypeLong,
@@ -730,6 +731,18 @@ def StdRcSummaryProvider(valobj, dict):
730731
return "strong={}, weak={}".format(strong, weak)
731732

732733

734+
_REF_COUNTS_TYPE = None
735+
736+
737+
def _get_or_init_ref_counts_type(target):
738+
global _REF_COUNTS_TYPE
739+
740+
if _REF_COUNTS_TYPE is None:
741+
_REF_COUNTS_TYPE = target.FindFirstType("alloc::raw_rc::RefCounts")
742+
743+
return _REF_COUNTS_TYPE
744+
745+
733746
class StdRcSyntheticProvider:
734747
"""Pretty-printer for alloc::rc::Rc<T> and alloc::sync::Arc<T>
735748
@@ -750,21 +763,33 @@ def __init__(self, valobj, dict, is_atomic=False):
750763
# type: (SBValue, dict, bool) -> StdRcSyntheticProvider
751764
self.valobj = valobj
752765

753-
self.ptr = unwrap_unique_or_non_null(self.valobj.GetChildMemberWithName("ptr"))
766+
ptr = (
767+
self.valobj.GetChildMemberWithName("raw_rc")
768+
.GetChildMemberWithName("weak")
769+
.GetChildMemberWithName("ptr")
770+
.GetChildMemberWithName("pointer")
771+
)
754772

755-
self.value = self.ptr.GetChildMemberWithName("data" if is_atomic else "value")
773+
self.value = ptr.deref.Clone("value")
756774

757-
self.strong = (
758-
self.ptr.GetChildMemberWithName("strong")
759-
.GetChildAtIndex(0)
760-
.GetChildMemberWithName("value")
761-
)
762-
self.weak = (
763-
self.ptr.GetChildMemberWithName("weak")
764-
.GetChildAtIndex(0)
765-
.GetChildMemberWithName("value")
775+
target = valobj.GetTarget()
776+
ref_counts_type = _get_or_init_ref_counts_type(target)
777+
ref_counts_address = ptr.GetValueAsUnsigned() - ref_counts_type.size
778+
779+
ref_counts_value = target.CreateValueFromAddress(
780+
"ref_counts",
781+
SBAddress(ref_counts_address, target),
782+
ref_counts_type,
766783
)
767784

785+
self.strong = ref_counts_value.GetChildMemberWithName(
786+
"strong"
787+
).GetChildMemberWithName("value")
788+
789+
self.weak = ref_counts_value.GetChildMemberWithName(
790+
"weak"
791+
).GetChildMemberWithName("value")
792+
768793
self.value_builder = ValueBuilder(valobj)
769794

770795
self.update()

tests/codegen/issues/issue-111603.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub fn new_from_array(x: u64) -> Arc<[u64]> {
2020
// CHECK-LABEL: @new_uninit
2121
#[no_mangle]
2222
pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> {
23-
// CHECK: call alloc::sync::arcinner_layout_for_value_layout
24-
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
23+
// CHECK-NOT: call alloc::raw_rc::RcLayout::from_value_layout
2524
let mut arc = Arc::new_uninit();
2625
unsafe { Arc::get_mut_unchecked(&mut arc) }.write([x; 1000]);
2726
unsafe { arc.assume_init() }
@@ -30,8 +29,8 @@ pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> {
3029
// CHECK-LABEL: @new_uninit_slice
3130
#[no_mangle]
3231
pub fn new_uninit_slice(x: u64) -> Arc<[u64]> {
33-
// CHECK: call alloc::sync::arcinner_layout_for_value_layout
34-
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
32+
// CHECK: call alloc::raw_rc::RcLayout::from_value_layout
33+
// CHECK-NOT: call alloc::raw_rc::RcLayout::from_value_layout
3534
let mut arc = Arc::new_uninit_slice(1000);
3635
for elem in unsafe { Arc::get_mut_unchecked(&mut arc) } {
3736
elem.write(x);

tests/debuginfo/rc_arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// lldb-command:v rc
2020
// lldb-check:[...] strong=11, weak=1 { value = 111 }
2121
// lldb-command:v arc
22-
// lldb-check:[...] strong=21, weak=1 { data = 222 }
22+
// lldb-check:[...] strong=21, weak=1 { value = 222 }
2323

2424
// === CDB TESTS ==================================================================================
2525

tests/debuginfo/strings-and-strs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// gdb-check:$4 = ("Hello", "World")
2020

2121
// gdb-command:print str_in_rc
22-
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<alloc::rc::RcInner<&str>> {pointer: 0x[...]}, phantom: core::marker::PhantomData<alloc::rc::RcInner<&str>>, alloc: alloc::alloc::Global}
22+
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {raw_rc: alloc::raw_rc::RawRc<&str, alloc::alloc::Global> {weak: alloc::raw_rc::RawWeak<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<&str> {pointer: 0x[...]}, alloc: alloc::alloc::Global}, _phantom_data: core::marker::PhantomData<&str>}}
2323

2424
// === LLDB TESTS ==================================================================================
2525
// lldb-command:run
@@ -38,7 +38,6 @@
3838
// lldb-command:v str_in_rc
3939
// lldb-check:(alloc::rc::Rc<&str, alloc::alloc::Global>) str_in_rc = strong=1, weak=0 { value = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } }
4040

41-
4241
#![allow(unused_variables)]
4342
#![feature(omit_gdb_pretty_printer_section)]
4443
#![omit_gdb_pretty_printer_section]

0 commit comments

Comments
 (0)