]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | |
1a4d82fc JJ |
12 | // min-lldb-version: 310 |
13 | ||
14 | // compile-flags:-g | |
15 | ||
16 | // === GDB TESTS =================================================================================== | |
17 | ||
18 | // gdb-command:run | |
19 | ||
20 | // gdb-command:print some | |
9346a6ac | 21 | // gdb-check:$1 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x12345678}} |
1a4d82fc JJ |
22 | |
23 | // gdb-command:print none | |
9346a6ac | 24 | // gdb-check:$2 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x0}} |
1a4d82fc JJ |
25 | |
26 | // gdb-command:print full | |
9346a6ac | 27 | // gdb-check:$3 = {RUST$ENCODED$ENUM$1$Empty = {__0 = 454545, __1 = 0x87654321, __2 = 9988}} |
1a4d82fc JJ |
28 | |
29 | // gdb-command:print empty_gdb->discr | |
30 | // gdb-check:$4 = (isize *) 0x0 | |
31 | ||
32 | // gdb-command:print droid | |
33 | // gdb-check:$5 = {RUST$ENCODED$ENUM$2$Void = {id = 675675, range = 10000001, internals = 0x43218765}} | |
34 | ||
35 | // gdb-command:print void_droid_gdb->internals | |
36 | // gdb-check:$6 = (isize *) 0x0 | |
37 | ||
85aaf69f | 38 | // gdb-command:print nested_non_zero_yep |
9346a6ac | 39 | // gdb-check:$7 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = 10.5, __1 = {a = 10, b = 20, c = [...]}}} |
85aaf69f SL |
40 | |
41 | // gdb-command:print nested_non_zero_nope | |
9346a6ac | 42 | // gdb-check:$8 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = [...], __1 = {a = [...], b = [...], c = 0x0}}} |
85aaf69f | 43 | |
1a4d82fc JJ |
44 | // gdb-command:continue |
45 | ||
46 | ||
47 | // === LLDB TESTS ================================================================================== | |
48 | ||
49 | // lldb-command:run | |
50 | ||
51 | // lldb-command:print some | |
52 | // lldb-check:[...]$0 = Some(&0x12345678) | |
53 | ||
54 | // lldb-command:print none | |
55 | // lldb-check:[...]$1 = None | |
56 | ||
57 | // lldb-command:print full | |
58 | // lldb-check:[...]$2 = Full(454545, &0x87654321, 9988) | |
59 | ||
60 | // lldb-command:print empty | |
61 | // lldb-check:[...]$3 = Empty | |
62 | ||
63 | // lldb-command:print droid | |
64 | // lldb-check:[...]$4 = Droid { id: 675675, range: 10000001, internals: &0x43218765 } | |
65 | ||
66 | // lldb-command:print void_droid | |
67 | // lldb-check:[...]$5 = Void | |
68 | ||
69 | // lldb-command:print some_str | |
62682a34 | 70 | // lldb-check:[...]$6 = Some("abc") |
1a4d82fc JJ |
71 | |
72 | // lldb-command:print none_str | |
73 | // lldb-check:[...]$7 = None | |
74 | ||
85aaf69f SL |
75 | // lldb-command:print nested_non_zero_yep |
76 | // lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] }) | |
77 | ||
78 | // lldb-command:print nested_non_zero_nope | |
79 | // lldb-check:[...]$9 = Nope | |
80 | ||
1a4d82fc JJ |
81 | |
82 | #![omit_gdb_pretty_printer_section] | |
83 | ||
84 | // If a struct has exactly two variants, one of them is empty, and the other one | |
85 | // contains a non-nullable pointer, then this value is used as the discriminator. | |
86 | // The test cases in this file make sure that something readable is generated for | |
87 | // this kind of types. | |
88 | // If the non-empty variant contains a single non-nullable pointer than the whole | |
89 | // item is represented as just a pointer and not wrapped in a struct. | |
90 | // Unfortunately (for these test cases) the content of the non-discriminant fields | |
91 | // in the null-case is not defined. So we just read the discriminator field in | |
92 | // this case (by casting the value to a memory-equivalent struct). | |
93 | ||
94 | enum MoreFields<'a> { | |
95 | Full(u32, &'a isize, i16), | |
96 | Empty | |
97 | } | |
98 | ||
99 | struct MoreFieldsRepr<'a> { | |
100 | a: u32, | |
101 | discr: &'a isize, | |
102 | b: i16 | |
103 | } | |
104 | ||
105 | enum NamedFields<'a> { | |
106 | Droid { id: i32, range: i64, internals: &'a isize }, | |
107 | Void | |
108 | } | |
109 | ||
110 | struct NamedFieldsRepr<'a> { | |
111 | id: i32, | |
112 | range: i64, | |
113 | internals: &'a isize | |
114 | } | |
115 | ||
85aaf69f SL |
116 | struct NestedNonZeroField<'a> { |
117 | a: u16, | |
118 | b: u32, | |
119 | c: &'a char, | |
120 | } | |
121 | ||
122 | enum NestedNonZero<'a> { | |
123 | Yep(f64, NestedNonZeroField<'a>), | |
124 | Nope | |
125 | } | |
126 | ||
1a4d82fc JJ |
127 | fn main() { |
128 | ||
129 | let some_str: Option<&'static str> = Some("abc"); | |
130 | let none_str: Option<&'static str> = None; | |
131 | ||
85aaf69f | 132 | let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678_usize) }); |
1a4d82fc JJ |
133 | let none: Option<&u32> = None; |
134 | ||
85aaf69f | 135 | let full = MoreFields::Full(454545, unsafe { std::mem::transmute(0x87654321_usize) }, 9988); |
1a4d82fc JJ |
136 | |
137 | let empty = MoreFields::Empty; | |
138 | let empty_gdb: &MoreFieldsRepr = unsafe { std::mem::transmute(&MoreFields::Empty) }; | |
139 | ||
140 | let droid = NamedFields::Droid { | |
141 | id: 675675, | |
142 | range: 10000001, | |
85aaf69f | 143 | internals: unsafe { std::mem::transmute(0x43218765_usize) } |
1a4d82fc JJ |
144 | }; |
145 | ||
146 | let void_droid = NamedFields::Void; | |
147 | let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) }; | |
148 | ||
85aaf69f SL |
149 | let x = 'x'; |
150 | let nested_non_zero_yep = NestedNonZero::Yep( | |
151 | 10.5, | |
152 | NestedNonZeroField { | |
153 | a: 10, | |
154 | b: 20, | |
155 | c: &x | |
156 | }); | |
157 | ||
158 | let nested_non_zero_nope = NestedNonZero::Nope; | |
159 | ||
1a4d82fc JJ |
160 | zzz(); // #break |
161 | } | |
162 | ||
163 | fn zzz() {()} |