Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright (C) 1998-2015 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | |
17 | # | |
18 | # Support procedures for trace testing | |
19 | # | |
20 | ||
21 | ||
22 | # | |
23 | # Procedure: gdb_target_supports_trace | |
24 | # Returns true if GDB is connected to a target that supports tracing. | |
25 | # Allows tests to abort early if not running on a trace-aware target. | |
26 | # | |
27 | ||
28 | proc gdb_target_supports_trace { } { | |
29 | global gdb_prompt | |
30 | ||
31 | send_gdb "tstatus\n" | |
32 | gdb_expect { | |
33 | -re "\[Tt\]race can only be run on.*$gdb_prompt $" { | |
34 | return 0 | |
35 | } | |
36 | -re "\[Tt\]race can not be run on.*$gdb_prompt $" { | |
37 | return 0 | |
38 | } | |
39 | -re "\[Tt\]arget does not support.*$gdb_prompt $" { | |
40 | return 0 | |
41 | } | |
42 | -re ".*\[Ee\]rror.*$gdb_prompt $" { | |
43 | return 0 | |
44 | } | |
45 | -re ".*\[Ww\]arning.*$gdb_prompt $" { | |
46 | return 0 | |
47 | } | |
48 | -re ".*$gdb_prompt $" { | |
49 | return 1 | |
50 | } | |
51 | timeout { | |
52 | return 0 | |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | ||
58 | # | |
59 | # Procedure: gdb_delete_tracepoints | |
60 | # Many of the tests depend on setting tracepoints at various places and | |
61 | # running until that tracepoint is reached. At times, we want to start | |
62 | # with a clean slate with respect to tracepoints, so this utility proc | |
63 | # lets us do this without duplicating this code everywhere. | |
64 | # | |
65 | ||
66 | proc gdb_delete_tracepoints {} { | |
67 | global gdb_prompt | |
68 | ||
69 | send_gdb "delete tracepoints\n" | |
70 | gdb_expect 30 { | |
71 | -re "Delete all tracepoints.*y or n.*$" { | |
4ec70201 | 72 | send_gdb "y\n" |
c906108c SS |
73 | exp_continue |
74 | } | |
75 | -re ".*$gdb_prompt $" { # This happens if there were no tracepoints } | |
76 | timeout { | |
77 | perror "Delete all tracepoints in delete_tracepoints (timeout)" | |
78 | return | |
79 | } | |
80 | } | |
81 | send_gdb "info tracepoints\n" | |
82 | gdb_expect 30 { | |
83 | -re "No tracepoints.*$gdb_prompt $" {} | |
84 | -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return } | |
85 | timeout { perror "info tracepoints (timeout)" ; return } | |
86 | } | |
87 | } | |
88 | ||
c906108c SS |
89 | # Define actions for a tracepoint. |
90 | # Arguments: | |
c9a6ce02 PA |
91 | # actions_command -- the command used to create the actions. |
92 | # either "actions" or "commands". | |
c906108c | 93 | # testname -- identifying string for pass/fail output |
c9a6ce02 | 94 | # tracepoint -- to which tracepoint(s) do these actions apply? (optional) |
c906108c SS |
95 | # args -- list of actions to be defined. |
96 | # Returns: | |
97 | # zero -- success | |
98 | # non-zero -- failure | |
99 | ||
c9a6ce02 | 100 | proc gdb_trace_setactions_command { actions_command testname tracepoint args } { |
4ec70201 | 101 | global gdb_prompt |
c906108c | 102 | |
4ec70201 PA |
103 | set state 0 |
104 | set passfail "pass" | |
105 | send_gdb "$actions_command $tracepoint\n" | |
106 | set expected_result "" | |
c906108c SS |
107 | gdb_expect 5 { |
108 | -re "No tracepoint number .*$gdb_prompt $" { | |
109 | fail $testname | |
ae59b1da | 110 | return 1 |
c906108c SS |
111 | } |
112 | -re "Enter actions for tracepoint $tracepoint.*>" { | |
113 | if { [llength $args] > 0 } { | |
4ec70201 PA |
114 | set lastcommand "[lindex $args $state]" |
115 | send_gdb "[lindex $args $state]\n" | |
116 | incr state | |
117 | set expected_result [lindex $args $state] | |
118 | incr state | |
c906108c | 119 | } else { |
4ec70201 | 120 | send_gdb "end\n" |
c906108c | 121 | } |
4ec70201 | 122 | exp_continue |
c906108c | 123 | } |
a7bdde9e | 124 | -re "\(.*\)\[\r\n\]+\[ \t]*>$" { |
c906108c | 125 | if { $expected_result != "" } { |
4ec70201 | 126 | regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out |
c906108c | 127 | if ![regexp $expected_result $out] { |
4ec70201 | 128 | set passfail "fail" |
c906108c | 129 | } |
4ec70201 | 130 | set expected_result "" |
c906108c SS |
131 | } |
132 | if { $state < [llength $args] } { | |
4ec70201 PA |
133 | send_gdb "[lindex $args $state]\n" |
134 | incr state | |
135 | set expected_result [lindex $args $state] | |
136 | incr state | |
c906108c | 137 | } else { |
4ec70201 PA |
138 | send_gdb "end\n" |
139 | set expected_result "" | |
c906108c | 140 | } |
4ec70201 | 141 | exp_continue |
c906108c SS |
142 | } |
143 | -re "\(.*\)$gdb_prompt $" { | |
144 | if { $expected_result != "" } { | |
145 | if ![regexp $expected_result $expect_out(1,string)] { | |
4ec70201 | 146 | set passfail "fail" |
c906108c | 147 | } |
4ec70201 | 148 | set expected_result "" |
c906108c SS |
149 | } |
150 | if { [llength $args] < $state } { | |
4ec70201 | 151 | set passfail "fail" |
c906108c SS |
152 | } |
153 | } | |
154 | default { | |
4ec70201 | 155 | set passfail "fail" |
c906108c SS |
156 | } |
157 | } | |
158 | if { $testname != "" } { | |
4ec70201 | 159 | $passfail $testname |
c906108c SS |
160 | } |
161 | if { $passfail == "pass" } then { | |
ae59b1da | 162 | return 0 |
c906108c | 163 | } else { |
ae59b1da | 164 | return 1 |
c906108c SS |
165 | } |
166 | } | |
167 | ||
c9a6ce02 PA |
168 | # Define actions for a tracepoint, using the "actions" command. See |
169 | # gdb_trace_setactions_command. | |
170 | # | |
171 | proc gdb_trace_setactions { testname tracepoint args } { | |
172 | eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args | |
173 | } | |
174 | ||
175 | # Define actions for a tracepoint, using the "commands" command. See | |
176 | # gdb_trace_setactions_command. | |
177 | # | |
178 | proc gdb_trace_setcommands { testname tracepoint args } { | |
179 | eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args | |
180 | } | |
181 | ||
c906108c SS |
182 | # |
183 | # Procedure: gdb_tfind_test | |
184 | # Find a specified trace frame. | |
185 | # Arguments: | |
186 | # testname -- identifying string for pass/fail output | |
187 | # tfind_arg -- frame (line, PC, etc.) identifier | |
188 | # exp_res -- Expected result of frame test | |
189 | # args -- Test expression | |
190 | # Returns: | |
191 | # zero -- success | |
192 | # non-zero -- failure | |
193 | # | |
194 | ||
195 | proc gdb_tfind_test { testname tfind_arg exp_res args } { | |
4ec70201 | 196 | global gdb_prompt |
c906108c SS |
197 | |
198 | if { "$args" != "" } { | |
4ec70201 PA |
199 | set expr "$exp_res" |
200 | set exp_res "$args" | |
c906108c | 201 | } else { |
4ec70201 | 202 | set expr "(int) \$trace_frame" |
c906108c | 203 | } |
4ec70201 | 204 | set passfail "fail" |
c906108c SS |
205 | |
206 | gdb_test "tfind $tfind_arg" "" "" | |
4ec70201 | 207 | send_gdb "printf \"x \%d x\\n\", $expr\n" |
c906108c SS |
208 | gdb_expect 10 { |
209 | -re "x (-*\[0-9\]+) x" { | |
210 | if { $expect_out(1,string) == $exp_res } { | |
4ec70201 | 211 | set passfail "pass" |
c906108c | 212 | } |
4ec70201 | 213 | exp_continue |
c906108c SS |
214 | } |
215 | -re "$gdb_prompt $" { } | |
216 | } | |
4ec70201 | 217 | $passfail "$testname" |
c906108c | 218 | if { $passfail == "pass" } then { |
ae59b1da | 219 | return 0 |
c906108c | 220 | } else { |
ae59b1da | 221 | return 1 |
c906108c SS |
222 | } |
223 | } | |
224 | ||
225 | # | |
226 | # Procedure: gdb_readexpr | |
227 | # Arguments: | |
228 | # gdb_expr -- the expression whose value is desired | |
229 | # Returns: | |
230 | # the value of gdb_expr, as evaluated by gdb. | |
231 | # [FIXME: returns -1 on error, which is sometimes a legit value] | |
232 | # | |
233 | ||
234 | proc gdb_readexpr { gdb_expr } { | |
4ec70201 | 235 | global gdb_prompt |
c906108c | 236 | |
4ec70201 | 237 | set result -1 |
c906108c SS |
238 | send_gdb "print $gdb_expr\n" |
239 | gdb_expect 5 { | |
240 | -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" { | |
4ec70201 | 241 | set result $expect_out(1,string) |
c906108c SS |
242 | } |
243 | -re "$gdb_prompt $" { } | |
244 | default { } | |
245 | } | |
ae59b1da | 246 | return $result |
c906108c SS |
247 | } |
248 | ||
249 | # | |
250 | # Procedure: gdb_gettpnum | |
251 | # Arguments: | |
252 | # tracepoint (optional): if supplied, set a tracepoint here. | |
253 | # Returns: | |
254 | # the tracepoint ID of the most recently set tracepoint. | |
255 | # | |
256 | ||
257 | proc gdb_gettpnum { tracepoint } { | |
4ec70201 | 258 | global gdb_prompt |
c906108c SS |
259 | |
260 | if { $tracepoint != "" } { | |
261 | gdb_test "trace $tracepoint" "" "" | |
262 | } | |
ae59b1da | 263 | return [gdb_readexpr "\$tpnum"] |
c906108c SS |
264 | } |
265 | ||
266 | ||
267 | # | |
268 | # Procedure: gdb_find_function_baseline | |
269 | # Arguments: | |
270 | # func_name -- name of source function | |
271 | # Returns: | |
272 | # Sourcefile line of function definition (open curly brace), | |
273 | # or -1 on failure. Caller must check return value. | |
274 | # Note: | |
275 | # Works only for open curly brace at beginning of source line! | |
276 | # | |
277 | ||
278 | proc gdb_find_function_baseline { func_name } { | |
4ec70201 | 279 | global gdb_prompt |
c906108c | 280 | |
4ec70201 | 281 | set baseline -1 |
c906108c SS |
282 | |
283 | send_gdb "list $func_name\n" | |
284 | # gdb_expect { | |
285 | # -re "\[\r\n\]\[\{\].*$gdb_prompt $" { | |
286 | # set baseline 1 | |
287 | # } | |
288 | # } | |
289 | } | |
290 | ||
291 | # | |
292 | # Procedure: gdb_find_function_baseline | |
293 | # Arguments: | |
294 | # filename: name of source file of desired function. | |
295 | # Returns: | |
296 | # Sourcefile line of function definition (open curly brace), | |
297 | # or -1 on failure. Caller must check return value. | |
298 | # Note: | |
299 | # Works only for open curly brace at beginning of source line! | |
300 | # | |
301 | ||
302 | proc gdb_find_recursion_test_baseline { filename } { | |
4ec70201 | 303 | global gdb_prompt |
c906108c | 304 | |
4ec70201 | 305 | set baseline -1 |
c906108c SS |
306 | |
307 | gdb_test "list $filename:1" "" "" | |
308 | send_gdb "search gdb_recursion_test line 0\n" | |
309 | gdb_expect { | |
310 | -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" { | |
4ec70201 | 311 | set baseline $expect_out(1,string) |
c906108c SS |
312 | } |
313 | -re "$gdb_prompt $" { } | |
314 | default { } | |
315 | } | |
ae59b1da | 316 | return $baseline |
c906108c | 317 | } |
c0d4d1c0 YQ |
318 | |
319 | # Return the location of the IPA library. | |
320 | ||
321 | proc get_in_proc_agent {} { | |
322 | global objdir | |
323 | ||
324 | if [target_info exists in_proc_agent] { | |
325 | return [target_info in_proc_agent] | |
326 | } else { | |
327 | return $objdir/../gdbserver/libinproctrace.so | |
328 | } | |
329 | } | |
b4429ea2 YQ |
330 | |
331 | # Execute BINFILE on target to generate tracefile. Return 1 if | |
332 | # tracefile is generated successfully, return 0 otherwise. | |
333 | ||
334 | proc generate_tracefile { binfile } { | |
335 | set status [remote_exec target "$binfile"] | |
336 | ||
337 | if { [lindex $status 0] != 0 } { | |
338 | # Failed to execute $binfile, for example on bare metal targets. | |
339 | # Alternatively, load the binary and run it. If target doesn't | |
340 | # have fileio capabilities, tracefile can't be generated. Skip | |
341 | # the test. | |
342 | if [target_info exists gdb,nofileio] { | |
343 | return 0 | |
344 | } | |
345 | ||
346 | clean_restart $binfile | |
347 | ||
348 | if ![runto_main] then { | |
349 | return 0 | |
350 | } | |
351 | gdb_continue_to_end "" continue 1 | |
352 | gdb_exit | |
353 | } | |
354 | ||
355 | return 1 | |
356 | } |