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