xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/mi-trace-frame-collected.exp (revision 2718af68c3efc72c9769069b5c7f9ed36f6b9def)
1# Copyright 2013-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
16load_lib trace-support.exp
17
18standard_testfile actions.c
19
20if ![gdb_trace_common_supports_arch] {
21    unsupported "no trace-common.h support for arch"
22    return -1
23}
24
25if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug}] } {
26    return -1
27}
28
29if ![runto_main] {
30    fail "can't run to main to check for trace support"
31    return -1
32}
33
34if ![gdb_target_supports_trace] {
35    unsupported "current target does not support trace"
36    return -1
37}
38
39gdb_exit
40
41load_lib mi-support.exp
42set MIFLAGS "-i=mi"
43
44if [mi_gdb_start] {
45    return
46}
47mi_run_to_main
48
49mi_gdb_test "-break-insert end" \
50    "\\^done,bkpt=\{number=\"${decimal}\",type=\"breakpoint\".*\"\}" \
51    "insert tracepoint on end"
52mi_gdb_test "-break-insert -a gdb_recursion_test" \
53    "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \
54    "insert tracepoint on gdb_recursion_test"
55
56mi_gdb_test "-trace-define-variable \$tsv 1" {.*\^done} \
57    "-trace-define-variable"
58
59mi_gdb_test "-break-commands 3 \"collect gdb_char_test\" \"collect gdb_union1_test\" \"collect gdb_struct1_test.l\" \"collect gdb_arr_test\[0\]\" \"collect $${pcreg}\" \"teval \$tsv += 1\" \"collect \$tsv\" \"end\" " \
60    {\^done} "set action"
61
62mi_gdb_test "-break-insert -a gdb_c_test" \
63    "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \
64    "insert tracepoint on gdb_c_test"
65
66# Define an action.
67# Collect a global variable to be sure no registers are collected
68# except PC.
69mi_gdb_test "-break-commands 4 \"collect gdb_char_test\" \"end\" " \
70    {\^done} "set action on tracepoint 4"
71
72mi_gdb_test "-trace-start" {.*\^done} "trace start"
73mi_send_resuming_command "exec-continue" "continuing to end"
74mi_expect_stop \
75    "breakpoint-hit" "end" ".*" ".*" ".*" {"" "disp=\"keep\""} \
76    "stop at end"
77mi_gdb_test "-trace-stop" {.*\^done,stop-reason=.*} "trace stop"
78
79# Save trace frames to tfile.
80set tracefile [standard_output_file ${testfile}]
81mi_gdb_test "-trace-save ${tracefile}.tf" ".*\\^done" \
82    "save tfile trace file"
83# Save trace frames to ctf.
84mi_gdb_test "-trace-save -ctf ${tracefile}.ctf" ".*\\^done" \
85    "save ctf trace file"
86
87# Test the MI command '-trace-frame-collected' with DATA_SOURCE as
88# trace data source.
89
90proc test_trace_frame_collected { data_source } {
91    global decimal hex
92    global mi_gdb_prompt
93
94    with_test_prefix "$data_source" {
95	mi_gdb_test "-trace-find frame-number 0" \
96	    ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
97	    "-trace-find frame-number 0"
98
99	set reg_pattern "\{number=\"$decimal\",value=\"$hex\"\}"
100
101	# Test MI command '-trace-frame-collected' dumps only
102	# collected registers.
103
104	# While the tracepoint has no explicit action that causes
105	# collection of registers other than the PC, some
106	# architectures manage to collect or guess more than that.
107	if { [istarget "s390*-*-*"] } {
108	    # On s390 PC is a pseudo-register - collecting it also
109	    # collects the underlying PSWA register.
110	    if { "$data_source" != "tfile" } {
111		set reg_pattern "$reg_pattern,$reg_pattern"
112	    } else {
113		# For tfile, PSWM and CC are also guessed.
114		set reg_pattern "$reg_pattern,$reg_pattern,$reg_pattern,$reg_pattern"
115	    }
116	} elseif {[is_amd64_regs_target] && [is_ilp32_target]} {
117	    # x32.  While on the 64-bit ABI gdb only exposes 64-bit
118	    # $pc/$rip, on x32, GDB exposes 32-bit $eip as well, as a
119	    # pseudo-register.  Thus, collecting $pc/$rip
120	    # automatically always collects $eip as well.
121	    set reg_pattern "$reg_pattern,$reg_pattern"
122	}
123
124	mi_gdb_test "-trace-frame-collected" \
125	    "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",value=\".*\"\}\\\],computed-expressions=\\\[\\\],registers=\\\[$reg_pattern\\\],tvars=\\\[\\\],memory=\\\[\{address=\"$hex\",length=\"1\"\}\\\]"\
126	    "-trace-frame-collected (register)"
127
128	mi_gdb_test "-trace-find frame-number 1" \
129	    ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"1\",frame=\{.*" \
130	    "-trace-find frame-number 1"
131
132	# Test MI command '-trace-frame-collected'
133	mi_gdb_test "-trace-frame-collected" \
134	    "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",value=\".*\"\},\{name=\"gdb_union1_test\",value=\".*\"\}\\\],computed-expressions=\\\[\{name=\"gdb_struct1_test\.l\",.*\},\{name=\"gdb_arr_test\\\[0\\\]\",.*\}\\\],registers=\\\[.*\\\],tvars=\\\[\{name=\"\\\$tsv\",current=\"2\"\}\\\],memory=\\\[\{address=\"$hex\",length=\"1\"\},.*\\\]"\
135	    "-trace-frame-collected"
136	mi_gdb_test "-trace-frame-collected --var-print-values 2 --comp-print-values --simple-values --registers-format x --memory-contents" \
137	    "\\^done,explicit-variables=\\\[\{name=\"gdb_char_test\",type=\"char\",value=\".*\"\},\{name=\"gdb_union1_test\",type=\"union GDB_UNION_TEST\"\}\\\],computed-expressions=\\\[.*\\\],registers=\\\[.*\\\],tvars=\\\[\{name=\"\\\$tsv\",current=\"2\"\}\\\],memory=\\\[\{address=\"$hex\",length=\"1\",contents=\".*\"\},.*\\\]" \
138	    "-trace-frame-collected --var-print-values 2 --comp-print-values --simple-values --registers-format x --memory-contents"
139
140	mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" \
141	    "-trace-find none"
142    }
143}
144
145test_trace_frame_collected "live"
146
147# Change target to ctf if GDB supports it.
148set msg "-target-select ctf"
149send_gdb "-target-select ctf ${tracefile}.ctf\n"
150gdb_expect {
151    -re ".*\\^connected.*${mi_gdb_prompt}$" {
152	# GDB supports ctf, do the test.
153	test_trace_frame_collected "ctf"
154    }
155    -re ".*\\^error,msg=\"Undefined target command.*${mi_gdb_prompt}$" {
156	# GDB doesn't support ctf, skip the test.
157	unsupported "gdb does not support ctf target"
158    }
159    -re ".*$mi_gdb_prompt$" {
160	fail "$msg"
161    }
162    timeout {
163	fail "$msg (timeout)"
164    }
165}
166
167# Change target to tfile.
168mi_gdb_test "-target-select tfile ${tracefile}.tf" ".*\\^connected.*" \
169    "-target-select tfile"
170test_trace_frame_collected "tfile"
171
172mi_gdb_exit
173