1 # Copyright (C) 2014-2023 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 # On decr_pc_after_break targets, GDB used to adjust the PC
17 # incorrectly if a background single-step stopped somewhere where
18 # PC-$decr_pc had a breakpoint, and the thread was not the current
21 # ADDR1 nop <-- breakpoint here
24 # IOW, say thread A is stepping ADDR2's line in the background (an
25 # infinite loop), and the user switches focus to thread B. GDB's
26 # adjust_pc_after_break logic would confuse the single-step stop of
27 # thread A for a hit of the breakpoint at ADDR1, and thus adjust
28 # thread A's PC to point at ADDR1 when it should not: the thread had
29 # been single-stepped, not continued.
33 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
41 # Make sure it's GDB's decr_pc logic that's being tested, not the
43 gdb_test_no_output "set range-stepping off"
47 gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
48 gdb_continue_to_breakpoint "run to nop breakpoint"
49 gdb_test "info threads" " 1 .*\\\* 2 .*" "info threads shows all threads"
51 gdb_test "next" "while.*" "next over nop"
53 gdb_test_no_output "next&" "next& over inf loop"
55 set test "switch to main thread"
56 gdb_test_multiple "thread 1" $test {
57 -re "Cannot execute this command while the target is running.*$gdb_prompt $" {
60 # With remote targets, we can't send any other remote packet
61 # until the target stops. Switching thread wants to ask the
62 # remote side whether the thread is alive.
65 -re "Switching to thread 1.*\\(running\\)\r\n$gdb_prompt " {
66 # Prefer to match the prompt without an anchor. If there's a
67 # bug and output comes after the prompt immediately, it's
68 # faster to handle that in the following test, instead of
69 # waiting for a timeout here.
74 # Wait a bit. Use gdb_expect instead of sleep so that any (bad) GDB
75 # output is visible in the log.
78 set test "no output while stepping"
79 gdb_test_multiple "" $test {
85 # If we see any output, it's a failure. On the original bug,
86 # this would be a breakpoint hit.