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
20 // gdb-command:whatis simple_struct
21 // gdbg-check:type = struct Struct1
22 // gdbr-check:type = type_names::Struct1
24 // gdb-command:whatis generic_struct1
25 // gdbg-check:type = struct GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
26 // gdbr-check:type = type_names::GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
28 // gdb-command:whatis generic_struct2
29 // gdbg-check:type = struct GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
30 // gdbr-check:type = type_names::GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
32 // gdb-command:whatis mod_struct
33 // gdbg-check:type = struct Struct2
34 // gdbr-check:type = type_names::mod1::Struct2
38 // gdb-command:whatis simple_enum_1
39 // gdbg-check:type = union Enum1
40 // gdbr-check:type = type_names::Enum1
42 // gdb-command:whatis simple_enum_2
43 // gdbg-check:type = union Enum1
44 // gdbr-check:type = type_names::Enum1
46 // gdb-command:whatis simple_enum_3
47 // gdbg-check:type = union Enum2
48 // gdbr-check:type = type_names::mod1::Enum2
50 // gdb-command:whatis generic_enum_1
51 // gdbg-check:type = union Enum3<type_names::mod1::Struct2>
52 // gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>
54 // gdb-command:whatis generic_enum_2
55 // gdbg-check:type = union Enum3<type_names::Struct1>
56 // gdbr-check:type = type_names::mod1::mod2::Enum3<type_names::Struct1>
60 // gdb-command:whatis tuple1
61 // gdbg-check:type = struct (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
62 // gdbr-check:type = (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
64 // gdb-command:whatis tuple2
65 // gdbg-check:type = struct ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
66 // gdbr-check:type = ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
70 // gdb-command:whatis box1
71 // gdbg-check:type = struct (alloc::boxed::Box<f32>, i32)
72 // gdbr-check:type = (alloc::boxed::Box<f32>, i32)
74 // gdb-command:whatis box2
75 // gdbg-check:type = struct (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
76 // gdbr-check:type = (alloc::boxed::Box<type_names::mod1::mod2::Enum3<f32>>, i32)
80 // gdb-command:whatis ref1
81 // gdbg-check:type = struct (&type_names::Struct1, i32)
82 // gdbr-check:type = (&type_names::Struct1, i32)
84 // gdb-command:whatis ref2
85 // gdbg-check:type = struct (&type_names::GenericStruct<char, type_names::Struct1>, i32)
86 // gdbr-check:type = (&type_names::GenericStruct<char, type_names::Struct1>, i32)
88 // gdb-command:whatis mut_ref1
89 // gdbg-check:type = struct (&mut type_names::Struct1, i32)
90 // gdbr-check:type = (&mut type_names::Struct1, i32)
92 // gdb-command:whatis mut_ref2
93 // gdbg-check:type = struct (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
94 // gdbr-check:type = (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
98 // gdb-command:whatis mut_ptr1
99 // gdbg-check:type = struct (*mut type_names::Struct1, isize)
100 // gdbr-check:type = (*mut type_names::Struct1, isize)
102 // gdb-command:whatis mut_ptr2
103 // gdbg-check:type = struct (*mut isize, isize)
104 // gdbr-check:type = (*mut isize, isize)
106 // gdb-command:whatis mut_ptr3
107 // gdbg-check:type = struct (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
108 // gdbr-check:type = (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
110 // gdb-command:whatis const_ptr1
111 // gdbg-check:type = struct (*const type_names::Struct1, isize)
112 // gdbr-check:type = (*const type_names::Struct1, isize)
114 // gdb-command:whatis const_ptr2
115 // gdbg-check:type = struct (*const isize, isize)
116 // gdbr-check:type = (*const isize, isize)
118 // gdb-command:whatis const_ptr3
119 // gdbg-check:type = struct (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
120 // gdbr-check:type = (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
124 // gdb-command:whatis fixed_size_vec1
125 // gdbg-check:type = struct ([type_names::Struct1; 3], i16)
126 // gdbr-check:type = ([type_names::Struct1; 3], i16)
128 // gdb-command:whatis fixed_size_vec2
129 // gdbg-check:type = struct ([usize; 3], i16)
130 // gdbr-check:type = ([usize; 3], i16)
132 // gdb-command:whatis slice1
133 // gdbg-check:type = struct &[usize]
134 // gdbr-check:type = &[usize]
136 // gdb-command:whatis slice2
137 // gdbg-check:type = struct &[type_names::mod1::Enum2]
138 // gdbr-check:type = &[type_names::mod1::Enum2]
142 // gdb-command:whatis box_trait
143 // gdbg-check:type = struct Box<Trait1>
144 // gdbr-check:type = type_names::Box<Trait1>
146 // gdb-command:whatis ref_trait
147 // gdbg-check:type = struct &Trait1
148 // gdbr-check:type = type_names::&Trait1
150 // gdb-command:whatis mut_ref_trait
151 // gdbg-check:type = struct &mut Trait1
152 // gdbr-check:type = type_names::&mut Trait1
154 // gdb-command:whatis generic_box_trait
155 // gdbg-check:type = struct Box<Trait2<i32, type_names::mod1::Struct2>>
156 // gdbr-check:type = type_names::Box<Trait2<i32, type_names::mod1::Struct2>>
158 // gdb-command:whatis generic_ref_trait
159 // gdbg-check:type = struct &Trait2<type_names::Struct1, type_names::Struct1>
160 // gdbr-check:type = type_names::&Trait2<type_names::Struct1, type_names::Struct1>
162 // gdb-command:whatis generic_mut_ref_trait
163 // gdbg-check:type = struct &mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
164 // gdbr-check:type = type_names::&mut Trait2<type_names::mod1::mod2::Struct3, type_names::GenericStruct<usize, isize>>
168 // gdb-command:whatis rust_fn
169 // gdbg-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
170 // gdbr-check:type = (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
172 // gdb-command:whatis extern_c_fn
173 // gdbg-check:type = struct (extern "C" fn(isize), usize)
174 // gdbr-check:type = (extern "C" fn(isize), usize)
176 // gdb-command:whatis unsafe_fn
177 // gdbg-check:type = struct (unsafe fn(core::result::Result<char, f64>), usize)
178 // gdbr-check:type = (unsafe fn(core::result::Result<char, f64>), usize)
180 // gdb-command:whatis extern_stdcall_fn
181 // gdbg-check:type = struct (extern "stdcall" fn(), usize)
182 // gdbr-check:type = (extern "stdcall" fn(), usize)
184 // gdb-command:whatis rust_fn_with_return_value
185 // gdbg-check:type = struct (fn(f64) -> usize, usize)
186 // gdbr-check:type = (fn(f64) -> usize, usize)
188 // gdb-command:whatis extern_c_fn_with_return_value
189 // gdbg-check:type = struct (extern "C" fn() -> type_names::Struct1, usize)
190 // gdbr-check:type = (extern "C" fn() -> type_names::Struct1, usize)
192 // gdb-command:whatis unsafe_fn_with_return_value
193 // gdbg-check:type = struct (unsafe fn(type_names::GenericStruct<u16, u8>) -> type_names::mod1::Struct2, usize)
194 // gdbr-check:type = (unsafe fn(type_names::GenericStruct<u16, u8>) -> type_names::mod1::Struct2, usize)
196 // gdb-command:whatis extern_stdcall_fn_with_return_value
197 // gdbg-check:type = struct (extern "stdcall" fn(alloc::boxed::Box<isize>) -> usize, usize)
198 // gdbr-check:type = (extern "stdcall" fn(alloc::boxed::Box<isize>) -> usize, usize)
200 // gdb-command:whatis generic_function_int
201 // gdbg-check:type = struct (fn(isize) -> isize, usize)
202 // gdbr-check:type = (fn(isize) -> isize, usize)
204 // gdb-command:whatis generic_function_struct3
205 // gdbg-check:type = struct (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
206 // gdbr-check:type = (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
208 // gdb-command:whatis variadic_function
209 // gdbg-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
210 // gdbr-check:type = (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
214 // gdb-command:whatis closure1
215 // gdbg-check:type = struct (closure, usize)
216 // gdbr-check:type = (closure, usize)
218 // gdb-command:whatis closure2
219 // gdbg-check:type = struct (closure, usize)
220 // gdbr-check:type = (closure, usize)
222 #![feature(box_syntax)]
223 #![allow(unused_variables)]
224 #![feature(omit_gdb_pretty_printer_section)]
225 #![omit_gdb_pretty_printer_section]
227 use self::Enum1::{Variant1, Variant2};
228 use std::marker::PhantomData;
232 struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
240 pub use self::Enum2::{Variant1, Variant2};
245 Variant2(super::Struct1),
249 pub use self::Enum3::{Variant1, Variant2};
259 trait Trait1 { fn dummy(&self) { } }
260 trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
262 impl Trait1 for isize {}
263 impl<T1, T2> Trait2<T1, T2> for isize {}
265 fn rust_fn(_: Option<isize>, _: Option<&mod1::Struct2>) {}
266 extern "C" fn extern_c_fn(_: isize) {}
267 unsafe fn unsafe_fn(_: Result<char, f64>) {}
268 extern "stdcall" fn extern_stdcall_fn() {}
270 fn rust_fn_with_return_value(_: f64) -> usize { 4 }
271 extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 }
272 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 { mod1::Struct2 }
273 extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize { 0 }
275 fn generic_function<T>(x: T) -> T { x }
277 #[allow(improper_ctypes)]
279 fn printf(_:*const u8, ...) -> isize;
282 // In many of the cases below, the type that is actually under test is wrapped
283 // in a tuple, e.g. Box<T>, references, raw pointers, fixed-size vectors, ...
284 // This is because GDB will not print the type name from DWARF debuginfo for
285 // some kinds of types (pointers, arrays, functions, ...)
286 // Since tuples are structs as far as GDB is concerned, their name will be
287 // printed correctly, so the tests below just construct a tuple type that will
288 // then *contain* the type name that we want to see.
292 let simple_struct = Struct1;
293 let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
294 GenericStruct(PhantomData);
295 let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
296 GenericStruct(PhantomData);
297 let mod_struct = mod1::Struct2;
300 let simple_enum_1 = Variant1;
301 let simple_enum_2 = Variant2(0);
302 let simple_enum_3 = mod1::Variant2(Struct1);
304 let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
305 let generic_enum_2 = mod1::mod2::Variant2(Struct1);
308 let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
309 let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
312 let box1 = (box 1f32, 0i32);
313 let box2 = (box mod1::mod2::Variant2(1f32), 0i32);
316 let ref1 = (&Struct1, 0i32);
317 let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
319 let mut mut_struct1 = Struct1;
320 let mut mut_generic_struct = GenericStruct::<mod1::Enum2, f64>(PhantomData);
321 let mut_ref1 = (&mut mut_struct1, 0i32);
322 let mut_ref2 = (&mut mut_generic_struct, 0i32);
325 let mut_ptr1: (*mut Struct1, isize) = (ptr::null_mut(), 0);
326 let mut_ptr2: (*mut isize, isize) = (ptr::null_mut(), 0);
327 let mut_ptr3: (*mut mod1::mod2::Enum3<Struct1>, isize) = (ptr::null_mut(), 0);
329 let const_ptr1: (*const Struct1, isize) = (ptr::null(), 0);
330 let const_ptr2: (*const isize, isize) = (ptr::null(), 0);
331 let const_ptr3: (*const mod1::mod2::Enum3<Struct1>, isize) = (ptr::null(), 0);
334 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
335 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
337 let vec1 = vec![0_usize, 2, 3];
339 let vec2 = vec![mod1::Variant2(Struct1)];
343 let box_trait = (box 0_isize) as Box<Trait1>;
344 let ref_trait = &0_isize as &Trait1;
345 let mut mut_int1 = 0_isize;
346 let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
348 let generic_box_trait = (box 0_isize) as Box<Trait2<i32, mod1::Struct2>>;
349 let generic_ref_trait = (&0_isize) as &Trait2<Struct1, Struct1>;
351 let mut generic_mut_ref_trait_impl = 0_isize;
352 let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
353 &mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
356 let rust_fn = (rust_fn, 0_usize);
357 let extern_c_fn = (extern_c_fn, 0_usize);
358 let unsafe_fn = (unsafe_fn, 0_usize);
359 let extern_stdcall_fn = (extern_stdcall_fn, 0_usize);
361 let rust_fn_with_return_value = (rust_fn_with_return_value, 0_usize);
362 let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0_usize);
363 let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0_usize);
364 let extern_stdcall_fn_with_return_value = (extern_stdcall_fn_with_return_value, 0_usize);
366 let generic_function_int = (generic_function::<isize>, 0_usize);
367 let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
369 let variadic_function = (printf, 0_usize);
372 // I (mw) am a bit unclear about the current state of closures, their
373 // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
374 // how that maps to rustc's internal representation of these forms.
375 // Once closures have reached their 1.0 form, the tests below should
376 // probably be expanded.
377 let closure1 = (|x:isize| {}, 0_usize);
378 let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize);