xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.trace/disconnected-tracing.exp (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1#   Copyright 2012-2019 Free Software Foundation, Inc.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Test of disconnected-tracing.
17
18load_lib "trace-support.exp"
19
20standard_testfile
21set executable $testfile
22set expfile $testfile.exp
23set gdbserver_reconnect_p 1
24
25if { [info proc gdb_reconnect] == "" } {
26    unsupported "target does not support reconnect"
27    return -1
28}
29
30if [prepare_for_testing "failed to prepare" $executable $srcfile \
31        {debug nowarnings}] {
32    return -1
33}
34
35if ![runto_main] {
36    fail "can't run to main to check for trace support"
37    return -1
38}
39
40if ![gdb_target_supports_trace] {
41    unsupported "target does not support trace"
42    return -1
43}
44
45# Disconnect in tracing.
46
47proc disconnected_tracing {  } {
48    with_test_prefix "trace" {
49	global executable
50	global decimal
51	global srcfile
52
53	# Start with a fresh gdb.
54	clean_restart ${executable}
55	if ![runto_main] {
56	    fail "can't run to main"
57	    return -1
58	}
59
60	gdb_test_no_output "set confirm off"
61	gdb_test_no_output "set disconnected-tracing on"
62	gdb_test "trace start" ".*"
63	gdb_trace_setactions "collect on tracepoint 2" "2" \
64	    "collect foo" "^$"
65	gdb_breakpoint "end" qualified
66
67	gdb_test_no_output "tstart"
68
69	gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*"
70	gdb_test_no_output "tstop"
71
72	gdb_test "info tracepoints" ".*in start at.*" \
73	    "first info tracepoints"
74
75	gdb_test "disconnect" "Ending remote debugging\\." "first disconnect"
76	if { [gdb_reconnect] == 0 } {
77	    pass "first reconnect after unload"
78	} else {
79	    fail "first reconnect after unload"
80	    return 0
81	}
82	gdb_test "info tracepoints" ".*in start at.*" \
83	    "second info tracepoints"
84
85	delete_breakpoints
86	gdb_test "info tracepoints" ".*No tracepoints..*" \
87	    "third info tracepoints"
88
89	gdb_test "disconnect" "Ending remote debugging\\." "second disconnect"
90	if { [gdb_reconnect] == 0 } {
91	    pass "second reconnect after unload"
92	} else {
93	    fail "second reconnect after unload"
94	    return 0
95	}
96	gdb_test "tstatus"
97	gdb_test "info tracepoints" \
98	    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
99\[0-9\]+\[\t \]+tracepoint     keep y.* in start at .*$srcfile:\[0-9\]+.
100\[\t \]+tracepoint already hit 1 time.
101\[\t \]+trace buffer usage ${decimal} bytes.
102\[\t \]+collect foo.*" \
103	    "fourth info tracepoints"
104    }
105}
106
107disconnected_tracing
108
109# Disconnected in tfind
110
111proc disconnected_tfind {  } {
112    with_test_prefix "tfind" {
113	global executable
114	global decimal
115
116	# Start with a fresh gdb.
117	clean_restart ${executable}
118	if ![runto_main] {
119	    fail "can't run to main"
120	    return -1
121	}
122
123	gdb_test_no_output "set confirm off"
124	gdb_test_no_output "set disconnected-tracing on"
125	gdb_test "trace start" ".*"
126	gdb_test_no_output "tstart"
127
128	gdb_breakpoint "end" qualified
129	gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*"
130	gdb_test_no_output "tstop"
131
132	gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
133	gdb_test "p \$trace_frame" ".*\\\$${decimal} = 0.*" \
134	    "p \$trace_frame before disconnected"
135	gdb_test "p \$tracepoint" ".*\\\$${decimal} = 2.*" \
136	    "p \$tracepoint before disconnected"
137
138	gdb_test "disconnect" "Ending remote debugging\\." "first disconnect"
139
140	gdb_test "p \$trace_frame" ".*\\\$${decimal} = -1.*"
141	gdb_test "p \$tracepoint" ".*\\\$${decimal} = -1.*"
142	gdb_test "p \$trace_line" ".*\\\$${decimal} = -1.*"
143	gdb_test "p \$trace_file" ".*\\\$${decimal} = void.*"
144	gdb_test "p \$trace_func" ".*\\\$${decimal} = void.*"
145    }
146}
147
148disconnected_tfind
149
150# Reconnect for a clean gdbserver shutdown.
151gdb_reconnect
152