1 # Copyright (C) 2016-2024 Free Software Foundation, Inc.
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.
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.
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/>.
18 load_lib rust-support.exp
19 require allow_rust_tests
20 require {can_compile rust}
23 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
27 set line [gdb_get_line_number "set breakpoint 1 here"]
28 if {![runto ${srcfile}:$line]} {
29 untested "could not run to breakpoint"
33 gdb_test "print x" " = methods::HasMethods \\{value: 0\\}"
35 gdb_test "print methods::HasMethods{value: 73}" \
36 " = methods::HasMethods \\{value: 73\\}"
37 gdb_test "print methods::HasMethods{..x}" \
38 " = methods::HasMethods \\{value: 0\\}"
39 gdb_test "print methods::HasMethods{value:19, ..x}" \
40 " = methods::HasMethods \\{value: 19\\}"
42 gdb_test "print x.take()" " = methods::HasMethods \\{value: 0\\}"
43 gdb_test "print *(x.incr())" " = methods::HasMethods \\{value: 1\\}"
44 gdb_test "print *((&mut x).incr())" " = methods::HasMethods \\{value: 2\\}"
46 gdb_test "print a.value()" " = 23"
47 gdb_test "print (&mut a).value()" " = 23"
48 # gdb_test "print a.take_value().0" " = 23"
49 gdb_test "print b.value()" " = 24"
51 gdb_test "print c.value()" " = 452"
53 set line [gdb_get_line_number "set breakpoint 2 here"]
54 gdb_breakpoint ${srcfile}:$line
55 gdb_continue_to_breakpoint "second breakpoint"
57 gdb_test "print *self" " = 23"
60 gdb_test "info functions HasMethods::new" \
61 "fn methods::HasMethods::new\\(\\) -> methods::HasMethods;"
63 # Regression test for PR rust/20367 and PR rust/30211. This used to
65 gdb_test_no_output "complete break what"