1# Copyright 2017-2019 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# Set a breakpoint with a "continue" command attached, let the 17# inferior hit the breakpoint continuously. Check that we can use ^C 18# to interrupt the command, and that if ^C is pressed while GDB has 19# the terminal (between the stop and the re-resume), the resulting 20# "Quit" doesn't mess up the debug session. 21 22if [target_info exists gdb,nosignals] { 23 verbose "Skipping because of nosignals." 24 continue 25} 26 27# This test requires sending ^C to interrupt the running target. 28if [target_info exists gdb,nointerrupts] { 29 verbose "Skipping because of nointerrupts." 30 return 31} 32 33standard_testfile 34 35if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 36 return -1 37} 38 39# See intro. 40 41proc do_test {} { 42 global srcfile binfile 43 global gdb_prompt 44 45 gdb_test "break foo" "Breakpoint .*" "set breakpoint" 46 47 gdb_test \ 48 [multi_line_input \ 49 {commands} \ 50 { c} \ 51 {end}] \ 52 "" "commands" 53 54 set test "stop with control-c" 55 56 for {set iter 0} {$iter < 20} {incr iter} { 57 58 # Useful for debugging. 59 #send_user "iter: $iter\n" 60 61 # Consume one breakpoint hit (at least), to make sure that the 62 # continue actually continues between attempts, as opposed to 63 # "c" not actually resuming and then Ctrl-C managing to 64 # interrupt anyway. 65 if {[gdb_test_multiple "continue" "$test (continue)" { 66 -re "Continuing.*Breakpoint \[^\r\n\]*\r\n" { 67 } 68 }] != 0} { 69 return 70 } 71 72 set internal_pass "IPASS: $test (iter $iter)" 73 74 # Breakpoint commands run after the target is considered 75 # stopped, and thus run with GDB owning the terminal. That 76 # means that it is expected that a Ctrl-C that arrives between 77 # - GDB reporting the breakpoint hit, and, 78 # - the breakpoint command continuing the target 79 # results in a Quit. 80 81 after 200 {send_gdb "\003"} 82 if {[gdb_test_multiple "" "$test (unexpected)" { 83 -re "Program terminated with signal SIGALRM.*\r\n$gdb_prompt $" { 84 fail "$test (SIGALRM)" 85 return 86 } 87 -re "Program received signal SIGINT.*\r\n$gdb_prompt $" { 88 send_log "$internal_pass (SIGINT)\n" 89 } 90 -re "Quit\r\n$gdb_prompt $" { 91 send_log "$internal_pass (Quit)\n" 92 93 # Check that if we managed to quit somewhere deep in 94 # the unwinders, we can still unwind again. 95 set ok 0 96 gdb_test_multiple "bt" "$internal_pass (bt)" { 97 -re "#0.*$gdb_prompt $" { 98 send_log "$internal_pass (bt)\n" 99 set ok 1 100 } 101 } 102 if {!$ok} { 103 return 104 } 105 } 106 -re "Quit\r\n\r\nCommand aborted.\r\n$gdb_prompt $" { 107 send_log "$internal_pass (Command aborted)\n" 108 } 109 -re "Breakpoint \[^\r\n\]*$srcfile" { 110 exp_continue 111 } 112 }] != 0} { 113 break 114 } 115 } 116 117 gdb_assert {$iter == 20} "stop with control-c" 118} 119 120# With native debugging and "run" (with job control), if the inferior 121# is running, the Ctrl-C reaches the inferior directly, not GDB. With 122# native debugging and "attach", or with remote debugging, the Ctrl-C 123# reaches GDB first. So for completeness, try both "run" and 124# "attach". 125 126with_test_prefix "run" { 127 clean_restart $binfile 128 129 if {![runto_main]} { 130 return -1 131 } 132 133 do_test 134} 135 136with_test_prefix "attach" { 137 if {[can_spawn_for_attach]} { 138 clean_restart $binfile 139 140 set test_spawn_id [spawn_wait_for_attach $binfile] 141 set testpid [spawn_id_get_pid $test_spawn_id] 142 143 gdb_test "attach $testpid" "Attaching to.*process $testpid.*" "attach" 144 145 do_test 146 147 kill_wait_spawned_process $test_spawn_id 148 } 149} 150