Skip to content

Commit 7d9573b

Browse files
committed
Auto merge of rust-lang#135192 - jdupak-ms:cdb-tests, r=wesleywiser
Add and improve debuginfo tests for Windows Adds new test for closures and function pointers. Improves robustness of existing tests by sorting wildcard matched outputs.
2 parents 6afee11 + f86ca11 commit 7d9573b

File tree

6 files changed

+289
-46
lines changed

6 files changed

+289
-46
lines changed

Diff for: tests/debuginfo/closures.rs

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//@ only-cdb
2+
//@ compile-flags:-g
3+
4+
// === CDB TESTS ===================================================================================
5+
// Generic functions cause ambigious breakpoints.
6+
// cdb-command:dx @$debuggerRootNamespace.Debugger.Settings.EngineInitialization.ResolveAmbiguousBreakpoints = true;
7+
// cdb-command:bp `closures.rs:57`
8+
// cdb-command:g
9+
// cdb-command:dx add_closure
10+
// cdb-check:add_closure [Type: closures::main::closure_env$0]
11+
// cdb-check: [+0x[...]] _ref__base_value : 0x[...] : 42 [Type: int *]
12+
// cdb-command:dx increment
13+
// cdb-check:increment [Type: closures::main::closure_env$1]
14+
// cdb-check: [+0x[...]] _ref__count : 0x[...] : 2 [Type: int *]
15+
// cdb-command:dx consume_closure
16+
// cdb-check:consume_closure [Type: closures::main::closure_env$2]
17+
// cdb-check: [+0x[...]] x : [...] [Type: alloc::string::String]
18+
// cdb-check: [+0x[...]] _ref__base_value : 0x[...] : 42 [Type: int *]
19+
// cdb-command:dx simple_closure
20+
// cdb-checksimple_closure [Type: closures::main::closure_env$5]
21+
// cdb-check: [+0x[...]] _ref__base_value : 0x[...] : 42 [Type: int *]
22+
// cdb-command:g
23+
// cdb-command:dx first_closure
24+
// cdb-check:first_closure [Type: closures::main::closure_env$6]
25+
// cdb-check: [+0x[...]] _ref__variable : 0x[...] : 1 [Type: __int64 *]
26+
// cdb-check: [+0x[...]] _ref__constant : 0x[...] : 2 [Type: __int64 *]
27+
// cdb-check: [+0x[...]] _ref__a_struct : 0x[...] [Type: closures::Struct *]
28+
// cdb-check: [+0x[...]] _ref__struct_ref : 0x[...] [Type: closures::Struct * *]
29+
// cdb-check: [+0x[...]] _ref__owned_value : 0x[...] [Type: __int64 * *]
30+
// cdb-command:g
31+
// cdb-command:dx many_param_closure
32+
// cdb-check:many_param_closure [Type: closures::main::closure_env$7]
33+
// cdb-check: [+0x[...]] _ref__base_value : 0x[...] : 42 [Type: int *]
34+
// cdb-command:g
35+
// cdb-command:dv
36+
// cdb-command:dx generic_closure
37+
// cdb-check:generic_closure [Type: closures::generic_func::closure_env$0<i32>]
38+
// cdb-check: [+0x[...]] _ref__x : 0x[...] : 42 [Type: int *]
39+
// cdb-command:g
40+
// cdb-command:dx generic_closure
41+
// cdb-check:generic_closure [Type: closures::generic_func::closure_env$0<ref$<str$> >]
42+
// cdb-check: [+0x000] _ref__x : 0x[...] : "base_value" [Type: ref$<str$> *]
43+
// cdb-command:g
44+
// cdb-command:dx second_closure
45+
// cdb-check:second_closure [Type: closures::main::closure_env$8]
46+
// cdb-check: [+0x[...]] _ref__variable : 0x[...] : 2 [Type: __int64 *]
47+
// cdb-check: [+0x[...]] _ref__constant : 0x[...] : 2 [Type: __int64 *]
48+
// cdb-check: [+0x[...]] _ref__a_struct : 0x[...] [Type: closures::Struct *]
49+
// cdb-check: [+0x[...]] _ref__struct_ref : 0x[...] [Type: closures::Struct * *]
50+
// cdb-check: [+0x[...]] _ref__owned_value : 0x[...] [Type: __int64 * *]
51+
52+
#[inline(never)]
53+
fn generic_func<Tfunc: std::fmt::Debug>(x: Tfunc) {
54+
let generic_closure = |a: u32| {
55+
println!("{:?}", x);
56+
};
57+
58+
_zzz(); // #break
59+
60+
// rustc really wants to inline this closure, so we use black_box instead of calling it
61+
std::hint::black_box(generic_closure);
62+
}
63+
64+
struct Struct {
65+
a: isize,
66+
b: f64,
67+
c: usize,
68+
}
69+
70+
fn main() {
71+
let base_value = 42;
72+
let mut count = 0;
73+
74+
let add_closure = |a: i32, b: i32| a + b + base_value;
75+
76+
add_closure(40, 2);
77+
78+
let mut increment = || {
79+
count += 1;
80+
};
81+
82+
increment(); // count: 1
83+
increment(); // count: 2
84+
85+
let x = String::from("hello");
86+
87+
// Define a closure that consumes the captured variable `x`
88+
let consume_closure = move || {
89+
drop(x);
90+
base_value + 1
91+
};
92+
93+
consume_closure();
94+
95+
let paramless_closure = || 42;
96+
97+
let void_closure = |a: i32| {
98+
println!("Closure with arg: {:?}", a);
99+
};
100+
101+
let simple_closure = || {
102+
let incremented_value = base_value + 1;
103+
incremented_value
104+
};
105+
106+
let result = /*42; */ add_closure(40, 2);
107+
println!("Result: {:?}", result);
108+
void_closure(result);
109+
let result = simple_closure();
110+
println!("Result: {:?}", result);
111+
112+
let mut variable = 1;
113+
let constant = 2;
114+
115+
let a_struct = Struct { a: -3, b: 4.5, c: 5 };
116+
117+
_zzz(); // #break
118+
119+
let struct_ref = &a_struct;
120+
let owned_value: Box<_> = Box::new(6);
121+
122+
{
123+
let mut first_closure = || {
124+
variable = constant + a_struct.a + struct_ref.a + *owned_value;
125+
};
126+
127+
_zzz(); // #break
128+
129+
first_closure();
130+
}
131+
132+
let many_param_closure =
133+
|a: i32, b: f64, c: usize, d: Struct| base_value + a + b as i32 + c as i32 + d.c as i32;
134+
135+
_zzz(); // #break
136+
137+
many_param_closure(1, 2.0, 3, Struct { a: 4, b: 5.0, c: 6 });
138+
139+
generic_func(42);
140+
generic_func("base_value");
141+
142+
{
143+
let mut second_closure = || {
144+
variable = constant + a_struct.a + struct_ref.a + *owned_value;
145+
};
146+
147+
_zzz(); // #break
148+
149+
second_closure();
150+
}
151+
}
152+
153+
fn _zzz() {
154+
()
155+
}

