Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1998-2020 Free Software Foundation, Inc. |
06d72e16 PA |
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 | ||
497a5eb0 | 18 | standard_testfile unavailable.cc |
06d72e16 | 19 | set executable $testfile |
06d72e16 | 20 | |
5b362f04 | 21 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ |
ba22ff86 | 22 | {debug nowarnings c++ nopie}]} { |
06d72e16 PA |
23 | return -1 |
24 | } | |
25 | ||
26 | set ws "\[\r\n\t \]+" | |
27 | set cr "\[\r\n\]+" | |
28 | ||
29 | # | |
30 | # Utility procs | |
31 | # | |
32 | ||
0fdb4f18 PA |
33 | proc test_register { reg } { |
34 | global gdb_prompt | |
35 | global hex | |
36 | global cr | |
37 | ||
38 | gdb_test_multiple "print /x $reg" "collected $reg" { | |
39 | -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" { | |
40 | fail "collected $reg (zero)" | |
41 | } | |
42 | -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" { | |
43 | pass "collected $reg" | |
44 | } | |
45 | -re "\[Ee\]rror.*$gdb_prompt $" { | |
46 | fail "collected $reg (error)" | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | proc test_register_unavailable { reg } { | |
52 | gdb_test "print /x $reg" \ | |
53 | "<unavailable>" \ | |
54 | "correctly report $reg as unavailable" | |
55 | } | |
56 | ||
06d72e16 PA |
57 | proc prepare_for_trace_test {} { |
58 | global executable | |
59 | ||
60 | clean_restart $executable | |
61 | ||
62 | runto_main | |
63 | ||
194ed413 AA |
64 | gdb_breakpoint "begin" qualified |
65 | gdb_breakpoint "end" qualified | |
06d72e16 PA |
66 | } |
67 | ||
68 | proc run_trace_experiment { test_func } { | |
69 | global gdb_prompt | |
70 | ||
71 | gdb_test "continue" \ | |
72 | ".*Breakpoint \[0-9\]+, begin .*" \ | |
73 | "advance to begin" | |
74 | ||
75 | gdb_test_no_output "tstart" "start trace experiment" | |
76 | ||
77 | gdb_test "continue" \ | |
78 | "Continuing.*Breakpoint \[0-9\]+, end.*" \ | |
79 | "run trace experiment" | |
80 | gdb_test "tstop" \ | |
81 | "\[\r\n\]+" \ | |
82 | "stop trace experiment" | |
83 | gdb_test "tfind start" \ | |
84 | "#0 $test_func .*" \ | |
85 | "tfind test frame" | |
86 | } | |
87 | ||
af6e93b2 PA |
88 | # Test that "display VAR" works as expected, assuming VAR is wholly |
89 | # unavailable. | |
90 | ||
91 | proc test_maybe_regvar_display { var } { | |
92 | global gdb_prompt | |
93 | ||
94 | # Evaluating VAR's location description may throw an internal | |
95 | # "unavailable" exception, if for example, the value of a register | |
96 | # necessary for computing VAR's location is unavailable. Such an | |
97 | # exception is caught, and should not cause automatic disablement | |
98 | # of the current display being printed. (GDB used to disable the | |
99 | # current display whenever any exception was thrown.) | |
100 | set test "display $var" | |
101 | gdb_test_multiple "$test" "$test" { | |
102 | -re "Disabling display ? to avoid infinite recursion.*$gdb_prompt $" { | |
103 | fail "$test" | |
104 | } | |
105 | -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" { | |
106 | pass "$test" | |
107 | } | |
108 | } | |
109 | gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled" | |
110 | ||
111 | gdb_test "undisp" \ | |
112 | "" \ | |
113 | "delete $var display" \ | |
114 | ".*Delete all auto-display expressions.*y or n. $" \ | |
115 | "y" | |
116 | } | |
117 | ||
06d72e16 PA |
118 | # |
119 | # Test procs | |
120 | # | |
121 | ||
b5262cd0 YQ |
122 | proc gdb_collect_args_test_1 {} { |
123 | global cr | |
8661b11b | 124 | |
b5262cd0 YQ |
125 | # Test printing the variables, and also their addresses. We |
126 | # haven't collected any stack, so there's no way GDB can figure | |
127 | # out the latter. | |
8661b11b | 128 | |
b5262cd0 YQ |
129 | gdb_test "print argc" " = <unavailable>" |
130 | gdb_test "print &argc" \ | |
131 | "Can't take address of \"argc\" which isn't an lvalue\." | |
8661b11b | 132 | |
b5262cd0 YQ |
133 | gdb_test "print argi" " = <unavailable>" |
134 | gdb_test "print &argi" \ | |
135 | "Can't take address of \"argi\" which isn't an lvalue\." | |
8661b11b | 136 | |
b5262cd0 YQ |
137 | gdb_test "print argf" " = <unavailable>" |
138 | gdb_test "print &argf" \ | |
139 | "Can't take address of \"argf\" which isn't an lvalue\." | |
8661b11b | 140 | |
b5262cd0 YQ |
141 | gdb_test "print argd" " = <unavailable>" |
142 | gdb_test "print &argd" \ | |
143 | "Can't take address of \"argd\" which isn't an lvalue\." | |
8661b11b | 144 | |
b5262cd0 | 145 | # struct arg as one of several args (near end of list) |
8661b11b | 146 | |
b5262cd0 | 147 | gdb_test "print argstruct" " = <unavailable>" |
8661b11b | 148 | |
b5262cd0 YQ |
149 | gdb_test "print argstruct.memberc" " = <unavailable>" |
150 | gdb_test "print argstruct.memberi" " = <unavailable>" | |
151 | gdb_test "print argstruct.memberf" " = <unavailable>" | |
152 | gdb_test "print argstruct.memberd" " = <unavailable>" | |
8661b11b | 153 | |
b5262cd0 | 154 | gdb_test "print argarray" " = <unavailable>" |
8661b11b | 155 | |
b5262cd0 YQ |
156 | gdb_test "print &argarray" \ |
157 | "Can't take address of \"argarray\" which isn't an lvalue\." | |
8661b11b | 158 | |
b5262cd0 | 159 | gdb_test "print argarray\[0\]" "value is not available" |
8661b11b | 160 | |
b5262cd0 YQ |
161 | # Test "info args" |
162 | set r "" | |
163 | set r "${r}argc = <unavailable>${cr}" | |
164 | set r "${r}argi = <unavailable>${cr}" | |
165 | set r "${r}argf = <unavailable>${cr}" | |
166 | set r "${r}argd = <unavailable>${cr}" | |
167 | set r "${r}argstruct = <unavailable>${cr}" | |
168 | set r "${r}argarray = <unavailable>${cr}" | |
169 | gdb_test "info args" "$r" "info args" | |
8661b11b | 170 | |
b5262cd0 YQ |
171 | test_maybe_regvar_display "argc" |
172 | } | |
8661b11b | 173 | |
b5262cd0 YQ |
174 | proc gdb_collect_args_test {} { |
175 | with_test_prefix "unavailable arguments" { | |
176 | global gdb_prompt | |
290a839c YQ |
177 | global testfile srcdir subdir binfile |
178 | global trace_file_targets | |
8661b11b | 179 | |
b5262cd0 | 180 | prepare_for_trace_test |
8661b11b | 181 | |
b5262cd0 YQ |
182 | gdb_test "trace args_test_func" \ |
183 | "Tracepoint \[0-9\]+ at .*" \ | |
184 | "set tracepoint" | |
185 | ||
186 | # Begin the test. | |
187 | run_trace_experiment args_test_func | |
188 | ||
189 | gdb_collect_args_test_1 | |
af6e93b2 | 190 | |
0a251e08 YQ |
191 | gdb_test "tfind none" \ |
192 | "#0 end .*" \ | |
193 | "cease trace debugging" | |
290a839c YQ |
194 | |
195 | set tracefile [standard_output_file ${testfile}] | |
196 | gdb_test "tsave ${tracefile}.args.tfile" \ | |
197 | "Trace data saved to file '${tracefile}.args.tfile'\.\\r" \ | |
198 | "tsave ${testfile}.args.tfile" | |
199 | gdb_test "tsave -ctf ${tracefile}.args.ctf" \ | |
200 | "Trace data saved to directory '${tracefile}.args.ctf'\.\\r" \ | |
201 | "save ctf trace file" | |
202 | ||
203 | foreach target_name ${trace_file_targets} { | |
204 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
205 | gdb_exit | |
206 | gdb_start | |
207 | gdb_reinitialize_dir $srcdir/$subdir | |
208 | gdb_file_cmd $binfile | |
209 | gdb_test "target ${target_name} ${tracefile}.args.${target_name}" ".*" \ | |
210 | "change to ${target_name} target" | |
211 | ||
212 | with_test_prefix "${target_name}" { | |
213 | gdb_test "tfind start" "#0 args_test_func .*" \ | |
214 | "tfind test frame" | |
215 | gdb_collect_args_test_1 | |
216 | } | |
217 | } | |
0a251e08 YQ |
218 | } |
219 | } | |
8661b11b | 220 | |
b5262cd0 YQ |
221 | proc gdb_collect_locals_test_1 { func } { |
222 | global cr | |
223 | ||
224 | gdb_test "print locc" " = <unavailable>" | |
225 | gdb_test "print loci" " = <unavailable>" | |
226 | gdb_test "print locf" " = <unavailable>" | |
227 | gdb_test "print locd" " = <unavailable>" | |
228 | ||
229 | gdb_test "print locst.memberc" " = <unavailable>" | |
230 | gdb_test "print locst.memberi" " = <unavailable>" | |
231 | gdb_test "print locst.memberf" " = <unavailable>" | |
232 | gdb_test "print locst.memberd" " = <unavailable>" | |
233 | ||
234 | gdb_test "print locar\[0\]" " = <unavailable>" | |
235 | gdb_test "print locar\[1\]" " = <unavailable>" | |
236 | gdb_test "print locar\[2\]" " = <unavailable>" | |
237 | gdb_test "print locar\[3\]" " = <unavailable>" | |
238 | ||
239 | # Test "info locals" | |
240 | set r "" | |
241 | set r "${r}locf = <unavailable>${cr}" | |
242 | set r "${r}locd = <unavailable>${cr}" | |
243 | set r "${r}locst = <unavailable>${cr}" | |
244 | set r "${r}locar = <unavailable>${cr}" | |
245 | set r "${r}i = <unavailable>${cr}" | |
246 | if { $func == "local_test_func" } { | |
247 | set r "${r}locdefst = <unavailable>${cr}" | |
248 | } | |
249 | set r "${r}locc = <unavailable>${cr}" | |
250 | set r "${r}loci = <unavailable>${cr}" | |
251 | gdb_test "info locals" "$r" "info locals" | |
252 | ||
253 | test_maybe_regvar_display "loci" | |
254 | } | |
255 | ||
0a251e08 YQ |
256 | proc gdb_collect_locals_test { func msg } { |
257 | with_test_prefix "unavailable locals: $msg" { | |
0a251e08 | 258 | global gdb_prompt |
290a839c YQ |
259 | global testfile srcdir subdir binfile |
260 | global trace_file_targets | |
8661b11b | 261 | |
0a251e08 | 262 | prepare_for_trace_test |
8661b11b | 263 | |
0a251e08 | 264 | set testline [gdb_get_line_number "set $func tracepoint here"] |
8661b11b | 265 | |
0a251e08 | 266 | gdb_test "trace $testline" \ |
8661b11b PA |
267 | "Tracepoint \[0-9\]+ at .*" \ |
268 | "set tracepoint" | |
269 | ||
0a251e08 YQ |
270 | # Begin the test. |
271 | run_trace_experiment $func | |
272 | ||
b5262cd0 | 273 | gdb_collect_locals_test_1 $func |
af6e93b2 | 274 | |
0a251e08 YQ |
275 | gdb_test "tfind none" \ |
276 | "#0 end .*" \ | |
277 | "cease trace debugging" | |
290a839c YQ |
278 | |
279 | set tracefile [standard_output_file ${testfile}] | |
280 | gdb_test "tsave ${tracefile}.locals.tfile" \ | |
281 | "Trace data saved to file '${tracefile}.locals.tfile'\.\\r" \ | |
282 | "tsave ${testfile}.locals.tfile" | |
283 | gdb_test "tsave -ctf ${tracefile}.locals.ctf" \ | |
284 | "Trace data saved to directory '${tracefile}.locals.ctf'\.\\r" \ | |
285 | "save ctf trace file" | |
286 | ||
287 | foreach target_name ${trace_file_targets} { | |
288 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
289 | gdb_exit | |
290 | gdb_start | |
291 | gdb_reinitialize_dir $srcdir/$subdir | |
292 | gdb_file_cmd $binfile | |
293 | gdb_test "target ${target_name} ${tracefile}.locals.${target_name}" ".*" \ | |
294 | "change to ${target_name} target" | |
295 | ||
296 | with_test_prefix "${target_name}" { | |
297 | gdb_test "tfind start" "#0 $func .*" \ | |
298 | "tfind test frame" | |
299 | gdb_collect_locals_test_1 $func | |
300 | } | |
301 | } | |
0a251e08 YQ |
302 | } |
303 | } | |
8661b11b | 304 | |
b5262cd0 YQ |
305 | proc gdb_unavailable_registers_test_1 { } { |
306 | global spreg | |
307 | global pcreg | |
308 | ||
309 | # On some archs, the $sp/$pc are a real raw registers. On others, | |
310 | # like x86, they're user registers. Test both variants. | |
311 | test_register_unavailable "\$$spreg" | |
312 | test_register_unavailable "\$sp" | |
313 | ||
314 | # Test reading uncollected pseudo-registers. The set of which | |
315 | # depends on target. | |
316 | if [is_amd64_regs_target] { | |
317 | # Check the raw register first. | |
318 | test_register_unavailable "\$rax" | |
319 | test_register_unavailable "\$eax" | |
320 | test_register_unavailable "\$ax" | |
321 | } elseif [is_x86_like_target] { | |
322 | # Check the raw register first. | |
323 | test_register_unavailable "\$eax" | |
324 | test_register_unavailable "\$ax" | |
325 | } | |
326 | ||
327 | # GDBserver always provides the PC value of regular tracepoint | |
328 | # hits, since it's the same as the tracepoint's address. | |
329 | test_register "\$$pcreg" | |
330 | test_register "\$pc" | |
331 | ||
332 | gdb_test "info registers" \ | |
4000e47e | 333 | ".*<unavailable>.*<unavailable>.*" \ |
b5262cd0 YQ |
334 | "info registers, multiple registers not available" |
335 | ||
336 | gdb_test "info registers \$$spreg" \ | |
337 | "<unavailable>" \ | |
338 | "info registers \$$spreg reports not available" | |
339 | } | |
340 | ||
0a251e08 YQ |
341 | proc gdb_unavailable_registers_test { } { |
342 | with_test_prefix "unavailable registers" { | |
290a839c YQ |
343 | global testfile srcdir subdir binfile |
344 | global trace_file_targets | |
0fdb4f18 | 345 | |
0a251e08 | 346 | prepare_for_trace_test |
0fdb4f18 | 347 | |
0a251e08 YQ |
348 | # We'll simply re-use the globals_test_function for this test |
349 | gdb_test "trace globals_test_func" \ | |
0fdb4f18 PA |
350 | "Tracepoint \[0-9\]+ at .*" \ |
351 | "set tracepoint" | |
352 | ||
0a251e08 YQ |
353 | # Collect nothing. |
354 | ||
355 | # Begin the test. | |
356 | run_trace_experiment globals_test_func | |
0fdb4f18 | 357 | |
b5262cd0 | 358 | gdb_unavailable_registers_test_1 |
0a251e08 YQ |
359 | |
360 | gdb_test "tfind none" "#0 end .*" "cease trace debugging" | |
290a839c YQ |
361 | |
362 | set tracefile [standard_output_file ${testfile}] | |
363 | gdb_test "tsave ${tracefile}.registers.tfile" \ | |
364 | "Trace data saved to file '${tracefile}.registers.tfile'\.\\r" \ | |
365 | "tsave ${testfile}.registers.tfile" | |
366 | gdb_test "tsave -ctf ${tracefile}.registers.ctf" \ | |
367 | "Trace data saved to directory '${tracefile}.registers.ctf'\.\\r" \ | |
368 | "save ctf trace file" | |
369 | ||
370 | foreach target_name ${trace_file_targets} { | |
371 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
372 | gdb_exit | |
373 | gdb_start | |
374 | gdb_reinitialize_dir $srcdir/$subdir | |
375 | gdb_file_cmd $binfile | |
376 | gdb_test "target ${target_name} ${tracefile}.registers.${target_name}" ".*" \ | |
377 | "change to ${target_name} target" | |
378 | ||
379 | with_test_prefix "${target_name}" { | |
380 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
381 | "tfind test frame" | |
382 | gdb_unavailable_registers_test_1 | |
383 | } | |
384 | } | |
0a251e08 YQ |
385 | } |
386 | } | |
0fdb4f18 | 387 | |
b5262cd0 | 388 | proc gdb_unavailable_floats_1 { } { |
ad5f7d6e PA |
389 | global gdb_prompt |
390 | ||
b5262cd0 YQ |
391 | # Necessarily target specific. |
392 | if {[istarget "x86_64-*-*"] || [istarget i?86-*]} { | |
393 | send_gdb "info float\n" | |
394 | gdb_expect_list "info float" ".*$gdb_prompt $" { | |
395 | "Status Word: <unavailable>" | |
396 | "Control Word: <unavailable>" | |
397 | "Tag Word: <unavailable>" | |
398 | "Instruction Pointer: <unavailable>:<unavailable>" | |
399 | "Operand Pointer: <unavailable>:<unavailable>" | |
400 | "Opcode: <unavailable>" | |
401 | } | |
402 | } | |
403 | } | |
404 | ||
405 | proc gdb_unavailable_floats { } { | |
ad5f7d6e | 406 | with_test_prefix "unavailable floats" { |
290a839c YQ |
407 | global testfile srcdir subdir binfile |
408 | global trace_file_targets | |
409 | ||
ad5f7d6e PA |
410 | prepare_for_trace_test |
411 | ||
412 | # We'll simply re-use the globals_test_function for this test | |
413 | gdb_test "trace globals_test_func" \ | |
414 | "Tracepoint \[0-9\]+ at .*" \ | |
415 | "set tracepoint" | |
416 | ||
417 | # Collect nothing. | |
418 | ||
419 | # Begin the test. | |
420 | run_trace_experiment globals_test_func | |
421 | ||
b5262cd0 | 422 | gdb_unavailable_floats_1 |
ad5f7d6e PA |
423 | |
424 | gdb_test "tfind none" "#0 end .*" "cease trace debugging" | |
290a839c YQ |
425 | |
426 | set tracefile [standard_output_file ${testfile}] | |
427 | gdb_test "tsave ${tracefile}.floats.tfile" \ | |
428 | "Trace data saved to file '${tracefile}.floats.tfile'\.\\r" \ | |
429 | "tsave ${testfile}.floats.tfile" | |
430 | gdb_test "tsave -ctf ${tracefile}.floats.ctf" \ | |
431 | "Trace data saved to directory '${tracefile}.floats.ctf'\.\\r" \ | |
432 | "save ctf trace file" | |
433 | ||
434 | foreach target_name ${trace_file_targets} { | |
435 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
436 | gdb_exit | |
437 | gdb_start | |
438 | gdb_reinitialize_dir $srcdir/$subdir | |
439 | gdb_file_cmd $binfile | |
440 | gdb_test "target ${target_name} ${tracefile}.floats.${target_name}" ".*" \ | |
441 | "change to ${target_name} target" | |
442 | ||
443 | with_test_prefix "${target_name}" { | |
444 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
445 | "tfind test frame" | |
446 | gdb_unavailable_floats_1 | |
447 | } | |
448 | } | |
ad5f7d6e PA |
449 | } |
450 | } | |
451 | ||
b5262cd0 YQ |
452 | proc gdb_collect_globals_test_1 { } { |
453 | global ws | |
454 | global cr | |
455 | global gdb_prompt | |
456 | global hex | |
06d72e16 | 457 | |
b5262cd0 YQ |
458 | gdb_test "print globalc" " = <unavailable>" |
459 | gdb_test "print globali" " = <unavailable>" | |
460 | gdb_test "print globalf" " = <unavailable>" | |
461 | gdb_test "print globald" " = <unavailable>" | |
06d72e16 | 462 | |
b5262cd0 YQ |
463 | gdb_test "print globalstruct.memberc" " = <unavailable>" |
464 | gdb_test "print globalstruct.memberi" " = <unavailable>" | |
465 | gdb_test "print globalstruct.memberf" " = <unavailable>" | |
466 | gdb_test "print globalstruct.memberd" " = <unavailable>" | |
06d72e16 | 467 | |
b5262cd0 | 468 | gdb_test "print globalstruct" " = <unavailable>" |
06d72e16 | 469 | |
b5262cd0 YQ |
470 | gdb_test "print globalp == &globalstruct" \ |
471 | "value is not available" \ | |
472 | "can't compare using non collected global pointer" | |
0a251e08 | 473 | |
b5262cd0 YQ |
474 | gdb_test "print globalarr\[1\]" " = <unavailable>" |
475 | gdb_test "print globalarr\[2\]" " = <unavailable>" | |
476 | gdb_test "print globalarr\[3\]" " = <unavailable>" | |
0a251e08 | 477 | |
b5262cd0 YQ |
478 | gdb_test "print struct_b" \ |
479 | " = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}" | |
0a251e08 | 480 | |
b5262cd0 YQ |
481 | gdb_test "print /x struct_b" \ |
482 | " = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}, string = <unavailable>}" | |
0a251e08 | 483 | |
b5262cd0 YQ |
484 | gdb_test "print /x struct_b.struct_a" \ |
485 | " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}" | |
06d72e16 | 486 | |
b5262cd0 YQ |
487 | gdb_test "print /x struct_b.struct_a.array" \ |
488 | " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}" | |
06d72e16 | 489 | |
b5262cd0 | 490 | gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>" |
06d72e16 | 491 | |
b5262cd0 | 492 | gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa" |
06d72e16 | 493 | |
b5262cd0 YQ |
494 | # Check the target doesn't overcollect. GDB used to merge memory |
495 | # ranges to collect if they were close enough (collecting the hole | |
496 | # as well), but does not do that anymore. It's plausible that a | |
497 | # target may do this on its end, but as of this writing, no known | |
498 | # target does it. | |
499 | gdb_test "print {a, b, c}" \ | |
500 | " = \\{1, <unavailable>, 3\\}" \ | |
501 | "No overcollect of almost but not quite adjacent memory ranges" | |
06d72e16 | 502 | |
b5262cd0 | 503 | # Check <unavailable> isn't confused with 0 in array element repetitions |
06d72e16 | 504 | |
b5262cd0 | 505 | gdb_test_no_output "set print repeat 1" |
06d72e16 | 506 | |
b5262cd0 YQ |
507 | gdb_test "print /x tarray" \ |
508 | " = \{\{a = 0x0, b = <unavailable>\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\}, \{a = 0x0, b = 0x0\}, \{a = <unavailable>, b = 0x0\} <repeats 2 times>, \{a = <unavailable>, b = <unavailable>\} <repeats 2 times>\}" \ | |
509 | "<unavailable> is not the same as 0 in array element repetitions" | |
06d72e16 | 510 | |
b5262cd0 | 511 | gdb_test_no_output "set print repeat 10" |
06d72e16 | 512 | |
b5262cd0 YQ |
513 | # Check that value repeat handles unavailable-ness. |
514 | gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}" | |
1b28d0b3 | 515 | |
b5262cd0 | 516 | # Static fields |
06d72e16 | 517 | |
b5262cd0 | 518 | gdb_test "print struct_b.static_struct_a" " = <unavailable>" |
06d72e16 | 519 | |
b5262cd0 | 520 | # Bitfields |
06d72e16 | 521 | |
b5262cd0 | 522 | gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>" |
06d72e16 | 523 | |
b5262cd0 | 524 | # References |
24e6bcee | 525 | |
b5262cd0 | 526 | gdb_test "print g_int" " = <unavailable>" |
06d72e16 | 527 | |
b5262cd0 YQ |
528 | gdb_test "print g_ref" \ |
529 | "\\(int &\\) @$hex: <unavailable>" \ | |
530 | "global reference shows address but not value" | |
06d72e16 | 531 | |
b5262cd0 YQ |
532 | gdb_test "print *&g_ref" \ |
533 | "\\$\[0-9\]+ = <unavailable>$cr" \ | |
534 | "referenced integer was not collected (taking address of reference)" | |
06d72e16 | 535 | |
b5262cd0 | 536 | gdb_test "print *g_structref_p" " = <unavailable>" |
06d72e16 | 537 | |
b5262cd0 | 538 | # Strings |
06d72e16 | 539 | |
b5262cd0 YQ |
540 | # Const string is always available, even when not collected. |
541 | gdb_test "print g_const_string" \ | |
542 | " = \"hello world\"$cr" \ | |
543 | "non collected const string is still printable" | |
06d72e16 | 544 | |
b5262cd0 YQ |
545 | gdb_test "print g_string_p" \ |
546 | " = $hex <g_const_string> \"hello world\"" \ | |
547 | "printing constant string through collected pointer" | |
06d72e16 | 548 | |
b5262cd0 YQ |
549 | gdb_test "print g_string_unavail" \ |
550 | " = <unavailable>" \ | |
551 | "printing non collected string" | |
06d72e16 | 552 | |
b5262cd0 YQ |
553 | # Incomplete strings print as an array. |
554 | gdb_test "print g_string_partial" \ | |
555 | "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \ | |
556 | "printing partially collected string" | |
06d72e16 | 557 | |
b5262cd0 YQ |
558 | # It is important for this test that the last examined value is |
559 | # <unavailable>, to exercise the case of the $__ convenience | |
560 | # variable being set to <unavailable> without error. | |
561 | set msg "examining partially collected object" | |
562 | gdb_test_multiple "x /10x &struct_b" "$msg" { | |
563 | -re "$hex <struct_b>:${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>$cr$hex <struct_b\\+16>:${ws}<unavailable>${ws}<unavailable>${ws}0xaaaaaaaa${ws}<unavailable>$cr$hex <struct_b\\+32>:${ws}<unavailable>${ws}<unavailable>$cr$gdb_prompt $" { | |
564 | pass "$msg" | |
565 | } | |
566 | -re "value is not available" { | |
567 | fail "$msg" | |
568 | } | |
569 | } | |
06d72e16 | 570 | |
b5262cd0 | 571 | gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>" |
06d72e16 | 572 | |
b5262cd0 YQ |
573 | # This tests that building the array does not require accessing |
574 | # g_int's contents. | |
575 | gdb_test "print { 1, g_int, 3 }" \ | |
576 | " = \\{1, <unavailable>, 3\\}" \ | |
577 | "build array from unavailable value" | |
06d72e16 | 578 | |
b5262cd0 YQ |
579 | # Note, depends on previous test. |
580 | gdb_test "print \$\[1\]" \ | |
581 | " = <unavailable>" \ | |
582 | "subscript a non-memory rvalue array, accessing an unvailable element" | |
06d72e16 | 583 | |
b5262cd0 YQ |
584 | # Access a field of a non-lazy value, making sure the |
585 | # unavailable-ness is propagated. History values are easy | |
586 | # non-lazy values, so use those. The first test just sets up for | |
587 | # the second. | |
588 | gdb_test "print g_smallstruct" " = <unavailable>" | |
589 | gdb_test "print \$.member" " = <unavailable>" | |
06d72e16 | 590 | |
b5262cd0 YQ |
591 | # Cast to baseclass, checking the unavailable-ness is propagated. |
592 | gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>" | |
06d72e16 | 593 | |
b5262cd0 YQ |
594 | # Same cast, but starting from a non-lazy, value. |
595 | gdb_test "print g_smallstruct_b" " = <unavailable>" | |
596 | gdb_test "print (small_struct) \$" " = <unavailable>" | |
0a251e08 | 597 | |
b5262cd0 | 598 | gdb_test_no_output "set print object on" |
0a251e08 | 599 | |
b5262cd0 YQ |
600 | with_test_prefix "print object on" { |
601 | # With print object on, printing a pointer may need to fetch | |
602 | # the pointed-to object, to check its run-time type. Make | |
603 | # sure that fails gracefully and transparently when the | |
604 | # pointer itself is unavailable. | |
605 | gdb_test "print virtualp" " = <unavailable>" | |
0a251e08 | 606 | |
b5262cd0 YQ |
607 | # no vtable pointer available |
608 | gdb_test "print derived_unavail" " = <unavailable>" | |
0a251e08 | 609 | |
b5262cd0 YQ |
610 | # vtable pointer available, but nothing else |
611 | gdb_test "print derived_partial" \ | |
612 | " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}" | |
0a251e08 | 613 | |
b5262cd0 YQ |
614 | # whole object available |
615 | gdb_test "print derived_whole" \ | |
0a5d52f0 | 616 | " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = ${hex}( <\[^>]*>)?, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}" |
b5262cd0 | 617 | } |
0a251e08 | 618 | |
b5262cd0 | 619 | gdb_test_no_output "set print object off" |
0a251e08 | 620 | |
b5262cd0 YQ |
621 | with_test_prefix "print object off" { |
622 | gdb_test "print virtualp" " = <unavailable>" | |
0a251e08 | 623 | |
b5262cd0 YQ |
624 | # no vtable pointer available |
625 | gdb_test "print derived_unavail" \ | |
626 | " = <unavailable>" | |
0a251e08 | 627 | |
b5262cd0 YQ |
628 | # vtable pointer available, but nothing else |
629 | gdb_test "print derived_partial" \ | |
630 | " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}" | |
0a251e08 | 631 | |
b5262cd0 YQ |
632 | # whole object available |
633 | gdb_test "print derived_whole" \ | |
0a5d52f0 | 634 | " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = ${hex}( <\[^>]*>)?, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}" |
b5262cd0 YQ |
635 | } |
636 | ||
637 | # An instance of a virtual class where we collected everything but | |
638 | # the vptr. | |
639 | gdb_test "print virtual_partial" \ | |
640 | " = {_vptr.Virtual = <unavailable>, z = 0}" | |
641 | } | |
8af8e3bc | 642 | |
b5262cd0 YQ |
643 | proc gdb_collect_globals_test { } { |
644 | with_test_prefix "collect globals" { | |
290a839c YQ |
645 | global testfile binfile srcdir subdir |
646 | global trace_file_targets | |
647 | ||
b5262cd0 | 648 | prepare_for_trace_test |
ec0a52e1 | 649 | |
b5262cd0 | 650 | set testline [gdb_get_line_number "set globals_test_func tracepoint here"] |
8af8e3bc | 651 | |
b5262cd0 YQ |
652 | gdb_test "trace $testline" \ |
653 | "Tracepoint \[0-9\]+ at .*" \ | |
654 | "set tracepoint" | |
8af8e3bc | 655 | |
b5262cd0 YQ |
656 | # We collect the initial sizeof(pointer) bytes of derived_partial |
657 | # in an attempt of collecting the vptr. Not portable, but should | |
658 | # work everywhere we need to care. | |
659 | gdb_trace_setactions "define actions" \ | |
660 | "" \ | |
661 | "collect struct_b.struct_a.array\[2\]" "^$" \ | |
662 | "collect struct_b.struct_a.array\[100\]" "^$" \ | |
663 | \ | |
664 | "collect a" "^$" \ | |
665 | "collect c" "^$" \ | |
666 | \ | |
667 | "collect tarray\[0\].a" "^$" \ | |
668 | "collect tarray\[1\].a" "^$" \ | |
669 | "collect tarray\[3\].a" "^$" \ | |
670 | "collect tarray\[3\].b" "^$" \ | |
671 | "collect tarray\[4\].b" "^$" \ | |
672 | "collect tarray\[5\].b" "^$" \ | |
673 | \ | |
674 | "collect g_string_p" "^$" \ | |
675 | "collect g_string_partial\[1\]" "^$" \ | |
676 | "collect g_string_partial\[2\]" "^$" \ | |
677 | \ | |
678 | "collect g_structref_p" "^$" \ | |
679 | \ | |
680 | "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \ | |
681 | "collect derived_whole" "^$" \ | |
682 | \ | |
683 | "collect virtual_partial.z" "^$" | |
8af8e3bc | 684 | |
b5262cd0 YQ |
685 | # Begin the test. |
686 | run_trace_experiment globals_test_func | |
8af8e3bc | 687 | |
b5262cd0 | 688 | gdb_collect_globals_test_1 |
8af8e3bc | 689 | |
0a251e08 YQ |
690 | gdb_test "tfind none" \ |
691 | "#0 end .*" \ | |
692 | "cease trace debugging" | |
290a839c YQ |
693 | |
694 | set tracefile [standard_output_file ${testfile}] | |
695 | gdb_test "tsave ${tracefile}.globals.tfile" \ | |
696 | "Trace data saved to file '${tracefile}.globals.tfile'\.\\r" \ | |
697 | "tsave ${testfile}.globals.tfile" | |
698 | gdb_test "tsave -ctf ${tracefile}.globals.ctf" \ | |
699 | "Trace data saved to directory '${tracefile}.globals.ctf'\.\\r" \ | |
700 | "save ctf trace file" | |
701 | ||
702 | foreach target_name ${trace_file_targets} { | |
703 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
704 | gdb_exit | |
705 | gdb_start | |
706 | gdb_reinitialize_dir $srcdir/$subdir | |
707 | gdb_file_cmd $binfile | |
708 | gdb_test "target ${target_name} ${tracefile}.globals.${target_name}" ".*" \ | |
709 | "change to ${target_name} target" | |
710 | ||
711 | with_test_prefix "${target_name}" { | |
712 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
713 | "tfind test frame" | |
714 | gdb_collect_globals_test_1 | |
715 | } | |
716 | } | |
717 | ||
0a251e08 YQ |
718 | } |
719 | } | |
06d72e16 PA |
720 | |
721 | proc gdb_trace_collection_test {} { | |
722 | gdb_collect_globals_test | |
0fdb4f18 | 723 | gdb_unavailable_registers_test |
ad5f7d6e | 724 | gdb_unavailable_floats |
8661b11b PA |
725 | |
726 | gdb_collect_args_test | |
727 | gdb_collect_locals_test local_test_func "auto locals" | |
728 | gdb_collect_locals_test reglocal_test_func "register locals" | |
729 | gdb_collect_locals_test statlocal_test_func "static locals" | |
06d72e16 PA |
730 | } |
731 | ||
06d72e16 PA |
732 | runto_main |
733 | ||
06d72e16 | 734 | if { ![gdb_target_supports_trace] } then { |
bc6c7af4 | 735 | unsupported "current target does not support trace" |
ae59b1da | 736 | return 1 |
06d72e16 PA |
737 | } |
738 | ||
290a839c YQ |
739 | set trace_file_targets [list "tfile"] |
740 | gdb_test_multiple "target ctf" "" { | |
741 | -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" { | |
742 | } | |
743 | -re "No CTF directory specified.*\r\n$gdb_prompt $" { | |
744 | lappend trace_file_targets "ctf" | |
745 | } | |
746 | } | |
747 | ||
06d72e16 PA |
748 | # Body of test encased in a proc so we can return prematurely. |
749 | gdb_trace_collection_test | |
750 | ||
751 | # Finished! | |
752 | gdb_test "tfind none" ".*" "" |