55ebd40c2e4c29ebbe2593ede9d4a0432d26f578
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / step-bg-decr-pc-switch-thread.exp
1 # Copyright (C) 2014-2021 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
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
19 # thread, like:
20 #
21 # ADDR1 nop <-- breakpoint here
22 # ADDR2 jmp PC
23 #
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.
30
31 standard_testfile
32
33 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
34 return -1
35 }
36
37 clean_restart $binfile
38
39 if ![runto_main] {
40 continue
41 }
42
43 # Make sure it's GDB's decr_pc logic that's being tested, not the
44 # target's.
45 gdb_test_no_output "set range-stepping off"
46
47 delete_breakpoints
48
49 gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
50 gdb_continue_to_breakpoint "run to nop breakpoint"
51 gdb_test "info threads" " 1 .*\\\* 2 .*" "info threads shows all threads"
52
53 gdb_test "next" "while.*" "next over nop"
54
55 gdb_test_no_output "next&" "next& over inf loop"
56
57 set test "switch to main thread"
58 gdb_test_multiple "thread 1" $test {
59 -re "Cannot execute this command while the target is running.*$gdb_prompt $" {
60 unsupported $test
61
62 # With remote targets, we can't send any other remote packet
63 # until the target stops. Switching thread wants to ask the
64 # remote side whether the thread is alive.
65 return
66 }
67 -re "Switching to thread 1.*\\(running\\)\r\n$gdb_prompt " {
68 # Prefer to match the prompt without an anchor. If there's a
69 # bug and output comes after the prompt immediately, it's
70 # faster to handle that in the following test, instead of
71 # waiting for a timeout here.
72 pass $test
73 }
74 }
75
76 # Wait a bit. Use gdb_expect instead of sleep so that any (bad) GDB
77 # output is visible in the log.
78 gdb_expect 4 {}
79
80 set test "no output while stepping"
81 gdb_test_multiple "" $test {
82 -timeout 1
83 timeout {
84 pass $test
85 }
86 -re "." {
87 # If we see any output, it's a failure. On the original bug,
88 # this would be a breakpoint hit.
89 fail $test
90 }
91 }
This page took 0.033021 seconds and 3 git commands to generate.