xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.base/jump.exp (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1#   Copyright 1998-2023 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
17clear_xfail "*-*-*"
18
19standard_testfile .c
20
21# Build the test case
22if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
23     untested "failed to compile"
24     return -1
25    }
26
27
28# Start with a fresh gdb
29
30clean_restart ${binfile}
31
32if {![runto_main]} {
33  return -1
34}
35
36# Set a breakpoint on the statement that we're about to jump to.
37# The statement doesn't contain a function call.
38#
39set bp_on_non_call 0
40set non_call_line [gdb_get_line_number "bp-on-non-call"]
41gdb_test_multiple "break $non_call_line" "break before jump to non-call" {
42    -re "\[Bb\]reakpoint (${decimal}) at ${hex}: file .*${srcfile}, line $non_call_line.*$gdb_prompt $" {
43	set bp_on_non_call $expect_out(1,string)
44	pass "break before jump to non-call"
45    }
46}
47
48# Can we jump to the statement?  Do we stop there?
49#
50gdb_test "jump $non_call_line" "Breakpoint ${decimal}, .*${srcfile}:$non_call_line.*" \
51    "jump to non-call"
52
53# Set a breakpoint on the statement that we're about to jump to.
54# The statement does contain a function call.
55#
56set bp_on_call 0
57set call_line [gdb_get_line_number "bp-on-call"]
58gdb_test_multiple "break $call_line" "break before jump to call" {
59    -re "\[Bb\]reakpoint (${decimal}) at ${hex}: file .*${srcfile}, line $call_line.*$gdb_prompt $" {
60	set bp_on_call $expect_out(1,string)
61	pass "break before jump to call"
62    }
63}
64
65# Can we jump to the statement?  Do we stop there?
66#
67gdb_test "jump $call_line" \
68    "Breakpoint ${decimal}, .*${srcfile}:$call_line.*" \
69    "jump to call"
70
71# If we disable the breakpoint at the function call, and then
72# if we jump to that statement, do we not stop there, but at
73# the following breakpoint?
74#
75gdb_test_no_output "disable $bp_on_call" "disable breakpoint on call"
76
77gdb_test "jump $call_line" "Breakpoint ${decimal}, .*${srcfile}:$non_call_line.*" \
78    "jump to call with disabled breakpoint"
79
80# Verify that GDB responds gracefully to the "jump" command without
81# an argument.
82#
83gdb_test "jump" "Argument required .starting address.*" \
84    "jump without argument disallowed"
85
86
87# Verify that GDB responds gracefully to the "jump" command with
88# trailing junk.
89#
90gdb_test "jump $call_line 100" \
91    "malformed linespec error: unexpected number, \"100\"" \
92    "jump with trailing argument junk"
93
94
95# Verify that GDB responds gracefully to a request to jump out of
96# the current function.  (Note that this will very likely cause the
97# inferior to die.  Be prepared to rerun the inferior, if further
98# testing is desired.)
99#
100# Try it both ways: confirming and not confirming the jump.
101#
102
103set out_line [gdb_get_line_number "out-of-func"]
104gdb_test "jump $out_line" \
105    "Not confirmed.*" \
106    "aborted jump out of current function" \
107    "Line $out_line is not in `main'.  Jump anyway.*y or n. $" \
108    "n"
109
110gdb_test "jump $out_line" \
111    "Continuing at.*" \
112    "jump out of current function" \
113    "Line $out_line is not in `main'.  Jump anyway.*y or n. $" \
114    "y"
115
116gdb_exit
117return 0
118