1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2017-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 require allow_btrace_tests
21 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
22 untested "failed to prepare"
26 # We need to enable non-stop mode for the remote case.
27 save_vars { GDBFLAGS } {
28 append GDBFLAGS " -ex \"set non-stop on\""
29 clean_restart $testfile
36 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
39 gdb_continue_to_breakpoint "cont to $bp_1" ".*$bp_1\r\n.*"
40 gdb_test "cont&" "Continuing\."
42 # All threads are running. Let's start recording.
43 gdb_test_no_output "record btrace"
45 proc check_tracing_enabled { thread } {
48 with_test_prefix "thread $thread" {
49 gdb_test "thread $thread" "(running).*" "is running"
51 # We can't read the trace while the thread is running.
52 gdb_test "info record" "Selected thread is running\." \
53 "info record while running"
55 # Try various commands that try to read trace.
56 gdb_test "record instruction-history" "Selected thread is running\."
57 gdb_test "record function-call-history" "Selected thread is running\."
59 # Including reverse-stepping commands.
60 gdb_test "reverse-continue" "\[Ss\]elected thread is running\."
61 gdb_test "reverse-step" "\[Ss\]elected thread is running\."
62 gdb_test "reverse-next" "\[Ss\]elected thread is running\."
63 gdb_test "reverse-finish" "\[Ss\]elected thread is running\."
65 # Stop the thread before reading the trace.
66 gdb_test_multiple "interrupt" "interrupt" {
67 -re "interrupt\r\n$gdb_prompt " {
71 # Wait until the thread actually stopped.
72 gdb_test_multiple "" "stopped" {
73 -re "Thread $thread.*stopped\." {
77 # We will consume the thread's current location as part of the
78 # "info record" output.
79 gdb_test "info record" [multi_line \
80 "Active record target: record-btrace" \
81 "Recording format: .*" \
82 "Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*" \
85 # Continue the thread again.
86 gdb_test "cont&" "Continuing\."
90 # Check that recording was started on each thread.
91 foreach thread {1 2 3 4} {
92 check_tracing_enabled $thread
95 # Stop recording while all threads are running.
96 gdb_test "record stop" "Process record is stopped \[^\\\r\\\n\]*"