]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/type-names.rs
Rollup merge of #47081 - pietroalbini:fix-nested-tree-dump, r=nrc
[rust.git] / src / test / debuginfo / type-names.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12 // ignore-lldb
13 // ignore-gdb // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
14 // ignore-android: FIXME(#24958)
15 // ignore-arm: FIXME(#24958)
16 // ignore-aarch64: FIXME(#24958)
17
18 // compile-flags:-g
19
20 // gdb-command:run
21
22 // STRUCTS
23 // gdb-command:whatis simple_struct
24 // gdbg-check:type = struct Struct1
25 // gdbr-check:type = type_names::Struct1
26
27 // gdb-command:whatis generic_struct1
28 // gdbg-check:type = struct GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
29 // gdbr-check:type = type_names::GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
30
31 // gdb-command:whatis generic_struct2
32 // gdbg-check:type = struct GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
33 // gdbr-check:type = type_names::GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
34
35 // gdb-command:whatis mod_struct
36 // gdbg-check:type = struct Struct2
37 // gdbr-check:type = type_names::mod1::Struct2
38
39
40 // ENUMS
41 // gdb-command:whatis simple_enum_1
42 // gdbg-check:type = union Enum1
43 // gdbr-check:type = type_names::Enum1
44
45 // gdb-command:whatis simple_enum_2
46 // gdbg-check:type = union Enum1
47 // gdbr-check:type = type_names::Enum1
48
49 // gdb-command:whatis simple_enum_3
50 // gdbg-check:type = union Enum2
51 // gdbr-check:type = type_names::mod1::Enum2
52
53 // gdb-command:whatis generic_enum_1
54 // gdbg-check:type = union Enum3<type_names::mod1::Struct2>
55 // gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>
56
57 // gdb-command:whatis generic_enum_2
58 // gdbg-check:type = union Enum3<type_names::Struct1>
59 // gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::Struct1>
60
61
62 // TUPLES
63 // gdb-command:whatis tuple1
64 // gdbg-check:type = struct (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
65 // gdbr-check:type = (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
66
67 // gdb-command:whatis tuple2
68 // gdbg-check:type = struct ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
69 // gdbr-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
70
71
72 // BOX
73 // gdb-command:whatis box1
74 // gdbg-check:type = struct (alloc::boxed::Box<f32>, i32)
75 // gdbr-check:type = (alloc::boxed::Box<f32>, i32)
76
77 // gdb-command:whatis box2
78 // gdbg-check:type = struct (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
79 // gdbr-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
80
81
82 // REFERENCES
83 // gdb-command:whatis ref1
84 // gdbg-check:type = struct (&type_names::Struct1, i32)
85 // gdbr-check:type = (&type_names::Struct1, i32)
86
87 // gdb-command:whatis ref2
88 // gdbg-check:type = struct (&type_names::GenericStruct<char, type_names::Struct1>, i32)
89 // gdbr-check:type = (&type_names::GenericStruct<char, type_names::Struct1>, i32)
90
91 // gdb-command:whatis mut_ref1
92 // gdbg-check:type = struct (&mut type_names::Struct1, i32)
93 // gdbr-check:type = (&mut type_names::Struct1, i32)
94
95 // gdb-command:whatis mut_ref2
96 // gdbg-check:type = struct (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
97 // gdbr-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
98
99
100 // RAW POINTERS
101 // gdb-command:whatis mut_ptr1
102 // gdbg-check:type = struct (*mut type_names::Struct1, isize)
103 // gdbr-check:type = (*mut type_names::Struct1, isize)
104
105 // gdb-command:whatis mut_ptr2
106 // gdbg-check:type = struct (*mut isize, isize)
107 // gdbr-check:type = (*mut isize, isize)
108
109 // gdb-command:whatis mut_ptr3
110 // gdbg-check:type = struct (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
111 // gdbr-check:type = (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
112
113 // gdb-command:whatis const_ptr1
114 // gdbg-check:type = struct (*const type_names::Struct1, isize)
115 // gdbr-check:type = (*const type_names::Struct1, isize)
116
117 // gdb-command:whatis const_ptr2
118 // gdbg-check:type = struct (*const isize, isize)
119 // gdbr-check:type = (*const isize, isize)
120
121 // gdb-command:whatis const_ptr3
122 // gdbg-check:type = struct (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
123 // gdbr-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
124
125
126 // VECTORS
127 // gdb-command:whatis fixed_size_vec1
128 // gdbg-check:type = struct ([type_names::Struct1; 3], i16)
129 // gdbr-check:type = ([type_names::Struct1; 3], i16)
130
131 // gdb-command:whatis fixed_size_vec2
132 // gdbg-check:type = struct ([usize; 3], i16)
133 // gdbr-check:type = ([usize; 3], i16)
134
135 // gdb-command:whatis slice1
136 // gdbg-check:type = struct &[usize]
137 // gdbr-check:type = &[usize]
138
139 // gdb-command:whatis slice2
140 // gdbg-check:type = struct &[type_names::mod1::Enum2]
141 // gdbr-check:type = &[type_names::mod1::Enum2]
142
143
144 // TRAITS
145 // gdb-command:whatis box_trait
146 // gdbg-check:type = struct Box<Trait1>
147 // gdbr-check:type = type_names::Box<Trait1>
148
149 // gdb-command:whatis ref_trait
150 // gdbg-check:type = struct &Trait1
151 // gdbr-check:type = type_names::&Trait1
152
153 // gdb-command:whatis mut_ref_trait
154 // gdbg-check:type = struct &mut Trait1
155 // gdbr-check:type = type_names::&mut Trait1
156
157 // gdb-command:whatis generic_box_trait
158 // gdbg-check:type = struct Box<Trait2<i32, type_names::mod1::Struct2>>
159 // gdbr-check:type = type_names::Box<Trait2<i32, type_names::mod1::Struct2>>
160
161 // gdb-command:whatis generic_ref_trait
162 // gdbg-check:type = struct &Trait2<type_names::Struct1, type_names::Struct1>
163 // gdbr-check:type = type_names::&Trait2<type_names::Struct1, type_names::Struct1>
164
165 // gdb-command:whatis generic_mut_ref_trait
166 // gdbg-check:type = struct &mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
167 // gdbr-check:type = type_names::&mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
168
169
170 // BARE FUNCTIONS
171 // gdb-command:whatis rust_fn
172 // gdbg-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
173 // gdbr-check:type = (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
174
175 // gdb-command:whatis extern_c_fn
176 // gdbg-check:type = struct (extern "C" fn(isize), usize)
177 // gdbr-check:type = (extern "C" fn(isize), usize)
178
179 // gdb-command:whatis unsafe_fn
180 // gdbg-check:type = struct (unsafe fn(core::result::Result<char, f64>), usize)
181 // gdbr-check:type = (unsafe fn(core::result::Result<char, f64>), usize)
182
183 // gdb-command:whatis extern_stdcall_fn
184 // gdbg-check:type = struct (extern "stdcall" fn(), usize)
185 // gdbr-check:type = (extern "stdcall" fn(), usize)
186
187 // gdb-command:whatis rust_fn_with_return_value
188 // gdbg-check:type = struct (fn(f64) -> usize, usize)
189 // gdbr-check:type = (fn(f64) -> usize, usize)
190
191 // gdb-command:whatis extern_c_fn_with_return_value
192 // gdbg-check:type = struct (extern "C" fn() -> type_names::Struct1, usize)
193 // gdbr-check:type = (extern "C" fn() -> type_names::Struct1, usize)
194
195 // gdb-command:whatis unsafe_fn_with_return_value
196 // gdbg-check:type = struct (unsafe fn(type_names::GenericStruct<u16, u8>) -> type_names::mod1::Struct2, usize)
197 // gdbr-check:type = (unsafe fn(type_names::GenericStruct<u16, u8>) -> type_names::mod1::Struct2, usize)
198
199 // gdb-command:whatis extern_stdcall_fn_with_return_value
200 // gdbg-check:type = struct (extern "stdcall" fn(alloc::boxed::Box<isize>) -> usize, usize)
201 // gdbr-check:type = (extern "stdcall" fn(alloc::boxed::Box<isize>) -> usize, usize)
202
203 // gdb-command:whatis generic_function_int
204 // gdbg-check:type = struct (fn(isize) -> isize, usize)
205 // gdbr-check:type = (fn(isize) -> isize, usize)
206
207 // gdb-command:whatis generic_function_struct3
208 // gdbg-check:type = struct (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
209 // gdbr-check:type = (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
210
211 // gdb-command:whatis variadic_function
212 // gdbg-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
213 // gdbr-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
214
215
216 // CLOSURES
217 // gdb-command:whatis closure1
218 // gdbg-check:type = struct (closure, usize)
219 // gdbr-check:type = (closure, usize)
220
221 // gdb-command:whatis closure2
222 // gdbg-check:type = struct (closure, usize)
223 // gdbr-check:type = (closure, usize)
224
225 #![feature(box_syntax)]
226 #![allow(unused_variables)]
227 #![feature(omit_gdb_pretty_printer_section)]
228 #![omit_gdb_pretty_printer_section]
229
230 use self::Enum1::{Variant1, Variant2};
231 use std::marker::PhantomData;
232 use std::ptr;
233
234 pub struct Struct1;
235 struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
236
237 enum Enum1 {
238     Variant1,
239     Variant2(isize),
240 }
241
242 mod mod1 {
243     pub use self::Enum2::{Variant1, Variant2};
244     pub struct Struct2;
245
246     pub enum Enum2 {
247         Variant1,
248         Variant2(super::Struct1),
249     }
250
251     pub mod mod2 {
252         pub use self::Enum3::{Variant1, Variant2};
253         pub struct Struct3;
254
255         pub enum Enum3<T> {
256             Variant1,
257             Variant2(T),
258         }
259     }
260 }
261
262 trait Trait1 { fn dummy(&self) { } }
263 trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
264
265 impl Trait1 for isize {}
266 impl<T1, T2> Trait2<T1, T2> for isize {}
267
268 fn rust_fn(_: Option<isize>, _: Option<&mod1::Struct2>) {}
269 extern "C" fn extern_c_fn(_: isize) {}
270 unsafe fn unsafe_fn(_: Result<char, f64>) {}
271 extern "stdcall" fn extern_stdcall_fn() {}
272
273 fn rust_fn_with_return_value(_: f64) -> usize { 4 }
274 extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 }
275 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 { mod1::Struct2 }
276 extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize { 0 }
277
278 fn generic_function<T>(x: T) -> T { x }
279
280 #[allow(improper_ctypes)]
281 extern {
282     fn printf(_:*const u8, ...) -> isize;
283 }
284
285 // In many of the cases below, the type that is actually under test is wrapped
286 // in a tuple, e.g. Box<T>, references, raw pointers, fixed-size vectors, ...
287 // This is because GDB will not print the type name from DWARF debuginfo for
288 // some kinds of types (pointers, arrays, functions, ...)
289 // Since tuples are structs as far as GDB is concerned, their name will be
290 // printed correctly, so the tests below just construct a tuple type that will
291 // then *contain* the type name that we want to see.
292 fn main() {
293
294     // Structs
295     let simple_struct = Struct1;
296     let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
297         GenericStruct(PhantomData);
298     let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
299         GenericStruct(PhantomData);
300     let mod_struct = mod1::Struct2;
301
302     // Enums
303     let simple_enum_1 = Variant1;
304     let simple_enum_2 = Variant2(0);
305     let simple_enum_3 = mod1::Variant2(Struct1);
306
307     let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
308     let generic_enum_2 = mod1::mod2::Variant2(Struct1);
309
310     // Tuples
311     let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
312     let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
313
314     // Box
315     let box1 = (box 1f32, 0i32);
316     let box2 = (box mod1::mod2::Variant2(1f32), 0i32);
317
318     // References
319     let ref1 = (&Struct1, 0i32);
320     let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
321
322     let mut mut_struct1 = Struct1;
323     let mut mut_generic_struct = GenericStruct::<mod1::Enum2, f64>(PhantomData);
324     let mut_ref1 = (&mut mut_struct1, 0i32);
325     let mut_ref2 = (&mut mut_generic_struct, 0i32);
326
327     // Raw Pointers
328     let mut_ptr1: (*mut Struct1, isize) = (ptr::null_mut(), 0);
329     let mut_ptr2: (*mut isize, isize) = (ptr::null_mut(), 0);
330     let mut_ptr3: (*mut mod1::mod2::Enum3<Struct1>, isize) = (ptr::null_mut(), 0);
331
332     let const_ptr1: (*const Struct1, isize) = (ptr::null(), 0);
333     let const_ptr2: (*const isize, isize) = (ptr::null(), 0);
334     let const_ptr3: (*const mod1::mod2::Enum3<Struct1>, isize) = (ptr::null(), 0);
335
336     // Vectors
337     let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
338     let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
339
340     let vec1 = vec![0_usize, 2, 3];
341     let slice1 = &*vec1;
342     let vec2 = vec![mod1::Variant2(Struct1)];
343     let slice2 = &*vec2;
344
345     // Trait Objects
346     let box_trait = (box 0_isize) as Box<Trait1>;
347     let ref_trait = &0_isize as &Trait1;
348     let mut mut_int1 = 0_isize;
349     let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
350
351     let generic_box_trait = (box 0_isize) as Box<Trait2<i32, mod1::Struct2>>;
352     let generic_ref_trait  = (&0_isize) as &Trait2<Struct1, Struct1>;
353
354     let mut generic_mut_ref_trait_impl = 0_isize;
355     let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
356         &mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
357
358     // Bare Functions
359     let rust_fn = (rust_fn, 0_usize);
360     let extern_c_fn = (extern_c_fn, 0_usize);
361     let unsafe_fn = (unsafe_fn, 0_usize);
362     let extern_stdcall_fn = (extern_stdcall_fn, 0_usize);
363
364     let rust_fn_with_return_value = (rust_fn_with_return_value, 0_usize);
365     let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0_usize);
366     let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0_usize);
367     let extern_stdcall_fn_with_return_value = (extern_stdcall_fn_with_return_value, 0_usize);
368
369     let generic_function_int = (generic_function::<isize>, 0_usize);
370     let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
371
372     let variadic_function = (printf, 0_usize);
373
374     // Closures
375     // I (mw) am a bit unclear about the current state of closures, their
376     // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
377     // how that maps to rustc's internal representation of these forms.
378     // Once closures have reached their 1.0 form, the tests below should
379     // probably be expanded.
380     let closure1 = (|x:isize| {}, 0_usize);
381     let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize);
382
383     zzz(); // #break
384 }
385
386 #[inline(never)]
387 fn zzz() { () }