1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2024 Free Software Foundation, Inc.
5 # Contributed by Intel Corp. <markus.t.metzger@intel.com>
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.
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.
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/>.
20 require allow_btrace_tests
23 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
24 untested "failed to prepare"
27 clean_restart $testfile
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]
38 proc gdb_cont_to_line { line } {
40 gdb_continue_to_breakpoint "cont to $line" ".*$line\r\n.*"
44 proc check_replay_insn { thread insn } {
45 gdb_test "thread apply $thread info record" \
46 "Replay in progress\. At instruction $insn\."
49 proc check_not_replaying { thread } {
52 set test "thread $thread not replaying"
54 gdb_test_multiple "thread apply $thread info record" $test {
55 -re "Replay in progress" {
64 # trace the code between the two 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
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" ".*"
81 gdb_test "thread 2" ".*"
82 with_test_prefix "thread 2" {
83 gdb_test "record goto begin" ".*"
92 with_test_prefix "step" {
93 gdb_test "thread 1" ".*"
94 with_test_prefix "thread 1" {
100 gdb_test "thread 2" ".*"
101 with_test_prefix "thread 2" {
102 gdb_test "stepi" ".*"
104 check_replay_insn 1 2
105 check_replay_insn 2 2
111 with_test_prefix "cont" {
112 gdb_test "thread 1" ".*"
113 with_test_prefix "thread 1" {
114 gdb_test "continue" "Reached end of recorded history.*"
116 check_not_replaying 1
117 check_replay_insn 2 2
119 gdb_test "thread 2" ".*"
120 with_test_prefix "thread 2" {
121 gdb_test "continue" "Reached end of recorded history.*"
123 check_not_replaying 1
124 check_not_replaying 2
129 proc test_cont_all {} {
130 with_test_prefix "cont-all" {
131 gdb_test "continue" "Reached end of recorded history.*"
133 # this works because we're lock-stepping threads that executed exactly
134 # the same code starting from the same instruction.
136 check_not_replaying 1
137 check_not_replaying 2
142 with_test_prefix "reverse-step" {
143 gdb_test "thread apply all record goto 3"
145 gdb_test "thread 1" ".*"
146 with_test_prefix "thread 1" {
147 gdb_test "reverse-stepi" ".*"
149 check_replay_insn 1 2
150 check_replay_insn 2 3
152 gdb_test "thread 2" ".*"
153 with_test_prefix "thread 2" {
154 gdb_test "reverse-stepi" ".*"
156 check_replay_insn 1 2
157 check_replay_insn 2 2
162 proc test_goto_end {} {
163 with_test_prefix "goto-end" {
164 gdb_test "thread apply all record goto end"
166 check_not_replaying 1
167 check_not_replaying 2
171 foreach schedlock { "replay" "on" "step" } {
172 with_test_prefix "schedlock-$schedlock" {
173 gdb_test_no_output "set scheduler-locking $schedlock"
177 if { $schedlock == "step" } {
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.
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"
195 gdb_test "thread 1" ".*"
196 with_test_prefix "thread 1" {
197 gdb_test "record goto begin" ".*"
199 check_replay_insn 1 1
201 gdb_test "thread 2" ".*"
202 with_test_prefix "thread 2" {
203 gdb_test "record goto end" ".*"
205 check_not_replaying 2
207 # if we reach the breakpoint, thread 2 terminated...
208 gdb_cont_to_line $srcfile:$bp_3
210 # and thread 1 stopped replaying
211 check_not_replaying 1