1 # Copyright 2023-2024 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 # Check that sending GDB a SIGINT while handling execution control
17 # does not interrupt the execution control.
19 # The way we get the pid of gdb doesn't work with remote host. We get the
20 # pid of the ssh session on build instead.
21 require {!is_remote host}
25 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
29 # Run the test. Sets a breakpoint with a condition that sends a
30 # SIGINT to GDB, and ensures that that doesn't make the breakpoint hit
31 # cause a premature stop. This emulates pressing Ctrl-C just while
32 # GDB is evaluating the breakpoint condition.
34 # AFTER_KILL_COND is appended to the breakpoint condition, after "kill
36 proc test { {after_kill_cond ""} } {
37 clean_restart $::binfile
45 set gdb_pid [exp_pid -i [board_info host fileid]]
47 # Set a breakpoint with a condition that sends a SIGINT to GDB. This
48 # emulates pressing Ctrl-C just while GDB is evaluating the breakpoint
51 "break foo if \$hit_count\+\+ == 1 || \$_shell(\"kill -INT $gdb_pid\") != 0 $after_kill_cond" \
53 "break foo if <condition>"
55 for { set i 0 } { $i < 10 } { incr i } {
59 # A counter used in the breakpoint's condition to ensure that it
60 # causes a stop after one hit.
61 gdb_test "p \$hit_count = 0" " = 0" "reset hit counter"
63 # Number of times we've seen GDB print "Quit" followed by the
64 # prompt. We should see that exactly one time.
67 gdb_test_multiple "c&" "SIGINT does not interrupt background execution" {
68 -re "^c&\r\nContinuing\\.\r\n$::gdb_prompt " {
71 -re "^Quit\r\n$::gdb_prompt " {
73 verbose -log "quit_count=$quit_count"
76 -re "^\r\nBreakpoint .*return 0;" {
77 gdb_assert {$quit_count == 1} $gdb_test_name
79 -re ".*Asynchronous execution not supported on this target\..*" {
80 unsupported "$gdb_test_name (asynchronous execution not supported)"
84 fail "$gdb_test_name (timeout)"
95 # Test without writing to memory after killing GDB. This does not
96 # take any Python path at the time of writing.
97 with_test_prefix "no force memory write" {
101 # Writing to memory from the condition makes GDB enter Python for
102 # reporting a memory changed event. Thus this tests that GDB doesn't
103 # forward the SIGINT to Python, interrupting Python, causing the
104 # breakpoint to prematurely stop like:
108 # (gdb) Error in testing breakpoint condition:
111 with_test_prefix "force memory write" {
112 test " || (global = 0)"