1# Copyright 1998, 1999, 2007 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# Please email any bugs, comments, and/or additions to this file to: 17# bug-gdb@prep.ai.mit.edu 18 19if $tracelevel then { 20 strace $tracelevel 21 } 22 23set prms_id 0 24set bug_id 0 25 26clear_xfail "*-*-*" 27 28set testfile "jump" 29set srcfile ${testfile}.c 30set binfile ${objdir}/${subdir}/${testfile} 31 32# Build the test case 33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { 34 untested jump.exp 35 return -1 36 } 37 38 39# Start with a fresh gdb 40 41gdb_exit 42gdb_start 43gdb_reinitialize_dir $srcdir/$subdir 44gdb_load ${binfile} 45 46if ![runto_main] then { 47 perror "Couldn't run to main" 48 return -1 49} 50 51# Set a breakpoint on the statement that we're about to jump to. 52# The statement doesn't contain a function call. 53# 54send_gdb "break 22\n" 55set bp_on_non_call 0 56gdb_expect { 57 -re "\[Bb\]reakpoint (\[0-9\]*) at 0x\[0-9a-fA-F\]*: file .*${srcfile}, line 22.*$gdb_prompt $"\ 58 {set bp_on_non_call $expect_out(1,string) 59 pass "break before jump to non-call"} 60 -re "$gdb_prompt $"\ 61 {fail "break before jump to non-call"} 62 timeout {fail "(timeout) break before jump to non-call"} 63} 64 65# Can we jump to the statement? Do we stop there? 66# 67send_gdb "jump 22\n" 68gdb_expect { 69 -re "Breakpoint \[0-9\]*, .*${srcfile}:22.*$gdb_prompt $"\ 70 {pass "jump to non-call"} 71 -re "$gdb_prompt $"\ 72 {fail "jump to non-call"} 73 timeout {fail "(timeout) jump to non-call"} 74} 75 76# Set a breakpoint on the statement that we're about to jump to. 77# The statement does contain a function call. 78# 79send_gdb "break 21\n" 80set bp_on_call 0 81gdb_expect { 82 -re "\[Bb\]reakpoint (\[0-9\]*) at 0x\[0-9a-fA-F\]*: file .*${srcfile}, line 21.*$gdb_prompt $"\ 83 {set bp_on_call $expect_out(1,string) 84 pass "break before jump to call"} 85 -re "$gdb_prompt $"\ 86 {fail "break before jump to call"} 87 timeout {fail "(timeout) break before jump to call"} 88} 89 90# Can we jump to the statement? Do we stop there? 91# 92send_gdb "jump 21\n" 93gdb_expect { 94 -re "Breakpoint \[0-9\]*, .*${srcfile}:21.*$gdb_prompt $"\ 95 {pass "jump to call"} 96 -re "$gdb_prompt $"\ 97 {fail "jump to call"} 98 timeout {fail "(timeout) jump to call"} 99} 100 101# If we disable the breakpoint at the function call, and then 102# if we jump to that statement, do we not stop there, but at 103# the following breakpoint? 104# 105send_gdb "disable $bp_on_call\n" 106gdb_expect { 107 -re "$gdb_prompt $"\ 108 {pass "disable breakpoint on call"} 109 timeout {fail "(timeout) disable breakpoint on call"} 110} 111 112send_gdb "jump 21\n" 113gdb_expect { 114 -re "Breakpoint \[0-9\]*, .*${srcfile}:22.*$gdb_prompt $"\ 115 {pass "jump to call with disabled breakpoint"} 116 -re "$gdb_prompt $"\ 117 {fail "jump to call with disabled breakpoint"} 118 timeout {fail "(timeout) jump to call with disabled breakpoint"} 119} 120 121# Verify that GDB responds gracefully to the "jump" command without 122# an argument. 123# 124send_gdb "jump\n" 125gdb_expect { 126 -re "Argument required .starting address..*$gdb_prompt $"\ 127 {pass "jump without argument disallowed"} 128 -re "$gdb_prompt $"\ 129 {fail "jump without argument disallowed"} 130 timeout {fail "(timeout) jump without argument disallowed"} 131} 132 133# Verify that GDB responds gracefully to the "jump" command with 134# trailing junk. 135# 136send_gdb "jump 21 100\n" 137gdb_expect { 138 -re "Junk at end of line specification: 100.*$gdb_prompt $"\ 139 {pass "jump with trailing argument junk"} 140 -re "$gdb_prompt $"\ 141 {fail "jump with trailing argument junk"} 142 timeout {fail "(timeout) jump with trailing argument junk"} 143} 144 145# Verify that GDB responds gracefully to a request to jump out of 146# the current function. (Note that this will very likely cause the 147# inferior to die. Be prepared to rerun the inferior, if further 148# testing is desired.) 149# 150# Try it both ways: confirming and not confirming the jump. 151# 152send_gdb "jump 12\n" 153gdb_expect { 154 -re "Line 12 is not in `main'. Jump anyway.*y or n. $"\ 155 {send_gdb "n\n" 156 gdb_expect { 157 -re "Not confirmed.*$gdb_prompt $"\ 158 {pass "aborted jump out of current function"} 159 -re "$gdb_prompt $"\ 160 {fail "aborted jump out of current function"} 161 timeout {fail "(timeout) aborted jump out of current function"} 162 } 163 } 164 -re "$gdb_prompt $"\ 165 {fail "aborted jump out of current function"} 166 timeout {fail "(timeout) aborted jump out of current function"} 167} 168 169send_gdb "jump 12\n" 170gdb_expect { 171 -re "Line 12 is not in `main'. Jump anyway.*y or n. $"\ 172 {send_gdb "y\n" 173 gdb_expect { 174 -re "Continuing at.*$gdb_prompt $"\ 175 {pass "jump out of current function"} 176 -re "$gdb_prompt $"\ 177 {fail "jump out of current function"} 178 timeout {fail "(timeout) jump out of current function"} 179 } 180 } 181 -re "$gdb_prompt $"\ 182 {fail "jump out of current function"} 183 timeout {fail "(timeout) jump out of current function"} 184} 185 186gdb_exit 187return 0 188