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.
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.
11 // ignore-tidy-linelength
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)
23 // gdb-command:whatis simple_struct
24 // gdbg-check:type = struct Struct1
25 // gdbr-check:type = type_names::Struct1
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>
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>
35 // gdb-command:whatis mod_struct
36 // gdbg-check:type = struct Struct2
37 // gdbr-check:type = type_names::mod1::Struct2
41 // gdb-command:whatis simple_enum_1
42 // gdbg-check:type = union Enum1
43 // gdbr-check:type = type_names::Enum1
45 // gdb-command:whatis simple_enum_2
46 // gdbg-check:type = union Enum1
47 // gdbr-check:type = type_names::Enum1
49 // gdb-command:whatis simple_enum_3
50 // gdbg-check:type = union Enum2
51 // gdbr-check:type = type_names::mod1::Enum2
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>
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>
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>)
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)
73 // gdb-command:whatis box1
74 // gdbg-check:type = struct (alloc::boxed::Box<f32>, i32)
75 // gdbr-check:type = (alloc::boxed::Box<f32>, i32)
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)
83 // gdb-command:whatis ref1
84 // gdbg-check:type = struct (&type_names::Struct1, i32)
85 // gdbr-check:type = (&type_names::Struct1, i32)
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)
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)
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)
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)
105 // gdb-command:whatis mut_ptr2
106 // gdbg-check:type = struct (*mut isize, isize)
107 // gdbr-check:type = (*mut isize, isize)
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)
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)
117 // gdb-command:whatis const_ptr2
118 // gdbg-check:type = struct (*const isize, isize)
119 // gdbr-check:type = (*const isize, isize)
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)
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)
131 // gdb-command:whatis fixed_size_vec2
132 // gdbg-check:type = struct ([usize; 3], i16)
133 // gdbr-check:type = ([usize; 3], i16)
135 // gdb-command:whatis slice1
136 // gdbg-check:type = struct &[usize]
137 // gdbr-check:type = &[usize]
139 // gdb-command:whatis slice2
140 // gdbg-check:type = struct &[type_names::mod1::Enum2]
141 // gdbr-check:type = &[type_names::mod1::Enum2]
145 // gdb-command:whatis box_trait
146 // gdbg-check:type = struct Box<Trait1>
147 // gdbr-check:type = type_names::Box<Trait1>
149 // gdb-command:whatis ref_trait
150 // gdbg-check:type = struct &Trait1
151 // gdbr-check:type = type_names::&Trait1
153 // gdb-command:whatis mut_ref_trait
154 // gdbg-check:type = struct &mut Trait1
155 // gdbr-check:type = type_names::&mut Trait1
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>>
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>
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>>
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)
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)
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)
183 // gdb-command:whatis extern_stdcall_fn
184 // gdbg-check:type = struct (extern "stdcall" fn(), usize)
185 // gdbr-check:type = (extern "stdcall" fn(), usize)
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)
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)
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)
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)
203 // gdb-command:whatis generic_function_int
204 // gdbg-check:type = struct (fn(isize) -> isize, usize)
205 // gdbr-check:type = (fn(isize) -> isize, usize)
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)
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)
217 // gdb-command:whatis closure1
218 // gdbg-check:type = struct (closure, usize)
219 // gdbr-check:type = (closure, usize)
221 // gdb-command:whatis closure2
222 // gdbg-check:type = struct (closure, usize)
223 // gdbr-check:type = (closure, usize)
225 #![feature(box_syntax)]
226 #![allow(unused_variables)]
227 #![feature(omit_gdb_pretty_printer_section)]
228 #![omit_gdb_pretty_printer_section]
230 use self::Enum1::{Variant1, Variant2};
231 use std::marker::PhantomData;
235 struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
243 pub use self::Enum2::{Variant1, Variant2};
248 Variant2(super::Struct1),
252 pub use self::Enum3::{Variant1, Variant2};
262 trait Trait1 { fn dummy(&self) { } }
263 trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
265 impl Trait1 for isize {}
266 impl<T1, T2> Trait2<T1, T2> for isize {}
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() {}
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 }
278 fn generic_function<T>(x: T) -> T { x }
280 #[allow(improper_ctypes)]
282 fn printf(_:*const u8, ...) -> isize;
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.
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;
303 let simple_enum_1 = Variant1;
304 let simple_enum_2 = Variant2(0);
305 let simple_enum_3 = mod1::Variant2(Struct1);
307 let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
308 let generic_enum_2 = mod1::mod2::Variant2(Struct1);
311 let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
312 let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
315 let box1 = (box 1f32, 0i32);
316 let box2 = (box mod1::mod2::Variant2(1f32), 0i32);
319 let ref1 = (&Struct1, 0i32);
320 let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
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);
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);
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);
337 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
338 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
340 let vec1 = vec![0_usize, 2, 3];
342 let vec2 = vec![mod1::Variant2(Struct1)];
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;
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>;
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>>;
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);
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);
369 let generic_function_int = (generic_function::<isize>, 0_usize);
370 let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
372 let variadic_function = (printf, 0_usize);
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);