Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.threads / continue-pending-after-query.exp
bloba0a7915fca8c79b0340542462f02364c9c674b85
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2022 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 # Regression test for a bug that would go like this:
20 # - Run to a breakpoint that is hit by two threads (A and B)
21 #   simultaneously.
23 # - One of the breakpoint hits is processed (e.g., thread A) and
24 #   causes a user-visible stop.  The other (thread B) is left pending.
26 # - The user deletes the breakpoint with "del", which causes a
27 #   confirmation query.
29 # - By mistake, that would result in the target being left with async
30 #   enabled, even though it wasn't to begin with.
32 # - GDB reacts to target async enablement by polling for target
33 #   events.  As no thread is resumed the target replies
34 #   TARGET_WAITKIND_NO_RESUMED.
36 # - The user continues the program, expecting it to exit.  The thread
37 #   that has an event pending (thread B) is not really resumed.
39 # - But, nothing signals the event loop that there's a pending event
40 #   waiting to be collected for thread B, so that event is never
41 #   processed, thread B is never resumed and the program never exits.
43 # Ref: https://sourceware.org/ml/gdb-patches/2015-01/msg00592.html
45 standard_testfile
47 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
48     return -1
51 proc test {} {
52     global srcfile gdb_prompt
54     if ![runto_main] {
55         return -1
56     }
58     delete_breakpoints
60     set bp_line [gdb_get_line_number "set break here" $srcfile]
62     gdb_breakpoint "break_function"
63     gdb_continue_to_breakpoint "cont to break_function" ".*$srcfile:$bp_line\r\n.*"
65     # Do something that causes a query/secondary prompt.
67     set test "delete breakpoints, answer prompt"
68     set saw_prompt 0
69     gdb_test_multiple "delete breakpoints" $test {
70         -re "Delete all breakpoints.*y or n.*$" {
71             set saw_prompt 1
72             send_gdb "y\n"
73             exp_continue
74         }
75         -re "$gdb_prompt $" {
76             gdb_assert $saw_prompt $test
77         }
78     }
80     gdb_continue_to_end "" "continue" 1
83 # Test a few times to make sure an event is left pending.  At the time
84 # of writing, the bug always triggers, but that might naturally depend
85 # on machine.
86 for {set i 1} {$i <= 10} {incr i} {
87     with_test_prefix "iter $i" {
88         test
89     }