]>
Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright 2017-2018 Free Software Foundation, Inc. |
a0922d80 PA |
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 | ||
22 | if [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. | |
28 | if [target_info exists gdb,nointerrupts] { | |
29 | verbose "Skipping because of nointerrupts." | |
30 | return | |
31 | } | |
32 | ||
33 | standard_testfile | |
34 | ||
35 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { | |
36 | return -1 | |
37 | } | |
38 | ||
39 | # See intro. | |
40 | ||
41 | proc 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 | -re "Quit\r\n\r\nCommand aborted.\r\n$gdb_prompt $" { | |
94 | send_log "$internal_pass (Command aborted)\n" | |
95 | } | |
96 | -re "Breakpoint \[^\r\n\]*$srcfile" { | |
97 | exp_continue | |
98 | } | |
99 | }] != 0} { | |
100 | break | |
101 | } | |
102 | } | |
103 | ||
104 | gdb_assert {$iter == 20} "stop with control-c" | |
105 | } | |
106 | ||
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 | |
111 | # "attach". | |
112 | ||
113 | with_test_prefix "run" { | |
114 | clean_restart $binfile | |
115 | ||
116 | if {![runto_main]} { | |
117 | return -1 | |
118 | } | |
119 | ||
120 | do_test | |
121 | } | |
122 | ||
123 | with_test_prefix "attach" { | |
124 | if {[can_spawn_for_attach]} { | |
125 | clean_restart $binfile | |
126 | ||
127 | set test_spawn_id [spawn_wait_for_attach $binfile] | |
128 | set testpid [spawn_id_get_pid $test_spawn_id] | |
129 | ||
130 | gdb_test "attach $testpid" "Attaching to.*process $testpid.*" "attach" | |
131 | ||
132 | do_test | |
133 | ||
134 | kill_wait_spawned_process $test_spawn_id | |
135 | } | |
136 | } |