]> git.proxmox.com Git - rustc.git/blob - src/test/debuginfo/type-names.rs
New upstream version 1.57.0+dfsg1
[rustc.git] / src / test / debuginfo / type-names.rs
1 // ignore-lldb
2
3 // GDB changed the way that it formatted Foreign types
4 // min-gdb-version: 9.2
5
6 // compile-flags:-g
7
8 // === GDB TESTS ===================================================================================
9
10 // gdb-command:run
11
12 // STRUCTS
13 // gdb-command:whatis simple_struct
14 // gdb-check:type = type_names::Struct1
15
16 // gdb-command:whatis generic_struct1
17 // gdb-check:type = type_names::GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
18
19 // gdb-command:whatis generic_struct2
20 // gdb-check:type = type_names::GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
21
22 // gdb-command:whatis mod_struct
23 // gdb-check:type = type_names::mod1::Struct2
24
25 // ENUMS
26 // gdb-command:whatis simple_enum_1
27 // gdb-check:type = type_names::Enum1
28
29 // gdb-command:whatis simple_enum_2
30 // gdb-check:type = type_names::Enum1
31
32 // gdb-command:whatis simple_enum_3
33 // gdb-check:type = type_names::mod1::Enum2
34
35 // gdb-command:whatis generic_enum_1
36 // gdb-check:type = type_names::mod1::mod2::Enum3
37
38 // gdb-command:whatis generic_enum_2
39 // gdb-check:type = type_names::mod1::mod2::Enum3
40
41 // TUPLES
42 // gdb-command:whatis tuple1
43 // gdb-check:type = (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
44
45 // gdb-command:whatis tuple2
46 // gdb-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
47
48 // BOX
49 // gdb-command:whatis box1
50 // gdb-check:type = (alloc::boxed::Box<f32, alloc::alloc::Global>, i32)
51
52 // gdb-command:whatis box2
53 // gdb-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>, alloc::alloc::Global>, i32)
54
55 // REFERENCES
56 // gdb-command:whatis ref1
57 // gdb-check:type = (&type_names::Struct1, i32)
58
59 // gdb-command:whatis ref2
60 // gdb-check:type = (&type_names::GenericStruct<char, type_names::Struct1>, i32)
61
62 // gdb-command:whatis mut_ref1
63 // gdb-check:type = (&mut type_names::Struct1, i32)
64
65 // gdb-command:whatis mut_ref2
66 // gdb-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
67
68 // RAW POINTERS
69 // gdb-command:whatis mut_ptr1
70 // gdb-check:type = (*mut type_names::Struct1, isize)
71
72 // gdb-command:whatis mut_ptr2
73 // gdb-check:type = (*mut isize, isize)
74
75 // gdb-command:whatis mut_ptr3
76 // gdb-check:type = (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
77
78 // gdb-command:whatis const_ptr1
79 // gdb-check:type = (*const type_names::Struct1, isize)
80
81 // gdb-command:whatis const_ptr2
82 // gdb-check:type = (*const isize, isize)
83
84 // gdb-command:whatis const_ptr3
85 // gdb-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
86
87 // VECTORS
88 // gdb-command:whatis fixed_size_vec1
89 // gdb-check:type = ([type_names::Struct1; 3], i16)
90
91 // gdb-command:whatis fixed_size_vec2
92 // gdb-check:type = ([usize; 3], i16)
93
94 // gdb-command:whatis slice1
95 // gdb-check:type = &[usize]
96
97 // gdb-command:whatis slice2
98 // gdb-check:type = &[type_names::mod1::Enum2]
99
100 // TRAITS
101 // gdb-command:whatis box_trait
102 // gdb-check:type = alloc::boxed::Box<dyn type_names::Trait1, alloc::alloc::Global>
103
104 // gdb-command:whatis ref_trait
105 // gdb-check:type = &dyn type_names::Trait1
106
107 // gdb-command:whatis mut_ref_trait
108 // gdb-check:type = &mut dyn type_names::Trait1
109
110 // gdb-command:whatis generic_box_trait
111 // gdb-check:type = alloc::boxed::Box<dyn type_names::Trait2<i32, type_names::mod1::Struct2>, alloc::alloc::Global>
112
113 // gdb-command:whatis generic_ref_trait
114 // gdb-check:type = &dyn type_names::Trait2<type_names::Struct1, type_names::Struct1>
115
116 // gdb-command:whatis generic_mut_ref_trait
117 // gdb-check:type = &mut dyn type_names::Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
118
119 // gdb-command:whatis no_principal_trait
120 // gdb-check:type = alloc::boxed::Box<(dyn core::marker::Send + core::marker::Sync), alloc::alloc::Global>
121
122 // gdb-command:whatis has_associated_type_trait
123 // gdb-check:type = &(dyn type_names::Trait3<u32, AssocType=isize> + core::marker::Send)
124
125
126 // BARE FUNCTIONS
127 // gdb-command:whatis rust_fn
128 // gdb-check:type = (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
129
130 // gdb-command:whatis extern_c_fn
131 // gdb-check:type = (extern "C" fn(isize), usize)
132
133 // gdb-command:whatis unsafe_fn
134 // gdb-check:type = (unsafe fn(core::result::Result<char, f64>), usize)
135
136 // gdb-command:whatis rust_fn_with_return_value
137 // gdb-check:type = (fn(f64) -> usize, usize)
138
139 // gdb-command:whatis extern_c_fn_with_return_value
140 // gdb-check:type = (extern "C" fn() -> type_names::Struct1, usize)
141
142 // gdb-command:whatis unsafe_fn_with_return_value
143 // gdb-check:type = (unsafe fn(type_names::GenericStruct<u16, u8>) -> type_names::mod1::Struct2, usize)
144
145 // gdb-command:whatis generic_function_int
146 // gdb-check:type = (fn(isize) -> isize, usize)
147
148 // gdb-command:whatis generic_function_struct3
149 // gdb-check:type = (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
150
151 // gdb-command:whatis variadic_function
152 // gdb-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
153
154 // CLOSURES
155 // gdb-command:whatis closure1
156 // gdb-check:type = (type_names::main::{closure#0}, usize)
157
158 // gdb-command:whatis closure2
159 // gdb-check:type = (type_names::main::{closure#1}, usize)
160
161 // FOREIGN TYPES
162 // gdb-command:whatis foreign1
163 // gdb-check:type = *mut ForeignType1
164
165 // gdb-command:whatis foreign2
166 // gdb-check:type = *mut ForeignType2
167
168 // === CDB TESTS ==================================================================================
169
170 // cdb-command: g
171
172 // STRUCTS
173 // 0-sized structs appear to be optimized away in some cases, so only check the structs that do
174 // actually appear.
175 // cdb-command:dv /t *_struct
176 // cdb-check:struct type_names::GenericStruct<enum$<type_names::mod1::Enum2>,f64> mut_generic_struct = [...]
177
178 // ENUMS
179 // cdb-command:dv /t *_enum_*
180 // cdb-check:union enum$<type_names::Enum1> simple_enum_1 = [...]
181 // cdb-check:union enum$<type_names::Enum1> simple_enum_2 = [...]
182 // cdb-check:type_names::mod1::Enum2 simple_enum_3 = [...]
183 // cdb-check:type_names::mod1::mod2::Enum3 generic_enum_1 = [...]
184 // cdb-check:type_names::mod1::mod2::Enum3 generic_enum_2 = [...]
185
186 // TUPLES
187 // cdb-command:dv /t tuple*
188 // cdb-check:struct tuple$<u32,type_names::Struct1,enum$<type_names::mod1::mod2::Enum3<type_names::mod1::Struct2> > > tuple1 = [...]
189 // cdb-check:struct tuple$<tuple$<type_names::Struct1,type_names::mod1::mod2::Struct3>,enum$<type_names::mod1::Enum2>,char> tuple2 = [...]
190
191 // BOX
192 // cdb-command:dv /t box*
193 // cdb-check:struct tuple$<alloc::boxed::Box<f32,alloc::alloc::Global>,i32> box1 = [...]
194 // cdb-check:struct tuple$<alloc::boxed::Box<enum$<type_names::mod1::mod2::Enum3<f32> >,alloc::alloc::Global>,i32> box2 = [...]
195
196 // REFERENCES
197 // cdb-command:dv /t *ref*
198 // cdb-check:struct tuple$<ref$<type_names::Struct1>,i32> ref1 = [...]
199 // cdb-check:struct tuple$<ref$<type_names::GenericStruct<char,type_names::Struct1> >,i32> ref2 = [...]
200 // cdb-check:struct tuple$<ref_mut$<type_names::Struct1>,i32> mut_ref1 = [...]
201 // cdb-check:struct tuple$<ref_mut$<type_names::GenericStruct<enum$<type_names::mod1::Enum2>,f64> >,i32> mut_ref2 = [...]
202
203 // RAW POINTERS
204 // cdb-command:dv /t *_ptr*
205 // cdb-check:struct tuple$<ptr_mut$<type_names::Struct1>,isize> mut_ptr1 = [...]
206 // cdb-check:struct tuple$<ptr_mut$<isize>,isize> mut_ptr2 = [...]
207 // cdb-check:struct tuple$<ptr_mut$<enum$<type_names::mod1::mod2::Enum3<type_names::Struct1> > >,isize> mut_ptr3 = [...]
208 // cdb-check:struct tuple$<ptr_const$<type_names::Struct1>,isize> const_ptr1 = [...]
209 // cdb-check:struct tuple$<ptr_const$<isize>,isize> const_ptr2 = [...]
210 // cdb-check:struct tuple$<ptr_const$<enum$<type_names::mod1::mod2::Enum3<type_names::Struct1> > >,isize> const_ptr3 = [...]
211
212 // VECTORS
213 // cdb-command:dv /t *vec*
214 // cdb-check:struct tuple$<array$<type_names::Struct1,3>,i16> fixed_size_vec1 = [...]
215 // cdb-check:struct tuple$<array$<usize,3>,i16> fixed_size_vec2 = [...]
216 // cdb-check:struct alloc::vec::Vec<usize,alloc::alloc::Global> vec1 = [...]
217 // cdb-check:struct alloc::vec::Vec<enum$<type_names::mod1::Enum2>,alloc::alloc::Global> vec2 = [...]
218 // cdb-command:dv /t slice*
219 // cdb-check:struct slice$<usize> slice1 = [...]
220 // cdb-check:struct slice$<enum$<type_names::mod1::Enum2> > slice2 = [...]
221
222 // TRAITS
223 // cdb-command:dv /t *_trait
224 // cdb-check:struct ref_mut$<dyn$<type_names::Trait2<type_names::mod1::mod2::Struct3,type_names::GenericStruct<usize,isize> > > > generic_mut_ref_trait = [...]
225 // cdb-check:struct ref$<dyn$<type_names::Trait2<type_names::Struct1,type_names::Struct1> > > generic_ref_trait = [...]
226 // cdb-check:struct alloc::boxed::Box<dyn$<type_names::Trait2<i32,type_names::mod1::Struct2> >,alloc::alloc::Global> generic_box_trait = [...]
227 // cdb-check:struct alloc::boxed::Box<dyn$<type_names::Trait1>,alloc::alloc::Global> box_trait = [...]
228 // cdb-check:struct ref$<dyn$<type_names::Trait1> > ref_trait = [...]
229 // cdb-check:struct ref_mut$<dyn$<type_names::Trait1> > mut_ref_trait = [...]
230 // cdb-check:struct alloc::boxed::Box<dyn$<core::marker::Send,core::marker::Sync>,alloc::alloc::Global> no_principal_trait = [...]
231 // cdb-check:struct ref$<dyn$<type_names::Trait3<u32,assoc$<AssocType,isize> >,core::marker::Send> > has_associated_type_trait = struct ref$<dyn$<type_names::Trait3<u32,assoc$<AssocType,isize> >,core::marker::Send> >
232
233 // BARE FUNCTIONS
234 // cdb-command:dv /t *_fn*
235 // cdb-check:struct tuple$<type_names::mod1::Struct2 (*)(type_names::GenericStruct<u16,u8>),usize> unsafe_fn_with_return_value = [...]
236 // cdb-check:struct tuple$<type_names::Struct1 (*)(),usize> extern_c_fn_with_return_value = [...]
237 // cdb-check:struct tuple$<usize (*)(f64),usize> rust_fn_with_return_value = [...]
238 // cdb-check:struct tuple$<void (*)(enum$<core::result::Result<char,f64> >),usize> unsafe_fn = [...]
239 // cdb-check:struct tuple$<void (*)(isize),usize> extern_c_fn = [...]
240 // cdb-check:struct tuple$<void (*)(enum$<core::option::Option<isize> >,enum$<core::option::Option<ref$<type_names::mod1::Struct2> >, 1, [...], Some>),usize> rust_fn = [...]
241 // cdb-command:dv /t *_function*
242 // cdb-check:struct tuple$<isize (*)(ptr_const$<u8>, ...),usize> variadic_function = [...]
243 // cdb-check:struct tuple$<type_names::mod1::mod2::Struct3 (*)(type_names::mod1::mod2::Struct3),usize> generic_function_struct3 = [...]
244 // cdb-check:struct tuple$<isize (*)(isize),usize> generic_function_int = [...]
245 // cdb-command:dx Debugger.State.Scripts.@"type-names.cdb".Contents.getFunctionDetails("rust_fn")
246 // cdb-check:Return Type: void
247 // cdb-check:Parameter Types: enum$<core::option::Option<isize> >,enum$<core::option::Option<ref$<type_names::mod1::Struct2> >, 1, [...], Some>
248 // cdb-command:dx Debugger.State.Scripts.@"type-names.cdb".Contents.getFunctionDetails("rust_fn_with_return_value")
249 // cdb-check:Return Type: usize
250 // cdb-check:Parameter Types: f64
251 // cdb-command:dx Debugger.State.Scripts.@"type-names.cdb".Contents.getFunctionDetails("extern_c_fn_with_return_value")
252 // cdb-check:Return Type: type_names::Struct1
253 // cdb-check:Parameter Types:
254
255 // CLOSURES
256 // cdb-command:dv /t closure*
257 // cdb-check:struct tuple$<type_names::main::closure$1,usize> closure2 = [...]
258 // cdb-check:struct tuple$<type_names::main::closure$0,usize> closure1 = [...]
259
260 // FOREIGN TYPES
261 // cdb-command:dv /t foreign*
262 // cdb-check:struct ForeignType2 * foreign2 = [...]
263 // cdb-check:struct ForeignType1 * foreign1 = [...]
264
265 #![allow(unused_variables)]
266 #![feature(omit_gdb_pretty_printer_section)]
267 #![omit_gdb_pretty_printer_section]
268 #![feature(extern_types)]
269
270 use self::Enum1::{Variant1, Variant2};
271 use std::marker::PhantomData;
272 use std::ptr;
273
274 pub struct Struct1;
275 struct GenericStruct<T1, T2>(PhantomData<(T1, T2)>);
276
277 enum Enum1 {
278 Variant1,
279 Variant2(isize),
280 }
281
282 extern { type ForeignType1; }
283
284 mod mod1 {
285 pub use self::Enum2::{Variant1, Variant2};
286 pub struct Struct2;
287
288 pub enum Enum2 {
289 Variant1,
290 Variant2(super::Struct1),
291 }
292
293 pub mod mod2 {
294 pub use self::Enum3::{Variant1, Variant2};
295 pub struct Struct3;
296
297 pub enum Enum3<T> {
298 Variant1,
299 Variant2(T),
300 }
301 }
302
303 extern { pub type ForeignType2; }
304 }
305
306 trait Trait1 {
307 fn dummy(&self) {}
308 }
309 trait Trait2<T1, T2> {
310 fn dummy(&self, _: T1, _: T2) {}
311 }
312 trait Trait3<T> {
313 type AssocType;
314 fn dummy(&self) -> T { panic!() }
315 }
316
317 impl Trait1 for isize {}
318 impl<T1, T2> Trait2<T1, T2> for isize {}
319 impl<T> Trait3<T> for isize {
320 type AssocType = isize;
321 }
322
323 fn rust_fn(_: Option<isize>, _: Option<&mod1::Struct2>) {}
324 extern "C" fn extern_c_fn(_: isize) {}
325 unsafe fn unsafe_fn(_: Result<char, f64>) {}
326
327 fn rust_fn_with_return_value(_: f64) -> usize {
328 4
329 }
330 extern "C" fn extern_c_fn_with_return_value() -> Struct1 {
331 Struct1
332 }
333 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 {
334 mod1::Struct2
335 }
336
337 fn generic_function<T>(x: T) -> T {
338 x
339 }
340
341 #[allow(improper_ctypes)]
342 extern "C" {
343 fn printf(_: *const u8, ...) -> isize;
344 }
345
346 // In many of the cases below, the type that is actually under test is wrapped
347 // in a tuple, e.g., Box<T>, references, raw pointers, fixed-size vectors, ...
348 // This is because GDB will not print the type name from DWARF debuginfo for
349 // some kinds of types (pointers, arrays, functions, ...)
350 // Since tuples are structs as far as GDB is concerned, their name will be
351 // printed correctly, so the tests below just construct a tuple type that will
352 // then *contain* the type name that we want to see.
353 fn main() {
354 // Structs
355 let simple_struct = Struct1;
356 let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
357 GenericStruct(PhantomData);
358 let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
359 GenericStruct(PhantomData);
360 let mod_struct = mod1::Struct2;
361
362 // Enums
363 let simple_enum_1 = Variant1;
364 let simple_enum_2 = Variant2(0);
365 let simple_enum_3 = mod1::Variant2(Struct1);
366
367 let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
368 let generic_enum_2 = mod1::mod2::Variant2(Struct1);
369
370 // Tuples
371 let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
372 let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
373
374 // Box
375 let box1 = (Box::new(1f32), 0i32);
376 let box2 = (Box::new(mod1::mod2::Variant2(1f32)), 0i32);
377
378 // References
379 let ref1 = (&Struct1, 0i32);
380 let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
381
382 let mut mut_struct1 = Struct1;
383 let mut mut_generic_struct = GenericStruct::<mod1::Enum2, f64>(PhantomData);
384 let mut_ref1 = (&mut mut_struct1, 0i32);
385 let mut_ref2 = (&mut mut_generic_struct, 0i32);
386
387 // Raw Pointers
388 let mut_ptr1: (*mut Struct1, isize) = (ptr::null_mut(), 0);
389 let mut_ptr2: (*mut isize, isize) = (ptr::null_mut(), 0);
390 let mut_ptr3: (*mut mod1::mod2::Enum3<Struct1>, isize) = (ptr::null_mut(), 0);
391
392 let const_ptr1: (*const Struct1, isize) = (ptr::null(), 0);
393 let const_ptr2: (*const isize, isize) = (ptr::null(), 0);
394 let const_ptr3: (*const mod1::mod2::Enum3<Struct1>, isize) = (ptr::null(), 0);
395
396 // Vectors
397 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
398 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
399
400 let vec1 = vec![0_usize, 2, 3];
401 let slice1 = &*vec1;
402 let vec2 = vec![mod1::Variant2(Struct1)];
403 let slice2 = &*vec2;
404
405 // Trait Objects
406 let box_trait = Box::new(0_isize) as Box<dyn Trait1>;
407 let ref_trait = &0_isize as &dyn Trait1;
408 let mut mut_int1 = 0_isize;
409 let mut_ref_trait = (&mut mut_int1) as &mut dyn Trait1;
410 let no_principal_trait = Box::new(0_isize) as Box<(dyn Send + Sync)>;
411 let has_associated_type_trait = &0_isize as &(dyn Trait3<u32, AssocType = isize> + Send);
412
413 let generic_box_trait = Box::new(0_isize) as Box<dyn Trait2<i32, mod1::Struct2>>;
414 let generic_ref_trait = (&0_isize) as &dyn Trait2<Struct1, Struct1>;
415
416 let mut generic_mut_ref_trait_impl = 0_isize;
417 let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl)
418 as &mut dyn Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
419
420 // Bare Functions
421 let rust_fn = (rust_fn, 0_usize);
422 let extern_c_fn = (extern_c_fn, 0_usize);
423 let unsafe_fn = (unsafe_fn, 0_usize);
424
425 let rust_fn_with_return_value = (rust_fn_with_return_value, 0_usize);
426 let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0_usize);
427 let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0_usize);
428
429 let generic_function_int = (generic_function::<isize>, 0_usize);
430 let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
431
432 let variadic_function = (printf, 0_usize);
433
434 // Closures
435 // I (mw) am a bit unclear about the current state of closures, their
436 // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
437 // how that maps to rustc's internal representation of these forms.
438 // Once closures have reached their 1.0 form, the tests below should
439 // probably be expanded.
440 let closure1 = (|x: isize| {}, 0_usize);
441 let closure2 = (|x: i8, y: f32| (x as f32) + y, 0_usize);
442
443 // Foreign Types
444 let foreign1 = unsafe{ 0 as *const ForeignType1 };
445 let foreign2 = unsafe{ 0 as *const mod1::ForeignType2 };
446
447 zzz(); // #break
448 }
449
450 #[inline(never)]
451 fn zzz() {
452 ()
453 }