xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.btrace/reconnect.exp (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1# This testcase is part of GDB, the GNU debugger.
2#
3# Copyright 2016-2023 Free Software Foundation, Inc.
4#
5# Contributed by Intel Corp. <tim.wiederhake@intel.com>
6#
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.
11#
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.
16#
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/>.
19
20load_lib gdbserver-support.exp
21
22if { [skip_btrace_tests] } {
23    unsupported "target does not support record-btrace"
24    return -1
25}
26if { [skip_gdbserver_tests] } {
27    unsupported "target does not support gdbserver"
28    return -1
29}
30
31standard_testfile
32if [prepare_for_testing "failed to prepare" $testfile $srcfile] {
33    return -1
34}
35
36# Make sure we're disconnected and no recording is active, in case
37# we're testing with an extended-remote board, therefore already
38# connected.
39with_test_prefix "preparation" {
40  gdb_test "record stop" ".*"
41  gdb_test "disconnect" ".*"
42}
43
44# Start fresh gdbserver.
45set gdbserver_reconnect_p 1
46set res [gdbserver_start "" $binfile]
47set gdbserver_protocol [lindex $res 0]
48set gdbserver_gdbport [lindex $res 1]
49gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
50
51# Create a record, check, reconnect
52with_test_prefix "first" {
53  gdb_test_no_output "record btrace" "record btrace enable"
54  gdb_test "stepi 19" ".*"
55
56  gdb_test "info record" [multi_line \
57    "Active record target: .*" \
58    "Recorded 19 instructions in .+ functions \\(. gaps\\) for thread 1 \\(Thread .*\\)."
59  ]
60
61  gdb_test "disconnect" "Ending remote debugging."
62  gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
63}
64
65# Test if we can access the recorded data from first connect.
66# Note: BTS loses the first function call entry with its associated
67# instructions for technical reasons.  This is why we test for
68# "a number between 10 and 19", so we catch at least the case where
69# there are 0 instructions in the record.
70with_test_prefix "second" {
71  gdb_test "info record" [multi_line \
72    "Active record target: .*" \
73    "Recorded 1. instructions in .+ functions \\(. gaps\\) for thread 1 \\(Thread .*\\)."
74  ]
75
76  gdb_test "record stop" "Process record is stopped and all execution logs are deleted."
77
78  gdb_test "disconnect" "Ending remote debugging."
79  gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
80}
81
82# Test that recording is now off.
83with_test_prefix "third" {
84  gdb_test "info record" "No recording is currently active."
85}
86