Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / multi-thread-step.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2013-2023 Free Software Foundation, Inc.
4 #
5 # Contributed by Intel Corp. <markus.t.metzger@intel.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 require allow_btrace_tests
21
22 standard_testfile
23 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
24 untested "failed to prepare"
25 return -1
26 }
27 clean_restart $testfile
28
29 if ![runto_main] {
30 return -1
31 }
32
33 # set up breakpoints
34 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
35 set bp_2 [gdb_get_line_number "bp.2" $srcfile]
36 set bp_3 [gdb_get_line_number "bp.3" $srcfile]
37
38 proc gdb_cont_to_line { line } {
39 gdb_breakpoint $line
40 gdb_continue_to_breakpoint "cont to $line" ".*$line\r\n.*"
41 delete_breakpoints
42 }
43
44 proc check_replay_insn { thread insn } {
45 gdb_test "thread apply $thread info record" \
46 "Replay in progress\. At instruction $insn\."
47 }
48
49 proc check_not_replaying { thread } {
50 global gdb_prompt
51
52 set test "thread $thread not replaying"
53
54 gdb_test_multiple "thread apply $thread info record" $test {
55 -re "Replay in progress" {
56 fail $test
57 }
58 -re "$gdb_prompt $" {
59 pass $test
60 }
61 }
62 }
63
64 # trace the code between the two breakpoints
65 delete_breakpoints
66 gdb_cont_to_line $srcfile:$bp_1
67 # make sure GDB knows about the new thread
68 gdb_test "info threads" ".*"
69 gdb_test_no_output "record btrace"
70 gdb_cont_to_line $srcfile:$bp_2
71
72 proc test_navigate {} {
73 with_test_prefix "navigate" {
74 gdb_test "thread 1" ".*"
75 with_test_prefix "thread 1" {
76 gdb_test "record goto begin" ".*"
77
78 check_replay_insn 1 1
79 check_not_replaying 2
80 }
81 gdb_test "thread 2" ".*"
82 with_test_prefix "thread 2" {
83 gdb_test "record goto begin" ".*"
84
85 check_replay_insn 1 1
86 check_replay_insn 2 1
87 }
88 }
89 }
90
91 proc test_step {} {
92 with_test_prefix "step" {
93 gdb_test "thread 1" ".*"
94 with_test_prefix "thread 1" {
95 gdb_test "stepi" ".*"
96
97 check_replay_insn 1 2
98 check_replay_insn 2 1
99 }
100 gdb_test "thread 2" ".*"
101 with_test_prefix "thread 2" {
102 gdb_test "stepi" ".*"
103
104 check_replay_insn 1 2
105 check_replay_insn 2 2
106 }
107 }
108 }
109
110 proc test_cont {} {
111 with_test_prefix "cont" {
112 gdb_test "thread 1" ".*"
113 with_test_prefix "thread 1" {
114 gdb_test "continue" "No more reverse-execution history.*"
115
116 check_not_replaying 1
117 check_replay_insn 2 2
118 }
119 gdb_test "thread 2" ".*"
120 with_test_prefix "thread 2" {
121 gdb_test "continue" "No more reverse-execution history.*"
122
123 check_not_replaying 1
124 check_not_replaying 2
125 }
126 }
127 }
128
129 proc test_cont_all {} {
130 with_test_prefix "cont-all" {
131 gdb_test "continue" "No more reverse-execution history.*"
132
133 # this works because we're lock-stepping threads that executed exactly
134 # the same code starting from the same instruction.
135
136 check_not_replaying 1
137 check_not_replaying 2
138 }
139 }
140
141 proc test_rstep {} {
142 with_test_prefix "reverse-step" {
143 gdb_test "thread apply all record goto 3"
144
145 gdb_test "thread 1" ".*"
146 with_test_prefix "thread 1" {
147 gdb_test "reverse-stepi" ".*"
148
149 check_replay_insn 1 2
150 check_replay_insn 2 3
151 }
152 gdb_test "thread 2" ".*"
153 with_test_prefix "thread 2" {
154 gdb_test "reverse-stepi" ".*"
155
156 check_replay_insn 1 2
157 check_replay_insn 2 2
158 }
159 }
160 }
161
162 proc test_goto_end {} {
163 with_test_prefix "goto-end" {
164 gdb_test "thread apply all record goto end"
165
166 check_not_replaying 1
167 check_not_replaying 2
168 }
169 }
170
171 foreach schedlock { "replay" "on" "step" } {
172 with_test_prefix "schedlock-$schedlock" {
173 gdb_test_no_output "set scheduler-locking $schedlock"
174
175 test_navigate
176 test_step
177 if { $schedlock == "step" } {
178 test_cont_all
179 } else {
180 test_cont
181 }
182 test_rstep
183 test_goto_end
184 }
185 }
186
187 # schedlock-off is difficult to test since we can't really say where the other
188 # thread will be when the resumed thread stops.
189
190 # navigate back into the history for thread 1 and continue thread 2
191 with_test_prefix "cont-to-end" {
192 # this test only works for scheduler-locking replay
193 gdb_test_no_output "set scheduler-locking replay"
194
195 gdb_test "thread 1" ".*"
196 with_test_prefix "thread 1" {
197 gdb_test "record goto begin" ".*"
198
199 check_replay_insn 1 1
200 }
201 gdb_test "thread 2" ".*"
202 with_test_prefix "thread 2" {
203 gdb_test "record goto end" ".*"
204
205 check_not_replaying 2
206
207 # if we reach the breakpoint, thread 2 terminated...
208 gdb_cont_to_line $srcfile:$bp_3
209
210 # and thread 1 stopped replaying
211 check_not_replaying 1
212 }
213 }