simple.exp revision 1.1.1.3
1# Copyright (C) 2016-2019 Free Software Foundation, Inc. 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 18load_lib rust-support.exp 19if {[skip_rust_tests]} { 20 continue 21} 22 23standard_testfile .rs 24if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} { 25 return -1 26} 27 28set line [gdb_get_line_number "set breakpoint here"] 29if {![runto ${srcfile}:$line]} { 30 untested "could not run to breakpoint" 31 return -1 32} 33 34gdb_test "print a" " = \\(\\)" 35gdb_test "ptype a" " = \\(\\)" 36gdb_test "print sizeof(a)" " = 0" 37 38gdb_test "print b" " = \\\[\\\]" 39gdb_test "ptype b" " = \\\[i32; 0\\\]" 40gdb_test "print *(&b as *const \[i32; 0\])" " = \\\[\\\]" 41gdb_test "print *(&b as *const \[i32; 0_0\])" " = \\\[\\\]" 42 43gdb_test "print c" " = 99" 44gdb_test "ptype c" " = i32" 45gdb_test "print sizeof(c)" " = 4" 46 47gdb_test "print c = 87" " = \\(\\)" 48gdb_test "print c" " = 87" 49gdb_test "print c += 3" " = \\(\\)" 50gdb_test "print c" " = 90" 51gdb_test "print c -= 90" " = \\(\\)" 52gdb_test "print c" " = 0" 53gdb_test "print *&c" " = 0" 54gdb_test "print *(&c as &i32)" " = 0" 55gdb_test "print *(&c as *const i32)" " = 0" 56gdb_test "print *(&c as *mut i32)" " = 0" 57gdb_test "ptype &c as *mut i32" "\\*mut i32" 58 59gdb_test "print/c f\[0\]" " = 104 'h'" 60 61gdb_test "print j" " = simple::Unit" 62gdb_test "ptype j" " = struct simple::Unit" 63gdb_test "print j2" " = simple::Unit" 64gdb_test "ptype j2" " = struct simple::Unit" 65gdb_test "print simple::Unit" " = simple::Unit" 66gdb_test "print simple::Unit{}" " = simple::Unit" 67 68gdb_test "print f" " = \"hi bob\"" 69gdb_test "print fslice" " = \"bob\"" 70gdb_test "print &f\[3..\]" " = \"bob\"" 71 72gdb_test "print g" " = \\(\\*mut \\\[u8; 6\\\]\\) $hex b\"hi bob\"" 73gdb_test "ptype g" " = \\*mut \\\[u8; 6\\\]" 74 75gdb_test "print v" " = simple::Something::Three" 76gdb_test_sequence "ptype v" "" { 77 " = enum simple::Something \\{" 78 " One," 79 " Two," 80 " Three," 81 "\\}" 82} 83 84gdb_test "print w" " = \\\[1, 2, 3, 4\\\]" 85gdb_test "ptype w" " = \\\[i32; 4\\\]" 86gdb_test "print w\[2\]" " = 3" 87gdb_test "print w\[2\] @ 2" " = \\\[3, 4\\\]" 88gdb_test "print w_ptr\[2\]" " = 3" 89gdb_test "print fromslice" " = 3" 90gdb_test "print slice\[0\]" " = 3" 91gdb_test "print slice as &\[i32\]\[0\]" " = 3" 92 93gdb_test_sequence "ptype slice" "" { 94 " = struct &\\\[i32\\\] \\{" 95 " data_ptr: \\*mut i32," 96 " length: usize," 97 "\\}" 98} 99gdb_test_sequence "ptype &slice\[..\]" "" { 100 " = struct &\\\[i32\\\] \\{" 101 " data_ptr: \\*mut i32," 102 " length: usize," 103 "\\}" 104} 105gdb_test_sequence "ptype &b\[..\]" "" { 106 " = struct &\\\[\\*gdb\\*\\\] \\{" 107 " data_ptr: \\*mut i32," 108 " length: usize," 109 "\\}" 110} 111 112gdb_test "print x" " = \\(23, 25\\.5\\)" 113gdb_test "ptype x" " = \\(i32, f64\\)" 114gdb_test "print x as (i32,f64)" " = \\(23, 25\\.5\\)" 115 116gdb_test "print y" " = simple::HiBob \\{field1: 7, field2: 8\\}" 117gdb_test_sequence "ptype y" "" { 118 " = struct simple::HiBob \\{" 119 " field1: i32," 120 " field2: u64," 121 "\\}" 122} 123gdb_test "print y.field2" " = 8" 124 125gdb_test "print z" " = simple::ByeBob \\(7, 8\\)" 126gdb_test_sequence "ptype z" "" { 127 " = struct simple::ByeBob \\(" 128 " i32," 129 " u64," 130 "\\)" 131} 132gdb_test "print z.1" " = 8" 133 134gdb_test "print univariant" " = simple::Univariant::Foo{a: 1}" 135gdb_test "print univariant.a" " = 1" 136gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)" 137gdb_test "print univariant_anon.0" " = 1" 138gdb_test "print univariant_anon.sss" \ 139 "Attempting to access named field sss of tuple variant simple::UnivariantAnon::Foo, which has only anonymous fields" 140 141gdb_test_sequence "ptype simple::Univariant" "" { 142 "type = enum simple::Univariant \\{" 143 " Foo\\{a: u8\\}," 144 "\\}" 145} 146 147gdb_test_sequence "ptype simple::UnivariantAnon" "" { 148 "type = enum simple::UnivariantAnon \\{" 149 " Foo\\(u8\\)," 150 "\\}" 151} 152 153gdb_test_sequence "ptype simple::ByeBob" "" { 154 " = struct simple::ByeBob \\(" 155 " i32," 156 " u64," 157 "\\)" 158} 159gdb_test "print simple::ByeBob(0xff, 5)" \ 160 " = simple::ByeBob \\(255, 5\\)" 161gdb_test "print simple::ByeBob\{field1: 0xff, field2:5\}" \ 162 "Struct expression applied to non-struct type" 163 164gdb_test "print simple::HiBob(0xff, 5)" \ 165 "Type simple::HiBob is not a tuple struct" 166gdb_test "print sizeof(simple::HiBob)" " = \[0-9\]+" 167gdb_test "print simple::HiBob + 5" \ 168 "Found type 'simple::HiBob', which can't be evaluated in this context" 169gdb_test "print nosuchsymbol" \ 170 "No symbol 'nosuchsymbol' in current context" 171 172gdb_test "print simple::HiBob{field1, field2}" \ 173 " = simple::HiBob \\{field1: 77, field2: 88\\}" 174 175gdb_test "print simple::HiBob{field1: 99, .. y}" \ 176 " = simple::HiBob \\{field1: 99, field2: 8\\}" 177 178gdb_test "print e" " = simple::MoreComplicated::Two\\(73\\)" 179gdb_test "print e2" \ 180 " = simple::MoreComplicated::Four\\{this: true, is: 8, a: 109 'm', struct_: 100, variant: 10\\}" 181gdb_test "print sizeof(e)" " = 24" 182gdb_test_sequence "ptype e" "" { 183 " = enum simple::MoreComplicated \\{" 184 " One," 185 " Two\\(i32\\)," 186 " Three\\(simple::HiBob\\)," 187 " Four\\{this: bool, is: u8, a: char, struct_: u64, variant: u32\\}," 188 "\\}" 189} 190 191gdb_test "print e.0" " = 73" 192gdb_test "print e.1" \ 193 "Cannot access field 1 of variant simple::MoreComplicated::Two, there are only 1 fields" 194gdb_test "print e.foo" \ 195 "Attempting to access named field foo of tuple variant simple::MoreComplicated::Two, which has only anonymous fields" 196 197gdb_test "print e2.variant" " = 10" 198gdb_test "print e2.notexist" \ 199 "Could not find field notexist of struct variant simple::MoreComplicated::Four" 200gdb_test "print e2.0" \ 201 "Variant simple::MoreComplicated::Four is not a tuple variant" 202 203gdb_test "print k" " = simple::SpaceSaver::Nothing" 204gdb_test "print l" " = simple::SpaceSaver::Thebox\\(9, $hex\\)" 205gdb_test "print *l.1" " = 1729" 206 207gdb_test "print diff2(3, 7)" " = -4" 208gdb_test "print self::diff2(8, 9)" " = -1" 209gdb_test "print ::diff2(23, -23)" " = 46" 210 211gdb_test "ptype diff2" "fn \\(i32, i32\\) -> i32" 212gdb_test "ptype empty" "fn \\(\\)" 213 214gdb_test "print (diff2 as fn(i32, i32) -> i32)(19, -2)" " = 21" 215 216gdb_test "print \"hello rust\"" " = \"hello rust.*\"" 217gdb_test "print \"hello" "Unexpected EOF in string" 218gdb_test "print r##\"hello \" rust\"##" " = \"hello \\\\\" rust.*\"" 219gdb_test "print r\"hello" "Unexpected EOF in string" 220gdb_test "print r###\"###hello\"" "Unexpected EOF in string" 221gdb_test "print r###\"###hello\"##" "Unexpected EOF in string" 222gdb_test "print r###\"hello###" "Unexpected EOF in string" 223 224gdb_test "print 0..5" " = .*::ops::Range.* \\{start: 0, end: 5\\}" 225gdb_test "print 0..=5" " = .*::ops::RangeInclusive.* \\{start: 0, end: 5\\}" 226gdb_test "print ..5" " = .*::ops::RangeTo.* \\{end: 5\\}" 227gdb_test "print ..=5" " = .*::ops::RangeToInclusive.* \\{end: 5\\}" 228gdb_test "print 5.." " = .*::ops::RangeFrom.* \\{start: 5\\}" 229gdb_test "print .." " = .*::ops::RangeFull" 230 231gdb_test "print str_some" \ 232 " = core::option::Option<\[a-z\]+::string::String>::Some\\(\[a-z\]+::string::String .*" 233gdb_test "print str_none" " = core::option::Option<\[a-z\]+::string::String>::None" 234gdb_test "print int_some" " = core::option::Option<u8>::Some\\(1\\)" 235gdb_test "print int_none" " = core::option::Option<u8>::None" 236gdb_test "print box_some" " = core::option::Option<\[a-z:\]*Box<u8>>::Some\\(.*\\)" 237gdb_test "print box_none" " = core::option::Option<\[a-z:\]*Box<u8>>::None" 238gdb_test "print custom_some" \ 239 " = simple::NonZeroOptimized::Value\\(\[a-z\]+::string::String .*" 240gdb_test "print custom_none" " = simple::NonZeroOptimized::Empty" 241 242proc test_one_slice {svar length base range} { 243 global hex 244 245 set result " = &\\\[.*\\\] \\{data_ptr: $hex, length: $length\\}" 246 247 gdb_test "print $svar" $result 248 gdb_test "print &${base}\[${range}\]" $result 249} 250 251test_one_slice slice 1 w 2..3 252test_one_slice slice 1 w 2..=2 253test_one_slice slice2 1 slice 0..1 254test_one_slice slice2 1 slice 0..=0 255 256test_one_slice all1 4 w .. 257test_one_slice all2 1 slice .. 258 259test_one_slice from1 3 w 1.. 260test_one_slice from2 0 slice 1.. 261 262test_one_slice to1 3 w ..3 263test_one_slice to1 3 w ..=2 264test_one_slice to2 1 slice ..1 265test_one_slice to2 1 slice ..=0 266 267gdb_test "print w\[2..3\]" "Can't take slice of array without '&'" 268 269 270gdb_test_sequence "complete print y.f" "" \ 271 {"print y.field1" "print y.field2"} 272gdb_test_sequence "complete print y." "" \ 273 {"print y.field1" "print y.field2"} 274 275# Unimplemented, but we can at least test the parser productions. 276gdb_test "print (1,2,3)" "Tuple expressions not supported yet" 277gdb_test "print (1,)" "Tuple expressions not supported yet" 278gdb_test "print (1)" " = 1" 279 280gdb_test "print 23..97.0" "Range expression with different types" 281 282gdb_test "print (*parametrized.next.val)" \ 283 " = simple::ParametrizedStruct<i32> {next: simple::ParametrizedEnum<\[a-z:\]*Box<simple::ParametrizedStruct<i32>>>::Empty, value: 1}" 284gdb_test "print parametrized.next.val" \ 285 " = \\(\\*mut simple::ParametrizedStruct<i32>\\) $hex" 286gdb_test "print parametrized" \ 287 " = simple::ParametrizedStruct<i32> \\{next: simple::ParametrizedEnum<\[a-z:\]*Box<simple::ParametrizedStruct<i32>>>::Val\\{val: $hex\\}, value: 0\\}" 288 289gdb_test "print u" " = simple::Union {f1: -1, f2: 255}" 290 291gdb_test_sequence "ptype/o Union" "" { 292 "/\\* offset | size \\*/ type = union simple::Union {" 293 "/\\* 1 \\*/ f1: i8," 294 "/\\* 1 \\*/ f2: u8," 295 "" 296 " /\\* total size \\(bytes\\): 1 \\*/" 297 " }" 298} 299 300gdb_test_sequence "ptype/o SimpleLayout" "" { 301 "/\\* offset | size \\*/ type = struct simple::SimpleLayout {" 302 "/\\* 0 | 2 \\*/ f1: u16," 303 "/\\* 2 | 2 \\*/ f2: u16," 304 "" 305 " /\\* total size \\(bytes\\): 4 \\*/" 306 " }" 307} 308 309# PR rust/23626 - this used to crash. Note that the results are 310# fairly lax because most existing versions of Rust (those before the 311# DW_TAG_variant patches) do not emit what gdb wants here; and there 312# was little point fixing gdb to cope with these cases as the fixed 313# compilers will be available soon 314gdb_test "print empty_enum_value" \ 315 " = simple::EmptyEnum.*" 316gdb_test "ptype empty_enum_value" "simple::EmptyEnum.*" 317# Just make sure these don't crash, for the same reason. 318gdb_test "print empty_enum_value.0" "" 319gdb_test "print empty_enum_value.something" "" 320 321load_lib gdb-python.exp 322if {[skip_python_tests]} { 323 continue 324} 325 326gdb_test "python print(gdb.lookup_type('simple::HiBob'))" "simple::HiBob" 327