1 # Copyright 1998-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib "trace-support.exp"
18 standard_testfile unavailable.cc
19 set executable $testfile
21 if {[prepare_for_testing $testfile.exp $testfile $srcfile \
22 {debug nowarnings c++}]} {
29 if [is_amd64_regs_target] {
33 } elseif [is_x86_like_target] {
47 proc test_register { reg } {
52 gdb_test_multiple "print /x $reg" "collected $reg" {
53 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
54 fail "collected $reg (zero)"
56 -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
59 -re "\[Ee\]rror.*$gdb_prompt $" {
60 fail "collected $reg (error)"
65 proc test_register_unavailable { reg } {
66 gdb_test "print /x $reg" \
68 "correctly report $reg as unavailable"
71 proc prepare_for_trace_test {} {
74 clean_restart $executable
78 gdb_test "break begin" ".*" ""
79 gdb_test "break end" ".*" ""
82 proc run_trace_experiment { test_func } {
86 ".*Breakpoint \[0-9\]+, begin .*" \
89 gdb_test_no_output "tstart" "start trace experiment"
92 "Continuing.*Breakpoint \[0-9\]+, end.*" \
93 "run trace experiment"
96 "stop trace experiment"
97 gdb_test "tfind start" \
102 # Test that "display VAR" works as expected, assuming VAR is wholly
105 proc test_maybe_regvar_display { var } {
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 $" {
119 -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
123 gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
127 "delete $var display" \
128 ".*Delete all auto-display expressions.*y or n. $" \
136 proc gdb_collect_args_test_1 {} {
139 # Test printing the variables, and also their addresses. We
140 # haven't collected any stack, so there's no way GDB can figure
143 gdb_test "print argc" " = <unavailable>"
144 gdb_test "print &argc" \
145 "Can't take address of \"argc\" which isn't an lvalue\."
147 gdb_test "print argi" " = <unavailable>"
148 gdb_test "print &argi" \
149 "Can't take address of \"argi\" which isn't an lvalue\."
151 gdb_test "print argf" " = <unavailable>"
152 gdb_test "print &argf" \
153 "Can't take address of \"argf\" which isn't an lvalue\."
155 gdb_test "print argd" " = <unavailable>"
156 gdb_test "print &argd" \
157 "Can't take address of \"argd\" which isn't an lvalue\."
159 # struct arg as one of several args (near end of list)
161 gdb_test "print argstruct" " = <unavailable>"
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>"
168 gdb_test "print argarray" " = <unavailable>"
170 gdb_test "print &argarray" \
171 "Can't take address of \"argarray\" which isn't an lvalue\."
173 gdb_test "print argarray\[0\]" "value is not available"
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"
185 test_maybe_regvar_display "argc"
188 proc gdb_collect_args_test {} {
189 with_test_prefix "unavailable arguments" {
192 prepare_for_trace_test
194 gdb_test "trace args_test_func" \
195 "Tracepoint \[0-9\]+ at .*" \
199 run_trace_experiment args_test_func
201 gdb_collect_args_test_1
203 gdb_test "tfind none" \
205 "cease trace debugging"
209 proc gdb_collect_locals_test_1 { func } {
212 gdb_test "print locc" " = <unavailable>"
213 gdb_test "print loci" " = <unavailable>"
214 gdb_test "print locf" " = <unavailable>"
215 gdb_test "print locd" " = <unavailable>"
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>"
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>"
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}"
237 set r "${r}locc = <unavailable>${cr}"
238 set r "${r}loci = <unavailable>${cr}"
239 gdb_test "info locals" "$r" "info locals"
241 test_maybe_regvar_display "loci"
244 proc gdb_collect_locals_test { func msg } {
245 with_test_prefix "unavailable locals: $msg" {
248 prepare_for_trace_test
250 set testline [gdb_get_line_number "set $func tracepoint here"]
252 gdb_test "trace $testline" \
253 "Tracepoint \[0-9\]+ at .*" \
257 run_trace_experiment $func
259 gdb_collect_locals_test_1 $func
261 gdb_test "tfind none" \
263 "cease trace debugging"
267 proc gdb_unavailable_registers_test_1 { } {
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"
276 # Test reading uncollected pseudo-registers. The set of which
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"
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"
294 gdb_test "info registers" \
295 "<unavailable>.*<unavailable>" \
296 "info registers, multiple registers not available"
298 gdb_test "info registers \$$spreg" \
300 "info registers \$$spreg reports not available"
303 proc gdb_unavailable_registers_test { } {
304 with_test_prefix "unavailable registers" {
306 prepare_for_trace_test
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 .*" \
316 run_trace_experiment globals_test_func
318 gdb_unavailable_registers_test_1
320 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
324 proc gdb_unavailable_floats_1 { } {
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>"
341 proc gdb_unavailable_floats { } {
342 with_test_prefix "unavailable floats" {
343 prepare_for_trace_test
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 .*" \
353 run_trace_experiment globals_test_func
355 gdb_unavailable_floats_1
357 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
361 proc gdb_collect_globals_test_1 { } {
367 gdb_test "print globalc" " = <unavailable>"
368 gdb_test "print globali" " = <unavailable>"
369 gdb_test "print globalf" " = <unavailable>"
370 gdb_test "print globald" " = <unavailable>"
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>"
377 gdb_test "print globalstruct" " = <unavailable>"
379 gdb_test "print globalp == &globalstruct" \
380 "value is not available" \
381 "can't compare using non collected global pointer"
383 gdb_test "print globalarr\[1\]" " = <unavailable>"
384 gdb_test "print globalarr\[2\]" " = <unavailable>"
385 gdb_test "print globalarr\[3\]" " = <unavailable>"
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>}"
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>}"
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>}"
396 gdb_test "print /x struct_b.struct_a.array" \
397 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
399 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
401 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
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
408 gdb_test "print {a, b, c}" \
409 " = \\{1, <unavailable>, 3\\}" \
410 "No overcollect of almost but not quite adjacent memory ranges"
412 # Check <unavailable> isn't confused with 0 in array element repetitions
414 gdb_test_no_output "set print repeat 1"
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"
420 gdb_test_no_output "set print repeat 10"
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>\\}\\}"
427 gdb_test "print struct_b.static_struct_a" " = <unavailable>"
431 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
435 gdb_test "print g_int" " = <unavailable>"
437 gdb_test "print g_ref" \
438 "\\(int &\\) @$hex: <unavailable>" \
439 "global reference shows address but not value"
441 gdb_test "print *&g_ref" \
442 "\\$\[0-9\]+ = <unavailable>$cr" \
443 "referenced integer was not collected (taking address of reference)"
445 gdb_test "print *g_structref_p" " = <unavailable>"
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"
454 gdb_test "print g_string_p" \
455 " = $hex <g_const_string> \"hello world\"" \
456 "printing constant string through collected pointer"
458 gdb_test "print g_string_unavail" \
460 "printing non collected string"
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"
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 $" {
475 -re "value is not available" {
480 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
482 # This tests that building the array does not require accessing
484 gdb_test "print { 1, g_int, 3 }" \
485 " = \\{1, <unavailable>, 3\\}" \
486 "build array from unavailable value"
488 # Note, depends on previous test.
489 gdb_test "print \$\[1\]" \
491 "subscript a non-memory rvalue array, accessing an unvailable element"
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
497 gdb_test "print g_smallstruct" " = <unavailable>"
498 gdb_test "print \$.member" " = <unavailable>"
500 # Cast to baseclass, checking the unavailable-ness is propagated.
501 gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>"
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>"
507 gdb_test_no_output "set print object on"
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>"
516 # no vtable pointer available
517 gdb_test "print derived_unavail" " = <unavailable>"
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>}"
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}"
528 gdb_test_no_output "set print object off"
530 with_test_prefix "print object off" {
531 gdb_test "print virtualp" " = <unavailable>"
533 # no vtable pointer available
534 gdb_test "print derived_unavail" \
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>}"
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}"
546 # An instance of a virtual class where we collected everything but
548 gdb_test "print virtual_partial" \
549 " = {_vptr.Virtual = <unavailable>, z = 0}"
552 proc gdb_collect_globals_test { } {
553 with_test_prefix "collect globals" {
554 prepare_for_trace_test
556 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
558 gdb_test "trace $testline" \
559 "Tracepoint \[0-9\]+ at .*" \
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" \
567 "collect struct_b.struct_a.array\[2\]" "^$" \
568 "collect struct_b.struct_a.array\[100\]" "^$" \
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" "^$" \
580 "collect g_string_p" "^$" \
581 "collect g_string_partial\[1\]" "^$" \
582 "collect g_string_partial\[2\]" "^$" \
584 "collect g_structref_p" "^$" \
586 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
587 "collect derived_whole" "^$" \
589 "collect virtual_partial.z" "^$"
592 run_trace_experiment globals_test_func
594 gdb_collect_globals_test_1
596 gdb_test "tfind none" \
598 "cease trace debugging"
602 proc gdb_trace_collection_test {} {
603 gdb_collect_globals_test
604 gdb_unavailable_registers_test
605 gdb_unavailable_floats
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"
615 if { ![gdb_target_supports_trace] } then {
616 unsupported "Current target does not support trace"
620 # Body of test encased in a proc so we can return prematurely.
621 gdb_trace_collection_test
624 gdb_test "tfind none" ".*" ""