Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / multi-thread-step.exp
blobcd20e8ad9f02b344afdab6e64253a91d75aadb88
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
22 standard_testfile
23 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
24     untested "failed to prepare"
25     return -1
27 clean_restart $testfile
29 if ![runto_main] {
30     return -1
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]
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
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 } {
50     global gdb_prompt
52     set test "thread $thread not replaying"
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     }
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
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" ".*"
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" ".*"
85             check_replay_insn 1 1
86             check_replay_insn 2 1
87         }
88     }
91 proc test_step {} {
92     with_test_prefix "step" {
93         gdb_test "thread 1" ".*"
94         with_test_prefix "thread 1" {
95             gdb_test "stepi" ".*"
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" ".*"
104             check_replay_insn 1 2
105             check_replay_insn 2 2
106         }
107     }
110 proc test_cont {} {
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
118         }
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
125         }
126     }
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
138     }
141 proc test_rstep {} {
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
151         }
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
158         }
159     }
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
168     }
171 foreach schedlock { "replay" "on" "step" } {
172     with_test_prefix "schedlock-$schedlock" {
173         gdb_test_no_output "set scheduler-locking $schedlock"
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     }
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
200     }
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
212     }