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