1 # Copyright 1998-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/>. */
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
25 # General testing of the 'jump' command. GDB is already started.
26 # There might be multiple inferior in the current debug session, in
27 # which case, the relevant inferior is already selected.
29 # Set a breakpoint on the statement that we're about to jump to.
30 # The statement doesn't contain a function call.
31 set non_call_line [gdb_get_line_number "bp-on-non-call"]
32 gdb_breakpoint "$non_call_line"
34 [get_integer_valueof "\$bpnum" "INVALID" "bp_on_non_call"]
36 # Can we jump to the statement? Do we stop there?
37 gdb_test "jump $non_call_line" \
38 "Breakpoint ${bp_on_non_call}(\.${::decimal})?, .*${::srcfile}:$non_call_line.*" \
41 # Set a breakpoint on the statement that we're about to jump to.
42 # The statement does contain a function call.
43 set call_line [gdb_get_line_number "bp-on-call"]
44 gdb_breakpoint "$call_line"
45 set bp_on_call [get_integer_valueof "\$bpnum" "INVALID" "bp_on_call"]
47 # Can we jump to the statement? Do we stop there?
48 gdb_test "jump $call_line" \
49 "Breakpoint ${bp_on_call}(\.${::decimal})?, .*${::srcfile}:$call_line.*" \
52 # If we disable the breakpoint at the function call, and then
53 # if we jump to that statement, do we not stop there, but at
54 # the following breakpoint?
55 gdb_test_no_output "disable $bp_on_call" "disable breakpoint on call"
57 gdb_test "jump $call_line" \
58 "Breakpoint ${bp_on_non_call}(\.${::decimal})?, .*${::srcfile}:$non_call_line.*" \
59 "jump to call with disabled breakpoint"
61 # Disable the breakpoint at the non-function call, so it won't hit
62 # if do_test is called again.
63 gdb_test_no_output "disable ${bp_on_non_call}" "disable bp_on_non_call"
65 # Verify that GDB responds gracefully to the "jump" command without
67 gdb_test "jump" "Argument required .starting address.*" \
68 "jump without argument disallowed"
70 # Verify that GDB responds gracefully to the "jump" command with
72 gdb_test "jump $call_line 100" \
73 "malformed linespec error: unexpected number, \"100\"" \
74 "jump with trailing argument junk"
76 # Verify that GDB responds gracefully to a request to jump out of
77 # the current function. (Note that this will very likely cause the
78 # inferior to die. Be prepared to rerun the inferior, if further
79 # testing is desired.)
80 # Try it both ways: confirming and not confirming the jump.
81 set out_line [gdb_get_line_number "out-of-func"]
82 gdb_test "jump $out_line" \
84 "aborted jump out of current function" \
85 "Line $out_line is not in `main'. Jump anyway.*y or n. $" \
88 gdb_test "jump $out_line" \
90 "jump out of current function" \
91 "Line $out_line is not in `main'. Jump anyway.*y or n. $" \
96 if {![use_gdb_stub]} {
100 # Run to main, add inferiors if needed.
104 for {set inf 2} {$inf <= $num_inferiors} {incr inf} {
105 # Start a new inferior, and run it with the same executable.
106 gdb_test "add-inferior -exec ${binfile}" \
107 "Added inferior ${inf}.*" \
108 "add inferior ${inf} with -exec "
109 gdb_test "inferior ${inf}" \
110 "Switching to inferior ${inf} .*" \
111 "switch to inferior ${inf}"
117 # Run tests on all inferiors.
118 for {set inf 1} {$inf <= $num_inferiors} {incr inf} {
119 with_test_prefix "inferior $inf" {
120 # Switch to the target inferior.
121 gdb_test "inferior $inf" ".*Switching to inferior $inf .*"