| 1 | # Copyright 2008, 2010-2012 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 | # Test inferior resumption after discarding a hand-called function. |
| 17 | # There are two things to test. |
| 18 | # 1) Inferior stops normally. Upon resumption it should continue normally, |
| 19 | # regardless of whatever signal the hand-called function got. |
| 20 | # 2) Inferior is stopped at a signal. Upon resumption it should continue |
| 21 | # with that signal, regardless of whatever the hand-called function did. |
| 22 | |
| 23 | if $tracelevel then { |
| 24 | strace $tracelevel |
| 25 | } |
| 26 | |
| 27 | if [target_info exists gdb,noinferiorio] { |
| 28 | verbose "Skipping call-signal-resume.exp because of no fileio capabilities." |
| 29 | continue |
| 30 | } |
| 31 | |
| 32 | if [target_info exists gdb,nosignals] { |
| 33 | verbose "Skipping call-signal-resume.exp because of nosignals." |
| 34 | continue |
| 35 | } |
| 36 | |
| 37 | |
| 38 | set testfile "call-signals" |
| 39 | set srcfile ${testfile}.c |
| 40 | set binfile ${objdir}/${subdir}/${testfile} |
| 41 | |
| 42 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 43 | untested call-signal-resume.exp |
| 44 | return -1 |
| 45 | } |
| 46 | |
| 47 | # Some targets can't do function calls, so don't even bother with this |
| 48 | # test. |
| 49 | if [target_info exists gdb,cannot_call_functions] { |
| 50 | setup_xfail "*-*-*" 2416 |
| 51 | fail "This target can not call functions" |
| 52 | continue |
| 53 | } |
| 54 | |
| 55 | proc get_dummy_frame_number { } { |
| 56 | global gdb_prompt |
| 57 | |
| 58 | gdb_test_multiple "bt" "backtrace" { |
| 59 | -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" { |
| 60 | return $expect_out(1,string) |
| 61 | } |
| 62 | } |
| 63 | return "" |
| 64 | } |
| 65 | |
| 66 | # Start with a fresh gdb. |
| 67 | |
| 68 | gdb_exit |
| 69 | gdb_start |
| 70 | gdb_reinitialize_dir $srcdir/$subdir |
| 71 | gdb_load ${binfile} |
| 72 | |
| 73 | if { ![runto_main] } { |
| 74 | fail "Can't run to main" |
| 75 | return 0 |
| 76 | } |
| 77 | |
| 78 | gdb_test "break stop_one" "Breakpoint \[0-9\]* at .*" |
| 79 | gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_one.*" \ |
| 80 | "continue to breakpoint at stop_one" |
| 81 | |
| 82 | # Call function (causing the program to get a signal), and see if gdb handles |
| 83 | # it properly. |
| 84 | gdb_test_multiple "call gen_signal ()" \ |
| 85 | "inferior function call signaled" { |
| 86 | -re "\[\r\n\]*no signal\[\r\n\]+$gdb_prompt $" { |
| 87 | unsupported "inferior function call signaled" |
| 88 | return 0 |
| 89 | } |
| 90 | -re "\[\r\n\]*The program being debugged was signaled.*\[\r\n\]+$gdb_prompt $" { |
| 91 | pass "inferior function call signaled" |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | set frame_number [get_dummy_frame_number] |
| 96 | if { "$frame_number" == "" } { |
| 97 | fail "dummy stack frame number" |
| 98 | setup_xfail "*-*-*" |
| 99 | } else { |
| 100 | pass "dummy stack frame number" |
| 101 | } |
| 102 | |
| 103 | # Pop the dummy frame. |
| 104 | gdb_test "frame $frame_number" ".*" |
| 105 | gdb_test_no_output "set confirm off" |
| 106 | gdb_test_no_output "return" |
| 107 | |
| 108 | # Resume execution, the program should continue without any signal. |
| 109 | |
| 110 | gdb_test "break stop_two" "Breakpoint \[0-9\]* at .*" |
| 111 | gdb_test "continue" "Breakpoint \[0-9\]*, stop_two.*" \ |
| 112 | "continue to breakpoint at stop_two" |
| 113 | |
| 114 | # Continue again, we should get a signal. |
| 115 | |
| 116 | gdb_test "continue" "Program received signal .*" \ |
| 117 | "continue to receipt of signal" |
| 118 | |
| 119 | # Hand call another function that prematurely stops, |
| 120 | # then manually pop the dummy stack frame. |
| 121 | |
| 122 | gdb_test "break null_hand_call" "Breakpoint \[0-9\]* at .*" |
| 123 | gdb_test "call null_hand_call ()" "Breakpoint \[0-9\]*, null_hand_call.*" \ |
| 124 | "null_hand_call" |
| 125 | |
| 126 | set frame_number [get_dummy_frame_number] |
| 127 | if { "$frame_number" == "" } { |
| 128 | fail "dummy stack frame number" |
| 129 | setup_xfail "*-*-*" |
| 130 | # Need something. |
| 131 | set frame_number 0 |
| 132 | } else { |
| 133 | pass "dummy stack frame number" |
| 134 | } |
| 135 | |
| 136 | # Pop the dummy frame. |
| 137 | gdb_test "frame $frame_number" ".*" |
| 138 | gdb_test_no_output "set confirm off" |
| 139 | gdb_test_no_output "return" |
| 140 | |
| 141 | # Continue again, this time we should get to the signal handler. |
| 142 | |
| 143 | gdb_test "break handle_signal" "Breakpoint \[0-9\]* at .*" |
| 144 | gdb_test "continue" "Breakpoint \[0-9\]*, handle_signal.*" \ |
| 145 | "continue to breakpoint at handle_signal" |
| 146 | |
| 147 | # Continue one last time, the program should exit normally. |
| 148 | |
| 149 | gdb_test "continue" "$inferior_exited_re normally." \ |
| 150 | "continue to program exit" |
| 151 | |
| 152 | return 0 |