]>
Commit | Line | Data |
---|---|---|
61baf725 | 1 | # Copyright (C) 2016-2017 Free Software Foundation, Inc. |
67218854 TT |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # Test expression parsing and evaluation that requires Rust compiler. | |
17 | ||
18 | load_lib rust-support.exp | |
19 | if {[skip_rust_tests]} { | |
20 | continue | |
21 | } | |
22 | ||
23 | standard_testfile .rs | |
5b362f04 | 24 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} { |
67218854 TT |
25 | return -1 |
26 | } | |
27 | ||
28 | set line [gdb_get_line_number "set breakpoint here"] | |
29 | if {![runto ${srcfile}:$line]} { | |
5b362f04 | 30 | untested "could not run to breakpoint" |
67218854 TT |
31 | return -1 |
32 | } | |
33 | ||
34 | gdb_test "print a" " = \\(\\)" | |
35 | gdb_test "ptype a" " = \\(\\)" | |
cdf5a07c | 36 | gdb_test "print sizeof(a)" " = 0" |
67218854 TT |
37 | |
38 | gdb_test "print b" " = \\\[\\\]" | |
39 | gdb_test "ptype b" " = \\\[i32; 0\\\]" | |
40 | gdb_test "print *(&b as *const \[i32; 0\])" " = \\\[\\\]" | |
41 | gdb_test "print *(&b as *const \[i32; 0_0\])" " = \\\[\\\]" | |
42 | ||
43 | gdb_test "print c" " = 99" | |
44 | gdb_test "ptype c" " = i32" | |
cdf5a07c | 45 | gdb_test "print sizeof(c)" " = 4" |
67218854 TT |
46 | |
47 | gdb_test "print c = 87" " = \\(\\)" | |
48 | gdb_test "print c" " = 87" | |
49 | gdb_test "print c += 3" " = \\(\\)" | |
50 | gdb_test "print c" " = 90" | |
51 | gdb_test "print c -= 90" " = \\(\\)" | |
52 | gdb_test "print c" " = 0" | |
53 | gdb_test "print *&c" " = 0" | |
54 | gdb_test "print *(&c as &i32)" " = 0" | |
55 | gdb_test "print *(&c as *const i32)" " = 0" | |
56 | gdb_test "print *(&c as *mut i32)" " = 0" | |
57 | ||
58 | gdb_test "print j" " = simple::Unit" | |
59 | gdb_test "ptype j" " = struct simple::Unit" | |
12df5c00 TT |
60 | gdb_test "print j2" " = simple::Unit" |
61 | gdb_test "ptype j2" " = struct simple::Unit" | |
67218854 | 62 | gdb_test "print simple::Unit" " = simple::Unit" |
12df5c00 | 63 | gdb_test "print simple::Unit{}" " = simple::Unit" |
67218854 TT |
64 | |
65 | gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\"" | |
66 | gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]" | |
67 | ||
68 | gdb_test "print v" " = simple::Something::Three" | |
69 | gdb_test_sequence "ptype v" "" { | |
70 | " = enum simple::Something \\{" | |
71 | " One," | |
72 | " Two," | |
73 | " Three," | |
74 | "\\}" | |
75 | } | |
76 | ||
77 | gdb_test "print w" " = \\\[1, 2, 3, 4\\\]" | |
78 | gdb_test "ptype w" " = \\\[i32; 4\\\]" | |
79 | gdb_test "print w\[2\]" " = 3" | |
80 | gdb_test "print w\[2\] @ 2" " = \\\[3, 4\\\]" | |
42d94011 | 81 | gdb_test "print w_ptr\[2\]" " = 3" |
67218854 TT |
82 | gdb_test "print fromslice" " = 3" |
83 | gdb_test "print slice\[0\]" " = 3" | |
84 | gdb_test "print slice as &\[i32\]\[0\]" " = 3" | |
85 | ||
86 | gdb_test "print x" " = \\(23, 25\\.5\\)" | |
87 | gdb_test "ptype x" " = \\(i32, f64\\)" | |
88 | gdb_test "print x as (i32,f64)" " = \\(23, 25\\.5\\)" | |
89 | ||
90 | gdb_test "print y" " = simple::HiBob \\{field1: 7, field2: 8\\}" | |
91 | gdb_test_sequence "ptype y" "" { | |
92 | " = struct simple::HiBob \\{" | |
93 | " field1: i32," | |
94 | " field2: u64," | |
95 | "\\}" | |
96 | } | |
97 | gdb_test "print y.field2" " = 8" | |
98 | ||
99 | gdb_test "print z" " = simple::ByeBob \\(7, 8\\)" | |
100 | gdb_test_sequence "ptype z" "" { | |
101 | " = struct simple::ByeBob \\(" | |
102 | " i32," | |
103 | " u64," | |
104 | "\\)" | |
105 | } | |
106 | gdb_test "print z.1" " = 8" | |
107 | ||
51a789c3 MG |
108 | gdb_test "print univariant" " = simple::Univariant::Foo{a: 1}" |
109 | gdb_test "print univariant.a" " = 1" | |
110 | gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)" | |
111 | gdb_test "print univariant_anon.0" " = 1" | |
112 | ||
f0fd41c1 TT |
113 | gdb_test_sequence "ptype simple::Univariant" "" { |
114 | "type = enum simple::Univariant \\{" | |
115 | " Foo\\{a: u8\\}," | |
116 | "\\}" | |
117 | } | |
118 | ||
119 | gdb_test_sequence "ptype simple::UnivariantAnon" "" { | |
120 | "type = enum simple::UnivariantAnon \\{" | |
121 | " Foo\\(u8\\)," | |
122 | "\\}" | |
123 | } | |
124 | ||
67218854 TT |
125 | gdb_test_sequence "ptype simple::ByeBob" "" { |
126 | " = struct simple::ByeBob \\(" | |
127 | " i32," | |
128 | " u64," | |
129 | "\\)" | |
130 | } | |
131 | gdb_test "print simple::ByeBob(0xff, 5)" \ | |
132 | " = simple::ByeBob \\(255, 5\\)" | |
133 | gdb_test "print simple::ByeBob\{field1: 0xff, field2:5\}" \ | |
134 | "Struct expression applied to non-struct type" | |
135 | ||
136 | gdb_test "print simple::HiBob(0xff, 5)" \ | |
137 | "Type simple::HiBob is not a tuple struct" | |
138 | gdb_test "print nosuchsymbol" \ | |
139 | "No symbol 'nosuchsymbol' in current context" | |
140 | ||
141 | gdb_test "print e" " = simple::MoreComplicated::Two\\(73\\)" | |
142 | gdb_test "print e2" \ | |
143 | " = simple::MoreComplicated::Four\\{this: true, is: 8, a: 109 'm', struct_: 100, variant: 10\\}" | |
cdf5a07c | 144 | gdb_test "print sizeof(e)" " = 24" |
67218854 TT |
145 | gdb_test_sequence "ptype e" "" { |
146 | " = enum simple::MoreComplicated \\{" | |
147 | " One," | |
148 | " Two\\(i32\\)," | |
149 | " Three\\(simple::HiBob\\)," | |
150 | " Four\\{this: bool, is: u8, a: char, struct_: u64, variant: u32\\}," | |
151 | "\\}" | |
152 | } | |
153 | ||
154 | gdb_test "print e.0" " = 73" | |
155 | gdb_test "print e.1" \ | |
156 | "Cannot access field 1 of variant simple::MoreComplicated::Two, there are only 1 fields" | |
157 | gdb_test "print e.foo" \ | |
158 | "Attempting to access named field foo of tuple variant simple::MoreComplicated::Two, which has only anonymous fields" | |
159 | ||
160 | gdb_test "print e2.variant" " = 10" | |
161 | gdb_test "print e2.notexist" \ | |
162 | "Could not find field notexist of struct variant simple::MoreComplicated::Four" | |
163 | gdb_test "print e2.0" \ | |
164 | "Variant simple::MoreComplicated::Four is not a tuple variant" | |
165 | ||
166 | gdb_test "print k" " = simple::SpaceSaver::Nothing" | |
167 | gdb_test "print l" " = simple::SpaceSaver::Thebox\\(9, $hex\\)" | |
168 | gdb_test "print *l.1" " = 1729" | |
169 | ||
170 | gdb_test "print diff2(3, 7)" " = -4" | |
171 | gdb_test "print self::diff2(8, 9)" " = -1" | |
172 | gdb_test "print ::diff2(23, -23)" " = 46" | |
173 | ||
174 | gdb_test "ptype diff2" "fn \\(i32, i32\\) -> i32" | |
921d8f54 | 175 | gdb_test "ptype empty" "fn \\(\\)" |
67218854 TT |
176 | |
177 | gdb_test "print (diff2 as fn(i32, i32) -> i32)(19, -2)" " = 21" | |
178 | ||
179 | # We need the ".*" because currently we don't extract the length and | |
180 | # use it to intelligently print the string data. | |
181 | gdb_test "print \"hello rust\"" \ | |
182 | " = &str \\{data_ptr: $hex \"hello rust.*\", length: 10\\}" | |
183 | gdb_test "print \"hello" "Unexpected EOF in string" | |
184 | gdb_test "print r##\"hello \" rust\"##" \ | |
185 | " = &str \\{data_ptr: $hex \"hello \\\\\" rust.*\", length: 12\\}" | |
186 | gdb_test "print r\"hello" "Unexpected EOF in string" | |
187 | gdb_test "print r###\"###hello\"" "Unexpected EOF in string" | |
188 | gdb_test "print r###\"###hello\"##" "Unexpected EOF in string" | |
189 | gdb_test "print r###\"hello###" "Unexpected EOF in string" | |
190 | ||
191 | gdb_test "print 0..5" " = .*::ops::Range.* \\{start: 0, end: 5\\}" | |
192 | gdb_test "print ..5" " = .*::ops::RangeTo.* \\{end: 5\\}" | |
193 | gdb_test "print 5.." " = .*::ops::RangeFrom.* \\{start: 5\\}" | |
194 | gdb_test "print .." " = .*::ops::RangeFull" | |
195 | ||
fccb08f8 MG |
196 | gdb_test "print str_some" \ |
197 | " = core::option::Option<collections::string::String>::Some\\(collections::string::String .*" | |
198 | gdb_test "print str_none" " = core::option::Option<collections::string::String>::None" | |
199 | gdb_test "print int_some" " = core::option::Option::Some\\(1\\)" | |
200 | gdb_test "print int_none" " = core::option::Option::None" | |
201 | gdb_test "print box_some" " = core::option::Option<Box<u8>>::Some\\(.*\\)" | |
202 | gdb_test "print box_none" " = core::option::Option<Box<u8>>::None" | |
203 | gdb_test "print custom_some" \ | |
204 | " = simple::NonZeroOptimized::Value\\(collections::string::String .*" | |
205 | gdb_test "print custom_none" " = simple::NonZeroOptimized::Empty" | |
206 | ||
67218854 TT |
207 | proc test_one_slice {svar length base range} { |
208 | global hex | |
209 | ||
210 | set result " = &\\\[.*\\\] \\{data_ptr: $hex, length: $length\\}" | |
211 | ||
212 | gdb_test "print $svar" $result | |
213 | gdb_test "print &${base}\[${range}\]" $result | |
214 | } | |
215 | ||
216 | test_one_slice slice 1 w 2..3 | |
217 | test_one_slice slice2 1 slice 0..1 | |
218 | ||
219 | test_one_slice all1 4 w .. | |
220 | test_one_slice all2 1 slice .. | |
221 | ||
222 | test_one_slice from1 3 w 1.. | |
223 | test_one_slice from2 0 slice 1.. | |
224 | ||
225 | test_one_slice to1 3 w ..3 | |
226 | test_one_slice to2 1 slice ..1 | |
227 | ||
228 | gdb_test "print w\[2..3\]" "Can't take slice of array without '&'" | |
229 | ||
230 | ||
231 | gdb_test_sequence "complete print y.f" "" \ | |
232 | {"print y.field1" "print y.field2"} | |
233 | gdb_test_sequence "complete print y." "" \ | |
234 | {"print y.field1" "print y.field2"} | |
235 | ||
236 | # Unimplemented, but we can at least test the parser productions. | |
237 | gdb_test "print (1,2,3)" "Tuple expressions not supported yet" | |
238 | gdb_test "print (1,)" "Tuple expressions not supported yet" | |
239 | gdb_test "print (1)" " = 1" | |
240 | ||
241 | gdb_test "print 23..97.0" "Range expression with different types" | |
51a789c3 MG |
242 | |
243 | gdb_test "print (*parametrized.next.val)" \ | |
244 | " = simple::ParametrizedStruct<i32> {next: simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Empty, value: 1}" | |
245 | gdb_test "print parametrized.next.val" \ | |
246 | " = \\(simple::ParametrizedStruct<i32> \\*\\) $hex" | |
247 | gdb_test "print parametrized" \ | |
248 | " = simple::ParametrizedStruct<i32> \\{next: simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Val\\{val: $hex\\}, value: 0\\}" |