]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/gdb-pretty-struct-and-enums.rs
auto merge of #16909 : carols10cents/rust/docs-links, r=alexcrichton
[rust.git] / src / test / debuginfo / gdb-pretty-struct-and-enums.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-test FIXME(#16919)
12 // ignore-tidy-linelength
13 // ignore-lldb
14 // ignore-android: FIXME(#10381)
15 // compile-flags:-g
16 // gdb-use-pretty-printer
17
18 // This test uses some GDB Python API features (e.g. accessing anonymous fields)
19 // which are only available in newer GDB version. The following directive will
20 // case the test runner to ignore this test if an older GDB version is used:
21 // min-gdb-version 7.7
22
23 // The following line actually doesn't have to do anything with pretty printing,
24 // it just tells GDB to print values on one line:
25 // gdb-command: set print pretty off
26
27 // gdb-command: rbreak zzz
28 // gdb-command: run
29 // gdb-command: finish
30
31 // gdb-command: print regular_struct
32 // gdb-check:$1 = RegularStruct = {the_first_field = 101, the_second_field = 102.5, the_third_field = false, the_fourth_field = "I'm so pretty, oh so pretty..."}
33
34 // gdb-command: print tuple
35 // gdb-check:$2 = {true, 103, "blub"}
36
37 // gdb-command: print tuple_struct
38 // gdb-check:$3 = TupleStruct = {-104.5, 105}
39
40 // gdb-command: print empty_struct
41 // gdb-check:$4 = EmptyStruct
42
43 // gdb-command: print c_style_enum1
44 // gdb-check:$5 = CStyleEnumVar1
45
46 // gdb-command: print c_style_enum2
47 // gdb-check:$6 = CStyleEnumVar2
48
49 // gdb-command: print c_style_enum3
50 // gdb-check:$7 = CStyleEnumVar3
51
52 // gdb-command: print mixed_enum_c_style_var
53 // gdb-check:$8 = MixedEnumCStyleVar
54
55 // gdb-command: print mixed_enum_tuple_var
56 // gdb-check:$9 = MixedEnumTupleVar = {106, 107, false}
57
58 // gdb-command: print mixed_enum_struct_var
59 // gdb-check:$10 = MixedEnumStructVar = {field1 = 108.5, field2 = 109}
60
61 // gdb-command: print some
62 // gdb-check:$11 = Some = {110}
63
64 // gdb-command: print none
65 // gdb-check:$12 = None
66
67 // gdb-command: print nested_variant1
68 // gdb-check:$13 = NestedVariant1 = {NestedStruct = {regular_struct = RegularStruct = {the_first_field = 111, the_second_field = 112.5, the_third_field = true, the_fourth_field = "NestedStructString1"}, tuple_struct = TupleStruct = {113.5, 114}, empty_struct = EmptyStruct, c_style_enum = CStyleEnumVar2, mixed_enum = MixedEnumTupleVar = {115, 116, false}}}
69
70 // gdb-command: print nested_variant2
71 // gdb-check:$14 = NestedVariant2 = {abc = NestedStruct = {regular_struct = RegularStruct = {the_first_field = 117, the_second_field = 118.5, the_third_field = false, the_fourth_field = "NestedStructString10"}, tuple_struct = TupleStruct = {119.5, 120}, empty_struct = EmptyStruct, c_style_enum = CStyleEnumVar3, mixed_enum = MixedEnumStructVar = {field1 = 121.5, field2 = -122}}}
72
73 #![feature(struct_variant)]
74
75 struct RegularStruct {
76     the_first_field: int,
77     the_second_field: f64,
78     the_third_field: bool,
79     the_fourth_field: &'static str,
80 }
81
82 struct TupleStruct(f64, i16);
83
84 struct EmptyStruct;
85
86 enum CStyleEnum {
87     CStyleEnumVar1,
88     CStyleEnumVar2,
89     CStyleEnumVar3,
90 }
91
92 enum MixedEnum {
93     MixedEnumCStyleVar,
94     MixedEnumTupleVar(u32, u16, bool),
95     MixedEnumStructVar { field1: f64, field2: i32 }
96 }
97
98 struct NestedStruct {
99     regular_struct: RegularStruct,
100     tuple_struct: TupleStruct,
101     empty_struct: EmptyStruct,
102     c_style_enum: CStyleEnum,
103     mixed_enum: MixedEnum,
104 }
105
106 enum NestedEnum {
107     NestedVariant1(NestedStruct),
108     NestedVariant2 { abc: NestedStruct }
109 }
110
111 fn main() {
112
113     let regular_struct = RegularStruct {
114         the_first_field: 101,
115         the_second_field: 102.5,
116         the_third_field: false,
117         the_fourth_field: "I'm so pretty, oh so pretty..."
118     };
119
120     let tuple = ( true, 103u32, "blub" );
121
122     let tuple_struct = TupleStruct(-104.5, 105);
123
124     let empty_struct = EmptyStruct;
125
126     let c_style_enum1 = CStyleEnumVar1;
127     let c_style_enum2 = CStyleEnumVar2;
128     let c_style_enum3 = CStyleEnumVar3;
129
130     let mixed_enum_c_style_var = MixedEnumCStyleVar;
131     let mixed_enum_tuple_var = MixedEnumTupleVar(106, 107, false);
132     let mixed_enum_struct_var = MixedEnumStructVar { field1: 108.5, field2: 109 };
133
134     let some = Some(110u);
135     let none: Option<int> = None;
136
137     let nested_variant1 = NestedVariant1(
138         NestedStruct {
139             regular_struct: RegularStruct {
140                 the_first_field: 111,
141                 the_second_field: 112.5,
142                 the_third_field: true,
143                 the_fourth_field: "NestedStructString1",
144             },
145             tuple_struct: TupleStruct(113.5, 114),
146             empty_struct: EmptyStruct,
147             c_style_enum: CStyleEnumVar2,
148             mixed_enum: MixedEnumTupleVar(115, 116, false)
149         }
150     );
151
152     let nested_variant2 = NestedVariant2 {
153         abc: NestedStruct {
154             regular_struct: RegularStruct {
155                 the_first_field: 117,
156                 the_second_field: 118.5,
157                 the_third_field: false,
158                 the_fourth_field: "NestedStructString10",
159             },
160             tuple_struct: TupleStruct(119.5, 120),
161             empty_struct: EmptyStruct,
162             c_style_enum: CStyleEnumVar3,
163             mixed_enum: MixedEnumStructVar {
164                 field1: 121.5,
165                 field2: -122
166             }
167         }
168     };
169
170     zzz();
171 }
172
173 fn zzz() { () }