Skip to content

Commit 543ab99

Browse files
committed
Auto merge of rust-lang#85448 - nanguye2496:nanguye2496/debuginfo_tests, r=Mark-Simulacrum
Add debug info tests for range, fix-sized array, and cell types This PR add several debug info tests to guarantee that the displays of fixed sized arrays, range types, cell types, threads, locks, and mutexes in CDB are correct. It also updates CDB tests for slices in pretty-std.rs after string visualization in WinDbg is fixed by this PR: rust-lang#81898.
2 parents a5b7511 + 0d917a6 commit 543ab99

10 files changed

+337
-5
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Testing the display of fixed sized arrays in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
9+
// cdb-command: g
10+
11+
// cdb-command: dx xs,d
12+
// cdb-check:xs,d [Type: int [5]]
13+
// cdb-check: [0] : 1 [Type: int]
14+
// cdb-check: [1] : 2 [Type: int]
15+
// cdb-check: [2] : 3 [Type: int]
16+
// cdb-check: [3] : 4 [Type: int]
17+
// cdb-check: [4] : 5 [Type: int]
18+
19+
// cdb-command: dx ys,d
20+
// cdb-check:ys,d [Type: int [3]]
21+
// cdb-check: [0] : 0 [Type: int]
22+
// cdb-check: [1] : 0 [Type: int]
23+
// cdb-check: [2] : 0 [Type: int]
24+
25+
fn main() {
26+
// Fixed-size array (type signature is superfluous)
27+
let xs: [i32; 5] = [1, 2, 3, 4, 5];
28+
29+
// All elements can be initialized to the same value
30+
let ys: [i32; 3] = [0; 3];
31+
32+
// Indexing starts at 0
33+
println!("first element of the array: {}", xs[0]);
34+
println!("second element of the array: {}", xs[1]);
35+
36+
zzz(); // #break
37+
}
38+
39+
fn zzz() { () }

src/test/debuginfo/mutable-locs.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Testing the display of Cell, RefCell, and RefMut in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
9+
// cdb-command: g
10+
11+
// 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>]
14+
15+
// 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]
18+
19+
// 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>]
23+
24+
// 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]
27+
28+
// 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]
32+
33+
#![allow(unused_variables)]
34+
35+
use std::cell::{Cell, RefCell};
36+
37+
fn main() {
38+
let static_c = Cell::new(5);
39+
static_c.set(10);
40+
41+
let dynamic_c = RefCell::new(5);
42+
dynamic_c.replace(15);
43+
44+
let dynamic_c_0 = RefCell::new(15);
45+
let mut b = dynamic_c_0.borrow_mut();
46+
*b = 42;
47+
48+
zzz(); // #break
49+
}
50+
51+
fn zzz() {()}

src/test/debuginfo/mutex.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Testing the display of Mutex and MutexGuard in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.21287.1005
5+
// compile-flags:-g
6+
// ignore-tidy-linelength
7+
8+
// === CDB TESTS ==================================================================================
9+
//
10+
// cdb-command:g
11+
//
12+
// cdb-command:dx m,d
13+
// cdb-check:m,d [Type: std::sync::mutex::Mutex<i32>]
14+
// cdb-check: [...] inner [Type: std::sys_common::mutex::MovableMutex]
15+
// cdb-check: [...] poison [Type: std::sync::poison::Flag]
16+
// cdb-check: [...] data [Type: core::cell::UnsafeCell<i32>]
17+
18+
//
19+
// cdb-command:dx m.data,d
20+
// cdb-check:m.data,d [Type: core::cell::UnsafeCell<i32>]
21+
// cdb-check: [...] value : 0 [Type: int]
22+
23+
//
24+
// cdb-command:dx lock,d
25+
// cdb-check:lock,d : Ok [Type: enum$<core::result::Result<std::sync::mutex::MutexGuard<i32>, enum$<std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32>>, 0, 1, Poisoned>>>]
26+
// cdb-check: [...] variant$ : Ok (0) [Type: core::result::Result]
27+
// cdb-check: [...] __0 [Type: std::sync::mutex::MutexGuard<i32>]
28+
29+
use std::sync::Mutex;
30+
31+
#[allow(unused_variables)]
32+
fn main()
33+
{
34+
let m = Mutex::new(0);
35+
let lock = m.try_lock();
36+
zzz(); // #break
37+
}
38+
39+
fn zzz() {}

src/test/debuginfo/pretty-std.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// compile-flags:-g
66
// min-gdb-version: 7.7
77
// min-lldb-version: 310
8+
// min-cdb-version: 10.0.18317.1001
89

910
// === GDB TESTS ===================================================================================
1011

@@ -71,8 +72,12 @@
7172
// cdb-command: g
7273

