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