1 # Copyright 2017-2018 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 -re "Quit\r\n\r\nCommand aborted.\r\n$gdb_prompt $" {
94 send_log "$internal_pass (Command aborted)\n"
96 -re "Breakpoint \[^\r\n\]*$srcfile" {
104 gdb_assert {$iter == 20} "stop with control-c"
107 # With native debugging and "run" (with job control), if the inferior
108 # is running, the Ctrl-C reaches the inferior directly, not GDB. With
109 # native debugging and "attach", or with remote debugging, the Ctrl-C
110 # reaches GDB first. So for completeness, try both "run" and
113 with_test_prefix "run" {
114 clean_restart $binfile
123 with_test_prefix "attach" {
124 if {[can_spawn_for_attach]} {
125 clean_restart $binfile
127 set test_spawn_id [spawn_wait_for_attach $binfile]
128 set testpid [spawn_id_get_pid $test_spawn_id]
130 gdb_test "attach $testpid" "Attaching to.*process $testpid.*" "attach"
134 kill_wait_spawned_process $test_spawn_id