7374
// cdb-command: dx slice,d
74-
// cdb-check:slice,d [...]
75-
// NOTE: While slices have a .natvis entry that works in VS & VS Code, it fails in CDB 10.0.18362.1
75+
// cdb-check:slice,d : { len=4 } [Type: slice<i32>]
76+
// cdb-check: [len] : 4 [Type: [...]]
77+
// cdb-check: [0] : 0 [Type: int]
78+
// cdb-check: [1] : 1 [Type: int]
79+
// cdb-check: [2] : 2 [Type: int]
80+
// cdb-check: [3] : 3 [Type: int]
7681

7782
// cdb-command: dx vec,d
7883
// cdb-check:vec,d [...] : { len=4 } [Type: [...]::Vec<u64, alloc::alloc::Global>]
@@ -84,8 +89,7 @@
8489
// cdb-check: [3] : 7 [Type: unsigned __int64]
8590

8691
// cdb-command: dx str_slice
87-
// cdb-check:str_slice [...]
88-
// NOTE: While string slices have a .natvis entry that works in VS & VS Code, it fails in CDB
92+
// cdb-check:str_slice : "IAMA string slice!" [Type: str]
8993

9094
// cdb-command: dx string
9195
// cdb-check:string : "IAMA string!" [Type: [...]::String]
@@ -113,9 +117,15 @@
113117

114118
// cdb-command: dx some
115119
// cdb-check:some : Some [Type: enum$<core::option::Option<i16>>]
120+
// cdb-check: [...] variant$ : Some (0x1) [Type: core::option::Option]
121+
// cdb-check: [...] __0 : 8 [Type: short]
122+
116123
// cdb-command: dx none
117124
// cdb-check:none : None [Type: enum$<core::option::Option<i64>>]
125+
// cdb-check: [...] variant$ : None (0x0) [Type: core::option::Option]
126+
118127
// cdb-command: dx some_string
128+
// NOTE: cdb fails to interpret debug info of Option enums on i686.
119129
// cdb-check:some_string [Type: enum$<core::option::Option<alloc::string::String>, 1, [...], Some>]
120130

121131
#![allow(unused_variables)]

src/test/debuginfo/range-types.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Testing the display of range types in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
9+
// cdb-command: g
10+
11+
// cdb-command: dx r1,d
12+
// cdb-check:r1,d [Type: core::ops::range::Range<i32>]
13+
// cdb-check: [...] start : 3 [Type: int]
14+
// cdb-check: [...] end : 5 [Type: int]
15+
16+
// cdb-command: dx r2,d
17+
// cdb-check:r2,d [Type: core::ops::range::RangeFrom<i32>]
18+
// cdb-check: [...] start : 2 [Type: int]
19+
20+
// cdb-command: dx r3,d
21+
// cdb-check:r3,d [Type: core::ops::range::RangeInclusive<i32>]
22+
// cdb-check: [...] start : 1 [Type: int]
23+
// cdb-check: [...] end : 4 [Type: int]
24+
// cdb-check: [...] exhausted : false [Type: bool]
25+
26+
// cdb-command: dx r4,d
27+
// cdb-check:r4,d [Type: core::ops::range::RangeToInclusive<i32>]
28+
// cdb-check: [...] end : 3 [Type: int]
29+
30+
// cdb-command: dx r5,d
31+
// cdb-check:r5,d [Type: core::ops::range::RangeFull]
32+
33+
#[allow(unused_variables)]
34+
35+
use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeToInclusive};
36+
37+
fn main()
38+
{
39+
let r1 = Range{start: 3, end: 5};
40+
let r2 = RangeFrom{start: 2};
41+
let r3 = RangeInclusive::new(1, 4);
42+
let r4 = RangeToInclusive{end: 3};
43+
let r5 = RangeFull{};
44+
zzz(); // #break
45+
}
46+
47+
fn zzz() { () }

src/test/debuginfo/rc_arc.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// ignore-windows pretty-printers are not loaded
1+
// pretty-printers are not loaded
22
// compile-flags:-g
3+
// ignore-tidy-linelength
34

45
// min-gdb-version: 8.1
6+
// min-cdb-version: 10.0.18317.1001
57

68
// === GDB TESTS ==================================================================================
79

@@ -22,6 +24,29 @@
2224
// lldb-command:print a
2325
// lldb-check:[...]$1 = strong=2, weak=1 { data = 42 }
2426

