Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / infcall-from-bp-cond-other-thread-event.exp
blobb5c0d84afbfaf48176ec64b1f1a0d84c02db091f
1 # Copyright 2022-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 # Test for conditional breakpoints where the breakpoint condition includes
17 # an inferior function call.
19 # The tests in this script are testing what happens when an event arrives in
20 # another thread while GDB is waiting for the inferior function call (in the
21 # breakpoint condition) to finish.
23 # The expectation is that GDB will queue events for other threads and wait
24 # for the inferior function call to complete, if the condition is true, then
25 # the conditional breakpoint should be reported first.  The other thread
26 # event should of course, not get lost, and should be reported as soon as
27 # the user tries to continue the inferior.
29 # If the conditional breakpoint ends up not being taken (the condition is
30 # false), then the other thread event should be reported immediately.
32 # This script tests what happens when the other thread event is (a) the
33 # other thread hitting a breakpoint, and (b) the other thread taking a
34 # signal (SIGSEGV in this case).
36 standard_testfile
38 if { [build_executable "failed to prepare" ${binfile} "${srcfile}" \
39           {debug pthreads}] == -1 } {
40     return
43 set cond_bp_line [gdb_get_line_number "First thread breakpoint"]
44 set other_bp_line [gdb_get_line_number "Other thread breakpoint"]
45 set final_bp_line [gdb_get_line_number "Final breakpoint here"]
46 set signal_line [gdb_get_line_number "Signal here"]
48 # Start GDB based on TARGET_ASYNC and TARGET_NON_STOP, and then runto main.
49 proc start_gdb_and_runto_main { target_async target_non_stop } {
50     save_vars { ::GDBFLAGS } {
51         append ::GDBFLAGS \
52             " -ex \"maint set target-non-stop $target_non_stop\""
53         append ::GDBFLAGS \
54             " -ex \"maintenance set target-async ${target_async}\""
56         clean_restart ${::binfile}
57     }
59     if { ![runto_main] } {
60         return -1
61     }
63     return 0
66 # Run a test of GDB's conditional breakpoints, where the conditions include
67 # inferior function calls.  While the inferior function call is executing
68 # another thread will hit a breakpoint (when OTHER_THREAD_SIGNAL is false),
69 # or receive a signal (when OTHER_THREAD_SIGNAL is true).  GDB should report
70 # the conditional breakpoint first (if the condition is true), and then
71 # report the second thread event once the inferior is continued again.
73 # When STOP_AT_COND is true then the conditional breakpoint will have a
74 # condition that evaluates to true (and GDB will stop at the breakpoint),
75 # otherwise, the condition will evaluate to false (and GDB will not stop at
76 # the breakpoint).
77 proc run_condition_test { stop_at_cond other_thread_signal \
78                               target_async target_non_stop } {
79     if { [start_gdb_and_runto_main $target_async \
80               $target_non_stop] == -1 } {
81         return
82     }
84     # Setup the conditional breakpoint.
85     if { $stop_at_cond } {
86         set cond_func "condition_true_func"
87     } else {
88         set cond_func "condition_false_func"
89     }
90     gdb_breakpoint \
91         "${::srcfile}:${::cond_bp_line} if (${cond_func} ())"
92     set cond_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \
93                         "get number for conditional breakpoint"]
95     if { $other_thread_signal } {
96         # Arrange for the other thread to raise a signal while GDB is
97         # evaluating the breakpoint condition.
98         gdb_test_no_output "set raise_signal = 1"
99     } else {
100         # And a breakpoint that will be hit by another thread only once the
101         # breakpoint condition starts to be evaluated.
102         gdb_breakpoint "${::srcfile}:${::other_bp_line}"
103         set other_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \
104                               "get number for other breakpoint"]
105     }
107     # A final breakpoint once the test has completed.
108     gdb_breakpoint "${::srcfile}:${::final_bp_line}"
109     set final_bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \
110                           "get number for final breakpoint"]
112     if { $stop_at_cond } {
113         # Continue.  The first breakpoint we hit should be the conditional
114         # breakpoint.  The other thread will have hit its breakpoint, but
115         # that will have been deferred until the conditional breakpoint is
116         # reported.
117         gdb_test "continue" \
118             [multi_line \
119                  "Continuing\\." \
120                  ".*" \
121                  "" \
122                  "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${cond_bp_num}, worker_func \[^\r\n\]+:${::cond_bp_line}" \
123                  "${::decimal}\\s+\[^\r\n\]+First thread breakpoint\[^\r\n\]+"] \
124             "hit the conditional breakpoint"
125     }
127     if { $other_thread_signal } {
128         # Now continue again, the other thread will now report that it
129         # received a signal.
130         gdb_test "continue" \
131             [multi_line \
132                  "Continuing\\." \
133                  ".*" \
134                  "Thread ${::decimal} \"\[^\"\r\n\]+\" received signal SIGSEGV, Segmentation fault\\." \
135                  "\\\[Switching to Thread \[^\r\n\]+\\\]" \
136                  "${::hex} in worker_func \[^\r\n\]+:${::signal_line}" \
137                  "${::decimal}\\s+\[^\r\n\]+Signal here\[^\r\n\]+"] \
138             "received signal in other thread"
139     } else {
140         # Now continue again, the other thread will now report its
141         # breakpoint.
142         gdb_test "continue" \
143             [multi_line \
144                  "Continuing\\." \
145                  ".*" \
146                  "" \
147                  "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${other_bp_num}, worker_func \[^\r\n\]+:${::other_bp_line}" \
148                  "${::decimal}\\s+\[^\r\n\]+Other thread breakpoint\[^\r\n\]+"] \
149             "hit the breakpoint in other thread"
151         # Run to the stop marker.
152         gdb_test "continue" \
153             [multi_line \
154                  "Continuing\\." \
155                  ".*" \
156                  "" \
157                  "Thread ${::decimal} \"\[^\"\r\n\]+\" hit Breakpoint ${final_bp_num}, stop_marker \[^\r\n\]+:${::final_bp_line}" \
158                  "${::decimal}\\s+\[^\r\n\]+Final breakpoint here\[^\r\n\]+"] \
159             "hit the final breakpoint"
160     }
162     gdb_exit
165 foreach_with_prefix target_async { "on" "off" } {
166     foreach_with_prefix target_non_stop { "on" "off" } {
167         foreach_with_prefix other_thread_signal { true false } {
168             foreach_with_prefix stop_at_cond { true false } {
169                 run_condition_test $stop_at_cond $other_thread_signal \
170                     $target_async $target_non_stop
171             }
172         }
173     }