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