1 # Copyright 2017-2020 Free Software Foundation, Inc.
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.
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.
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/>.
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.
22 if [target_info exists gdb,nosignals] {
23 verbose "Skipping because of nosignals."
27 # This test requires sending ^C to interrupt the running target.
28 if [target_info exists gdb,nointerrupts] {
29 verbose "Skipping because of nointerrupts."
35 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
42 global srcfile binfile
45 gdb_test "break foo" "Breakpoint .*" "set breakpoint"
54 set test "stop with control-c"
56 for {set iter 0} {$iter < 20} {incr iter} {
58 # Useful for debugging.
59 #send_user "iter: $iter\n"
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
65 if {[gdb_test_multiple "continue" "$test (continue)" {
66 -re "Continuing.*Breakpoint \[^\r\n\]*\r\n" {
72 set internal_pass "IPASS: $test (iter $iter)"
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
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)"
87 -re "Program received signal SIGINT.*\r\n$gdb_prompt $" {
88 send_log "$internal_pass (SIGINT)\n"
90 -re "Quit\r\n$gdb_prompt $" {
91 send_log "$internal_pass (Quit)\n"
93 # Check that if we managed to quit somewhere deep in
94 # the unwinders, we can still unwind again.
96 gdb_test_multiple "bt" "$internal_pass (bt)" {
97 -re "#0.*$gdb_prompt $" {
98 send_log "$internal_pass (bt)\n"
106 -re "Quit\r\n\r\nCommand aborted.\r\n$gdb_prompt $" {
107 send_log "$internal_pass (Command aborted)\n"
109 -re "Breakpoint \[^\r\n\]*$srcfile" {
117 gdb_assert {$iter == 20} "stop with control-c"
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
126 with_test_prefix "run" {
127 clean_restart $binfile
136 with_test_prefix "attach" {
137 if {[can_spawn_for_attach]} {
138 clean_restart $binfile
140 set test_spawn_id [spawn_wait_for_attach $binfile]
141 set testpid [spawn_id_get_pid $test_spawn_id]
143 gdb_test "attach $testpid" "Attaching to.*process $testpid.*" "attach"
147 kill_wait_spawned_process $test_spawn_id