Diff for: tests/debuginfo/coroutine-closure.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(async_closure)]
2+
//@ only-cdb
3+
//@ compile-flags:-g --edition=2021
4+
5+
// === CDB TESTS ===================================================================================
6+
7+
// cdb-command: g
8+
// cdb-command: dx closure
9+
// cdb-check:closure [Type: coroutine_closure::main::closure_env$0]
10+
// cdb-check: [+0x[...]] y : "" [Type: alloc::string::String]
11+
// cdb-check: [+0x[...]] x : "" [Type: alloc::string::String]
12+
#![allow(unused)]
13+
fn main() {
14+
let x = String::new();
15+
let y = String::new();
16+
let closure = async move || {
17+
drop(y);
18+
println!("{x}");
19+
};
20+
21+
_zzz(); // #break
22+
23+
std::hint::black_box(closure);
24+
}
25+
26+
#[inline(never)]
27+
fn _zzz() {
28+
()
29+
}

Diff for: tests/debuginfo/fn_ptr.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//@ only-cdb
2+
//@ compile-flags:-g
3+
4+
// === CDB TESTS ===================================================================================
5+
6+
// cdb-command: g
7+
// cdb-command: dx basic
8+
// cdb-check: basic : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$0,tuple$<i32,i32> >+0x0 [Type: int (__cdecl*)(int,int)]
9+
// cdb-check: a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$0,tuple$<i32,i32> >+0x0 [Type: int __cdecl(int,int)]
10+
11+
// cdb-command: dx paramless
12+
// cdb-check: paramless : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$1,tuple$<> >+0x0 [Type: int (__cdecl*)()]
13+
// cdb-check: a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$1,tuple$<> >+0x0 [Type: int __cdecl()]
14+
15+
// cdb-command: dx my_struct
16+
// cdb-check: my_struct [Type: fn_ptr::MyStruct]
17+
// cdb-check: [+0x000] my_field : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$2,tuple$<ref$<fn_ptr::MyStruct> > >+0x0 [Type: int (__cdecl*)(fn_ptr::MyStruct *)]
18+
19+
// cdb-command: dx non_rec_struct
20+
// cdb-check: non_rec_struct [Type: fn_ptr::NonRecStruct]
21+
// cdb-check: [+0x000] my_field : [...] : a!core::ops::function::FnOnce::call_once<fn_ptr::main::closure_env$3,tuple$<i32> >+0x0 [Type: int (__cdecl*)(int)]
22+
23+
type BasicFnPtr = fn(i32, i32) -> i32;
24+
25+
pub type ParamlessFnPtr = fn() -> i32;
26+
27+
type MyFnPtr = fn(b: &MyStruct) -> i32;
28+
29+
type NonRecFnPtr = fn(i: i32) -> i32;
30+
31+
struct MyStruct {
32+
my_field: MyFnPtr,
33+
}
34+
35+
struct NonRecStruct {
36+
my_field: NonRecFnPtr,
37+
}
38+
39+
fn main() {
40+
let basic: BasicFnPtr = |a, b| a + b;
41+
let paramless: ParamlessFnPtr = || 1;
42+
let my_struct = MyStruct { my_field: |_| 1 };
43+
let non_rec_struct = NonRecStruct { my_field: |i| i };
44+
45+
_zzz(); // #break
46+
}
47+
48+
#[inline(never)]
49+
fn _zzz() {
50+
()
51+
}

