xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.btrace/enable-running.exp (revision 924795e69c8bb3f17afd8fcbb799710cc1719dc4)
1# This testcase is part of GDB, the GNU debugger.
2#
3# Copyright 2017-2020 Free Software Foundation, Inc.
4#
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.
9#
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.
14#
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/>.
17
18if { [skip_btrace_tests] } {
19    unsupported "target does not support record-btrace"
20    return -1
21}
22
23standard_testfile
24if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
25    untested "failed to prepare"
26    return -1
27}
28
29# We need to enable non-stop mode for the remote case.
30save_vars { GDBFLAGS } {
31    append GDBFLAGS " -ex \"set non-stop on\""
32    clean_restart $testfile
33}
34
35if ![runto_main] {
36    untested "failed to run to main"
37    return -1
38}
39
40set bp_1 [gdb_get_line_number "bp.1" $srcfile]
41
42gdb_breakpoint $bp_1
43gdb_continue_to_breakpoint "cont to $bp_1" ".*$bp_1\r\n.*"
44gdb_test "cont&" "Continuing\."
45
46# All threads are running.  Let's start recording.
47gdb_test_no_output "record btrace"
48
49proc check_tracing_enabled { thread } {
50    global gdb_prompt
51
52    with_test_prefix "thread $thread" {
53        gdb_test "thread $thread" "(running).*" "is running"
54
55        # We can't read the trace while the thread is running.
56        gdb_test "info record" "Selected thread is running\." \
57            "info record while running"
58
59        # Try various commands that try to read trace.
60        gdb_test "record instruction-history" "Selected thread is running\."
61        gdb_test "record function-call-history" "Selected thread is running\."
62
63        # Including reverse-stepping commands.
64        gdb_test "reverse-continue" "\[Ss\]elected thread is running\."
65        gdb_test "reverse-step" "\[Ss\]elected thread is running\."
66        gdb_test "reverse-next" "\[Ss\]elected thread is running\."
67        gdb_test "reverse-finish" "\[Ss\]elected thread is running\."
68
69        # Stop the thread before reading the trace.
70        gdb_test_multiple "interrupt" "interrupt" {
71            -re "interrupt\r\n$gdb_prompt " {
72                pass "interrupt"
73            }
74        }
75        # Wait until the thread actually stopped.
76        gdb_test_multiple "" "stopped" {
77            -re "Thread $thread.*stopped\." {
78                pass "stopped"
79            }
80        }
81        # We will consume the thread's current location as part of the
82        # "info record" output.
83        gdb_test "info record" [multi_line \
84            "Active record target: record-btrace" \
85            "Recording format: .*" \
86            "Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*" \
87        ]
88
89        # Continue the thread again.
90        gdb_test "cont&" "Continuing\."
91    }
92}
93
94# Check that recording was started on each thread.
95foreach thread {1 2 3 4} {
96    check_tracing_enabled $thread
97}
98
99# Stop recording while all threads are running.
100gdb_test "record stop" "Process record is stopped \[^\\\r\\\n\]*"
101