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