1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2016 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 # check for btrace support
21 if { [skip_btrace_tests] } { return -1 }
25 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
28 clean_restart $testfile
35 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
36 set bp_2 [gdb_get_line_number "bp.2" $srcfile]
37 set bp_3 [gdb_get_line_number "bp.3" $srcfile]
39 proc gdb_cont_to_line { line } {
41 gdb_continue_to_breakpoint "cont to $line" ".*$line\r\n.*"
45 proc check_replay_insn { thread insn } {
46 gdb_test "thread apply $thread info record" \
47 "Replay in progress\. At instruction $insn\."
50 proc check_not_replaying { thread } {
53 set test "thread $thread not replaying"
55 gdb_test_multiple "thread apply $thread info record" $test {
56 -re "Replay in progress" {
65 # trace the code between the two breakpoints
67 gdb_cont_to_line $srcfile:$bp_1
68 # make sure GDB knows about the new thread
69 gdb_test "info threads" ".*"
70 gdb_test_no_output "record btrace"
71 gdb_cont_to_line $srcfile:$bp_2
73 proc test_navigate {} {
74 with_test_prefix "navigate" {
75 gdb_test "thread 1" ".*"
76 with_test_prefix "thread 1" {
77 gdb_test "record goto begin" ".*"
82 gdb_test "thread 2" ".*"
83 with_test_prefix "thread 2" {
84 gdb_test "record goto begin" ".*"
93 with_test_prefix "step" {
94 gdb_test "thread 1" ".*"
95 with_test_prefix "thread 1" {
101 gdb_test "thread 2" ".*"
102 with_test_prefix "thread 2" {
103 gdb_test "stepi" ".*"
105 check_replay_insn 1 2
106 check_replay_insn 2 2
112 with_test_prefix "cont" {
113 gdb_test "thread 1" ".*"
114 with_test_prefix "thread 1" {
115 gdb_test "continue" "No more reverse-execution history.*"
117 check_not_replaying 1
118 check_replay_insn 2 2
120 gdb_test "thread 2" ".*"
121 with_test_prefix "thread 2" {
122 gdb_test "continue" "No more reverse-execution history.*"
124 check_not_replaying 1
125 check_not_replaying 2
130 proc test_cont_all {} {
131 with_test_prefix "cont-all" {
132 gdb_test "continue" "No more reverse-execution history.*"
134 # this works because we're lock-stepping threads that executed exactly
135 # the same code starting from the same instruction.
137 check_not_replaying 1
138 check_not_replaying 2
143 with_test_prefix "reverse-step" {
144 gdb_test "thread apply all record goto 3"
146 gdb_test "thread 1" ".*"
147 with_test_prefix "thread 1" {
148 gdb_test "reverse-stepi" ".*"
150 check_replay_insn 1 2
151 check_replay_insn 2 3
153 gdb_test "thread 2" ".*"
154 with_test_prefix "thread 2" {
155 gdb_test "reverse-stepi" ".*"
157 check_replay_insn 1 2
158 check_replay_insn 2 2
163 proc test_goto_end {} {
164 with_test_prefix "goto-end" {
165 gdb_test "thread apply all record goto end"
167 check_not_replaying 1
168 check_not_replaying 2
172 foreach schedlock { "replay" "on" "step" } {
173 with_test_prefix "schedlock-$schedlock" {
174 gdb_test_no_output "set scheduler-locking $schedlock"
178 if { $schedlock == "step" } {
188 # schedlock-off is difficult to test since we can't really say where the other
189 # thread will be when the resumed thread stops.
191 # navigate back into the history for thread 1 and continue thread 2
192 with_test_prefix "cont-to-end" {
193 # this test only works for scheduler-locking replay
194 gdb_test_no_output "set scheduler-locking replay"
196 gdb_test "thread 1" ".*"
197 with_test_prefix "thread 1" {
198 gdb_test "record goto begin" ".*"
200 check_replay_insn 1 1
202 gdb_test "thread 2" ".*"
203 with_test_prefix "thread 2" {
204 gdb_test "record goto end" ".*"
206 check_not_replaying 2
208 # if we reach the breakpoint, thread 2 terminated...
209 gdb_cont_to_line $srcfile:$bp_3
211 # and thread 1 stopped replaying
212 check_not_replaying 1