27+
// === CDB TESTS ==================================================================================
28+
29+
// cdb-command:g
30+
31+
// cdb-command:dx r,d
32+
// cdb-check:r,d : 42 [Type: alloc::rc::Rc<i32>]
33+
34+
// cdb-command:dx r1,d
35+
// cdb-check:r1,d : 42 [Type: alloc::rc::Rc<i32>]
36+
37+
// cdb-command:dx w1,d
38+
// cdb-check:w1,d [Type: alloc::rc::Weak<i32>]
39+
// cdb-check: [...] ptr : [...] [Type: core::ptr::non_null::NonNull<alloc::rc::RcBox<i32>>]
40+
41+
// cdb-command:dx a,d
42+
// cdb-check:a,d : 42 [Type: alloc::sync::Arc<i32>]
43+
44+
// cdb-command:dx a1,d
45+
// cdb-check:a1,d : 42 [Type: alloc::sync::Arc<i32>]
46+
47+
// cdb-command:dx w2,d
48+
// cdb-check:w2,d : 42 [Type: alloc::sync::Weak<i32>]
49+
2550
use std::rc::Rc;
2651
use std::sync::Arc;
2752

src/test/debuginfo/result-types.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// cdb-only
2+
// min-cdb-version: 10.0.18317.1001
3+
// compile-flags:-g
4+
5+
// === CDB TESTS ==================================================================================
6+
7+
// cdb-command: g
8+
9+
// cdb-command: dx x,d
10+
// cdb-check:x,d : Ok [Type: enum$<core::result::Result<i32, str>>]
11+
// cdb-check: [...] __0 : -3 [Type: int]
12+
13+
// cdb-command: dx y
14+
// cdb-check:y : Err [Type: enum$<core::result::Result<i32, str>>]
15+
// cdb-check: [...] __0 : "Some error message" [Type: str]
16+
17+
fn main()
18+
{
19+
let x: Result<i32, &str> = Ok(-3);
20+
assert_eq!(x.is_ok(), true);
21+
22+
let y: Result<i32, &str> = Err("Some error message");
23+
assert_eq!(y.is_ok(), false);
24+
25+
zzz(); // #break.
26+
}
27+
28+
fn zzz() { () }

src/test/debuginfo/rwlock-read.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Testing the display of RwLock and RwLockReadGuard in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
//
9+
// cdb-command:g
10+
//
11+
// cdb-command:dx l
12+
// cdb-check:l [Type: std::sync::rwlock::RwLock<i32>]
13+
// cdb-check: [...] poison [Type: std::sync::poison::Flag]
14+
// cdb-check: [...] data [Type: core::cell::UnsafeCell<i32>]
15+
//
16+
// cdb-command:dx r
17+
// cdb-check:r [Type: std::sync::rwlock::RwLockReadGuard<i32>]
18+
// cdb-check: [...] lock : [...] [Type: std::sync::rwlock::RwLock<i32> *]
19+
//
20+
// 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]
23+
24+
#[allow(unused_variables)]
25+
26+
use std::sync::RwLock;
27+
28+
fn main()
29+
{
30+
let l = RwLock::new(0);
31+
let r = l.read().unwrap();
32+
zzz(); // #break
33+
}
34+
35+
fn zzz() {}

src/test/debuginfo/rwlock-write.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Testing the display of RwLockWriteGuard.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
//
9+
// cdb-command:g
10+
//
11+
// cdb-command:dx w
12+
// cdb-check:w [Type: std::sync::rwlock::RwLockWriteGuard<i32>]
13+
// cdb-check: [...] lock : [...] [Type: std::sync::rwlock::RwLock<i32> *]
14+
// cdb-check: [...] poison [Type: std::sync::poison::Guard]
15+
16+
#[allow(unused_variables)]
17+
18+
use std::sync::RwLock;
19+
20+
fn main()
21+
{
22+
let l = RwLock::new(0);
23+
let w = l.write().unwrap();
24+
zzz(); // #break
25+
}
26+
27+
fn zzz() {}

src/test/debuginfo/thread.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Testing the the display of JoinHandle and Thread in cdb.
2+
3+
// cdb-only
4+
// min-cdb-version: 10.0.18317.1001
5+
// compile-flags:-g
6+
7+
// === CDB TESTS ==================================================================================
8+
//
9+
// cdb-command:g
10+
//
11+
// cdb-command:dx join_handle,d
12+
// cdb-check:join_handle,d [Type: std::thread::JoinHandle<tuple<>>]
13+
// cdb-check: [...] __0 [Type: std::thread::JoinInner<tuple<>>]
14+
//
15+
// cdb-command:dx t,d
16+
// cdb-check:t,d : [...] [Type: std::thread::Thread *]
17+
// cdb-check: [...] inner : {...} [Type: alloc::sync::Arc<std::thread::Inner>]
18+
19+
use std::thread;
20+
21+
#[allow(unused_variables)]
22+
fn main()
23+
{
24+
let join_handle = thread::spawn(|| {
25+
println!("Initialize a thread");
26+
});
27+
let t = join_handle.thread();
28+
zzz(); // #break
29+
}
30+
31+
fn zzz() {}

0 commit comments

Comments
 (0)