Diff for: tests/debuginfo/lexical-scope-in-if-let.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,32 @@
4747

4848
// === CDB TESTS ==================================================================================
4949

50+
// Note: `/n` causes the the output to be sorted to avoid depending on the order in PDB which may be arbitrary.
51+
5052
// cdb-command: g
51-
// cdb-command: dv
53+
// cdb-command: dv /n
5254
// cdb-check:[...]a = 0n123
5355

5456
// cdb-command: g
55-
// cdb-command: dv
57+
// cdb-command: dv /n
5658
// cdb-check:[...]a = 0n123
5759
// cdb-check:[...]x = 0n42
5860

5961
// cdb-command: g
60-
// cdb-command: dv
62+
// cdb-command: dv /n
6163
// cdb-check:[...]a = 0n123
62-
// cdb-check:[...]x = 0n42
6364
// cdb-check:[...]b = 0n456
65+
// cdb-check:[...]x = 0n42
6466
// cdb-check:[...]y = true
6567

6668
// cdb-command: g
67-
// cdb-command: dv
68-
// cdb-check:[...]z = 0n10
69-
// cdb-check:[...]c = 0n789
69+
// cdb-command: dv /n
7070
// cdb-check:[...]a = 0n123
71-
// cdb-check:[...]x = 0n42
7271
// cdb-check:[...]b = 0n456
72+
// cdb-check:[...]c = 0n789
73+
// cdb-check:[...]x = 0n42
7374
// cdb-check:[...]y = true
75+
// cdb-check:[...]z = 0n10
7476

7577
fn main() {
7678
let a = id(123);
@@ -95,6 +97,8 @@ fn main() {
9597
}
9698

9799
#[inline(never)]
98-
fn id<T>(value: T) -> T { value }
100+
fn id<T>(value: T) -> T {
101+
value
102+
}
99103

100-
fn zzz() { }
104+
fn zzz() {}

Diff for: tests/debuginfo/step-into-match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
// cdb-check: [...]: match (a, b) {
301301

302302
// cdb-command: t
303-
// cdb-check: [...]: (_, _) => 5
303+
// cdb-check: [...]: (_, _) => 5,
304304

305305
// cdb-command: t
306306
// cdb-check: [...]: }
@@ -378,6 +378,6 @@ fn match_tuple(a: u8, b: i8) -> u32 {
378378
(29, _) => 2,
379379
(5, 12) => 3,
380380
(_, 9) => 4,
381-
(_, _) => 5
381+
(_, _) => 5,
382382
}
383383
}

0 commit comments

Comments
 (0)