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