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