1 1.1.1.2 christos # Copyright 2021-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test --exec-interrupt with thread-group. 17 1.1 christos # 18 1.1 christos # Run two inferiors, try interrupting them both with --exec-interrupt + 19 1.1 christos # --thread-group. 20 1.1 christos 21 1.1 christos load_lib mi-support.exp 22 1.1 christos set MIFLAGS "-i=mi" 23 1.1 christos 24 1.1 christos standard_testfile .c 25 1.1 christos 26 1.1 christos if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile \ 27 1.1 christos executable {debug additional_flags=-std=gnu99}] != "" } { 28 1.1 christos return -1 29 1.1 christos } 30 1.1 christos 31 1.1 christos save_vars { GDBFLAGS } { 32 1.1 christos append GDBFLAGS " -ex \"set non-stop on\" -ex \"set mi-async\"" 33 1.1 christos mi_clean_restart $binfile 34 1.1 christos } 35 1.1 christos 36 1.1 christos mi_detect_async 37 1.1 christos 38 1.1 christos # Create breakpoint by hand instead of using mi_runto, since we'll need it for 39 1.1 christos # both inferiors. 40 1.1 christos mi_create_breakpoint "all_threads_started" \ 41 1.1 christos "set breakpoint on all_threads_started" 42 1.1 christos 43 1.1 christos # Run first inferior to all_threads_started (to ensure all threads are started) 44 1.1 christos # and resume it. 45 1.1 christos if { [mi_run_cmd] < 0 } { 46 1.1 christos return 47 1.1 christos } 48 1.1 christos 49 1.1 christos mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \ 50 1.1 christos "inferior i1 stops at all_threads_started" 51 1.1 christos 52 1.1 christos mi_send_resuming_command "exec-continue --thread-group i1" \ 53 1.1 christos "continue inferior 1" 54 1.1 christos 55 1.1 christos # We can't run a second inferior on stub targets. We can still test with one 56 1.1 christos # inferior and ensure that the command has the desired effect. 57 1.1 christos set use_second_inferior [expr {![use_gdb_stub]}] 58 1.1 christos 59 1.1 christos if { $use_second_inferior } { 60 1.1 christos mi_gdb_test "-add-inferior" \ 61 1.1 christos "\\^done,inferior=\"i2\",connection=\\{\[^\}\]+\\}" \ 62 1.1 christos "add inferior 2" 63 1.1 christos mi_gdb_test "-file-exec-and-symbols --thread-group i2 $::binfile" \ 64 1.1 christos "\\^done" \ 65 1.1 christos "set executable of inferior 2" 66 1.1 christos # Run second inferior to all_threads_started (to ensure all threads are 67 1.1 christos # started) and resume it. 68 1.1 christos mi_gdb_test "-exec-run --thread-group i2" \ 69 1.1 christos "\\^running.*" \ 70 1.1 christos "run inferior 2" 71 1.1 christos 72 1.1 christos mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\"" "locno=\"[0-9]+\""} \ 73 1.1 christos "inferior i2 stops at all_threads_started" 74 1.1 christos 75 1.1 christos mi_send_resuming_command "exec-continue --thread-group i2" \ 76 1.1 christos "continue inferior 2" 77 1.1 christos 78 1.1 christos mi_check_thread_states { 79 1.1 christos "running" "running" "running" "running" "running" 80 1.1 christos "running" "running" "running" "running" "running" 81 1.1 christos } "before interrupting" 82 1.1 christos } else { 83 1.1 christos mi_check_thread_states { 84 1.1 christos "running" "running" "running" "running" "running" 85 1.1 christos } "before interrupting" 86 1.1 christos } 87 1.1 christos 88 1.1 christos # Interrupt inferior 1, wait for events. 89 1.1 christos mi_gdb_test "-exec-interrupt --thread-group i1" \ 90 1.1 christos "\\^done" \ 91 1.1 christos "interrupt inferior 1" 92 1.1 christos 93 1.1 christos for {set i 0} {$i < 5} {incr i} { 94 1.1 christos mi_expect_interrupt "inferior 1, interrupt $i" 95 1.1 christos } 96 1.1 christos 97 1.1 christos if { $use_second_inferior } { 98 1.1 christos mi_check_thread_states { 99 1.1 christos "stopped" "stopped" "stopped" "stopped" "stopped" 100 1.1 christos "running" "running" "running" "running" "running" 101 1.1 christos } "after interrupting inferior 1" 102 1.1 christos 103 1.1 christos # Interrupt inferior 2, wait for events. 104 1.1 christos mi_gdb_test "-exec-interrupt --thread-group i2" \ 105 1.1 christos "\\^done" \ 106 1.1 christos "interrupt inferior 2" 107 1.1 christos 108 1.1 christos for {set i 0} {$i < 5} {incr i} { 109 1.1 christos mi_expect_interrupt "inferior 2, interrupt $i" 110 1.1 christos } 111 1.1 christos 112 1.1 christos mi_check_thread_states { 113 1.1 christos "stopped" "stopped" "stopped" "stopped" "stopped" 114 1.1 christos "stopped" "stopped" "stopped" "stopped" "stopped" 115 1.1 christos } "after interrupting inferior 2" 116 1.1 christos } else { 117 1.1 christos mi_check_thread_states { 118 1.1 christos "stopped" "stopped" "stopped" "stopped" "stopped" 119 1.1 christos } "after interrupting inferior 1" 120 1.1 christos } 121