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