1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 load_lib "trace-support.exp"
19 set testfile "unavailable"
20 set srcfile ${testfile}.cc
21 set executable $testfile
22 set binfile $objdir/$subdir/$executable
24 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
25 executable {debug nowarnings c++}] != "" } {
26 untested unavailable.exp
33 if [is_amd64_regs_target] {
37 } elseif [is_x86_like_target] {
51 proc test_register { reg } {
56 gdb_test_multiple "print /x $reg" "collected $reg" {
57 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
58 fail "collected $reg (zero)"
60 -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
63 -re "\[Ee\]rror.*$gdb_prompt $" {
64 fail "collected $reg (error)"
69 proc test_register_unavailable { reg } {
70 gdb_test "print /x $reg" \
72 "correctly report $reg as unavailable"
75 proc prepare_for_trace_test {} {
78 clean_restart $executable
82 gdb_test "break begin" ".*" ""
83 gdb_test "break end" ".*" ""
86 proc run_trace_experiment { test_func } {
90 ".*Breakpoint \[0-9\]+, begin .*" \
93 gdb_test_no_output "tstart" "start trace experiment"
96 "Continuing.*Breakpoint \[0-9\]+, end.*" \
97 "run trace experiment"
100 "stop trace experiment"
101 gdb_test "tfind start" \
106 # Test that "display VAR" works as expected, assuming VAR is wholly
109 proc test_maybe_regvar_display { var } {
112 # Evaluating VAR's location description may throw an internal
113 # "unavailable" exception, if for example, the value of a register
114 # necessary for computing VAR's location is unavailable. Such an
115 # exception is caught, and should not cause automatic disablement
116 # of the current display being printed. (GDB used to disable the
117 # current display whenever any exception was thrown.)
118 set test "display $var"
119 gdb_test_multiple "$test" "$test" {
120 -re "Disabling display ? to avoid infinite recursion.*$gdb_prompt $" {
123 -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
127 gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
131 "delete $var display" \
132 ".*Delete all auto-display expressions.*y or n. $" \
140 proc gdb_collect_args_test {} {
145 set old_pf_prefix $pf_prefix
146 set pf_prefix "$pf_prefix unavailable arguments:"
148 prepare_for_trace_test
150 gdb_test "trace args_test_func" \
151 "Tracepoint \[0-9\]+ at .*" \
155 run_trace_experiment args_test_func
157 # Test printing the variables, and also their addresses. We
158 # haven't collected any stack, so there's no way GDB can figure
161 gdb_test "print argc" " = <unavailable>"
162 gdb_test "print &argc" \
163 "Can't take address of \"argc\" which isn't an lvalue\."
165 gdb_test "print argi" " = <unavailable>"
166 gdb_test "print &argi" \
167 "Can't take address of \"argi\" which isn't an lvalue\."
169 gdb_test "print argf" " = <unavailable>"
170 gdb_test "print &argf" \
171 "Can't take address of \"argf\" which isn't an lvalue\."
173 gdb_test "print argd" " = <unavailable>"
174 gdb_test "print &argd" \
175 "Can't take address of \"argd\" which isn't an lvalue\."
177 # struct arg as one of several args (near end of list)
179 gdb_test "print argstruct" \
180 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
182 gdb_test "print argstruct.memberc" " = <unavailable>"
183 gdb_test "print argstruct.memberi" " = <unavailable>"
184 gdb_test "print argstruct.memberf" " = <unavailable>"
185 gdb_test "print argstruct.memberd" " = <unavailable>"
187 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
189 gdb_test "print &argarray" \
190 "Can't take address of \"argarray\" which isn't an lvalue\."
192 gdb_test "print argarray\[0\]" "value is not available"
196 set r "${r}argc = <unavailable>${cr}"
197 set r "${r}argi = <unavailable>${cr}"
198 set r "${r}argf = <unavailable>${cr}"
199 set r "${r}argd = <unavailable>${cr}"
200 set r "${r}argstruct = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
201 set r "${r}argarray = <unavailable>${cr}"
202 gdb_test "info args" "$r" "info args"
204 test_maybe_regvar_display "argc"
206 gdb_test "tfind none" \
208 "cease trace debugging"
210 set pf_prefix $old_pf_prefix
213 proc gdb_collect_locals_test { func msg } {
218 set old_pf_prefix $pf_prefix
219 set pf_prefix "$pf_prefix unavailable locals: $msg:"
221 prepare_for_trace_test
223 set testline [gdb_get_line_number "set $func tracepoint here"]
225 gdb_test "trace $testline" \
226 "Tracepoint \[0-9\]+ at .*" \
230 run_trace_experiment $func
232 gdb_test "print locc" " = <unavailable>"
233 gdb_test "print loci" " = <unavailable>"
234 gdb_test "print locf" " = <unavailable>"
235 gdb_test "print locd" " = <unavailable>"
237 gdb_test "print locst.memberc" " = <unavailable>"
238 gdb_test "print locst.memberi" " = <unavailable>"
239 gdb_test "print locst.memberf" " = <unavailable>"
240 gdb_test "print locst.memberd" " = <unavailable>"
242 gdb_test "print locar\[0\]" " = <unavailable>"
243 gdb_test "print locar\[1\]" " = <unavailable>"
244 gdb_test "print locar\[2\]" " = <unavailable>"
245 gdb_test "print locar\[3\]" " = <unavailable>"
249 set r "${r}locf = <unavailable>${cr}"
250 set r "${r}locd = <unavailable>${cr}"
251 set r "${r}locst = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
252 set r "${r}locar = {<unavailable>, <unavailable>, <unavailable>, <unavailable>}${cr}"
253 set r "${r}i = <unavailable>${cr}"
254 if { $func == "local_test_func" } {
255 set r "${r}locdefst = {<No data fields>}${cr}"
257 set r "${r}locc = <unavailable>${cr}"
258 set r "${r}loci = <unavailable>${cr}"
259 gdb_test "info locals" "$r" "info locals"
261 test_maybe_regvar_display "loci"
263 gdb_test "tfind none" \
265 "cease trace debugging"
267 set pf_prefix $old_pf_prefix
270 proc gdb_unavailable_registers_test { } {
276 set old_pf_prefix $pf_prefix
277 set pf_prefix "$pf_prefix unavailable registers:"
279 prepare_for_trace_test
281 # We'll simply re-use the globals_test_function for this test
282 gdb_test "trace globals_test_func" \
283 "Tracepoint \[0-9\]+ at .*" \
289 run_trace_experiment globals_test_func
291 # On some archs, the $sp/$pc are a real raw registers. On others,
292 # like x86, they're user registers. Test both variants.
293 test_register_unavailable "\$$spreg"
294 test_register_unavailable "\$sp"
296 # Test reading uncollected pseudo-registers. The set of which
298 if [is_amd64_regs_target] {
299 # Check the raw register first.
300 test_register_unavailable "\$rax"
301 test_register_unavailable "\$eax"
302 test_register_unavailable "\$ax"
303 } elseif [is_x86_like_target] {
304 # Check the raw register first.
305 test_register_unavailable "\$eax"
306 test_register_unavailable "\$ax"
309 # GDBserver always provides the PC value of regular tracepoint
310 # hits, since it's the same as the tracepoint's address.
311 test_register "\$$pcreg"
314 gdb_test "info registers" \
315 "\\*value not available\\*.*\\*value not available\\*" \
316 "info registers, multiple registers not available"
318 gdb_test "info registers \$$spreg" \
319 "\\*value not available\\*" \
320 "info registers \$$spreg reports not available"
322 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
324 set pf_prefix $old_pf_prefix
327 proc gdb_collect_globals_test { } {
334 set old_pf_prefix $pf_prefix
335 set pf_prefix "$pf_prefix collect globals:"
337 prepare_for_trace_test
339 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
341 gdb_test "trace $testline" \
342 "Tracepoint \[0-9\]+ at .*" \
345 # We collect the initial sizeof(pointer) bytes of derived_partial
346 # in an attempt of collecting the vptr. Not portable, but should
347 # work everywhere we need to care.
348 gdb_trace_setactions "define actions" \
350 "collect struct_b.struct_a.array\[2\]" "^$" \
351 "collect struct_b.struct_a.array\[100\]" "^$" \
356 "collect tarray\[0\].a" "^$" \
357 "collect tarray\[1\].a" "^$" \
358 "collect tarray\[3\].a" "^$" \
359 "collect tarray\[3\].b" "^$" \
360 "collect tarray\[4\].b" "^$" \
361 "collect tarray\[5\].b" "^$" \
363 "collect g_string_p" "^$" \
364 "collect g_string_partial\[1\]" "^$" \
365 "collect g_string_partial\[2\]" "^$" \
367 "collect g_structref_p" "^$" \
369 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
370 "collect derived_whole" "^$" \
372 "collect virtual_partial.z" "^$"
375 run_trace_experiment globals_test_func
377 gdb_test "print globalc" " = <unavailable>"
378 gdb_test "print globali" " = <unavailable>"
379 gdb_test "print globalf" " = <unavailable>"
380 gdb_test "print globald" " = <unavailable>"
382 gdb_test "print globalstruct.memberc" " = <unavailable>"
383 gdb_test "print globalstruct.memberi" " = <unavailable>"
384 gdb_test "print globalstruct.memberf" " = <unavailable>"
385 gdb_test "print globalstruct.memberd" " = <unavailable>"
387 gdb_test "print globalstruct" \
388 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
390 gdb_test "print globalp == &globalstruct" \
391 "value is not available" \
392 "can't compare using non collected global pointer"
394 gdb_test "print globalarr\[1\]" " = <unavailable>"
395 gdb_test "print globalarr\[2\]" " = <unavailable>"
396 gdb_test "print globalarr\[3\]" " = <unavailable>"
398 gdb_test "print struct_b" \
399 " = {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>}"
401 gdb_test "print /x struct_b" \
402 " = {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>}"
404 gdb_test "print /x struct_b.struct_a" \
405 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
407 gdb_test "print /x struct_b.struct_a.array" \
408 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
410 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
412 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
414 # Check the target doesn't overcollect. GDB used to merge memory
415 # ranges to collect if they were close enough (collecting the hole
416 # as well), but does not do that anymore. It's plausible that a
417 # target may do this on its end, but as of this writing, no known
419 gdb_test "print {a, b, c}" \
420 " = \\{1, <unavailable>, 3\\}" \
421 "No overcollect of almost but not quite adjacent memory ranges"
423 # Check <unavailable> isn't confused with 0 in array element repetitions
425 gdb_test_no_output "set print repeat 1"
427 gdb_test "print /x tarray" \
428 " = \{\{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>\}" \
429 "<unavailable> is not the same as 0 in array element repetitions"
431 gdb_test_no_output "set print repeat 10"
433 # Check that value repeat handles unavailable-ness.
434 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
438 gdb_test "print struct_b.static_struct_a" \
439 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
443 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
447 gdb_test "print g_int" " = <unavailable>"
449 gdb_test "print g_ref" \
450 "\\(int &\\) @$hex: <unavailable>" \
451 "global reference shows address but not value"
453 gdb_test "print *&g_ref" \
454 "\\$\[0-9\]+ = <unavailable>$cr" \
455 "referenced integer was not collected (taking address of reference)"
457 gdb_test "print *g_structref_p" \
458 " = {d = <unavailable>, ref = <unavailable>}"
462 # Const string is always available, even when not collected.
463 gdb_test "print g_const_string" \
464 " = \"hello world\"$cr" \
465 "non collected const string is still printable"
467 gdb_test "print g_string_p" \
468 " = $hex \"hello world\"" \
469 "printing constant string through collected pointer"
471 gdb_test "print g_string_unavail" \
472 " = \{<unavailable> <repeats 12 times>\}" \
473 "printing non collected string"
475 # Incomplete strings print as an array.
476 gdb_test "print g_string_partial" \
477 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
478 "printing partially collected string"
480 # It is important for this test that the last examined value is
481 # <unavailable>, to exercise the case of the $__ convenience
482 # variable being set to <unavailable> without error.
483 set msg "examining partially collected object"
484 gdb_test_multiple "x /10x &struct_b" "$msg" {
485 -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 $" {
488 -re "value is not available" {
493 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
495 # This tests that building the array does not require accessing
497 gdb_test "print { 1, g_int, 3 }" \
498 " = \\{1, <unavailable>, 3\\}" \
499 "build array from unavailable value"
501 # Note, depends on previous test.
502 gdb_test "print \$\[1\]" \
504 "subscript a non-memory rvalue array, accessing an unvailable element"
506 # Access a field of a non-lazy value, making sure the
507 # unavailable-ness is propagated. History values are easy
508 # non-lazy values, so use those. The first test just sets up for
510 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
511 gdb_test "print \$.member" " = <unavailable>"
513 # Cast to baseclass, checking the unavailable-ness is propagated.
514 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
516 # Same cast, but starting from a non-lazy, value.
517 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
518 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
520 gdb_test_no_output "set print object on"
522 set old_pf_prefix_2 $pf_prefix
523 set pf_prefix "$pf_prefix print object on:"
525 # With print object on, printing a pointer may need to fetch the
526 # pointed-to object, to check its run-time type. Make sure that
527 # fails gracefully and transparently when the pointer itself is
529 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
531 # no vtable pointer available
532 gdb_test "print derived_unavail" \
533 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
535 # vtable pointer available, but nothing else
536 gdb_test "print derived_partial" \
537 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
539 # whole object available
540 gdb_test "print derived_whole" \
541 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
543 set pf_prefix $old_pf_prefix_2
545 gdb_test_no_output "set print object off"
547 set pf_prefix "$pf_prefix print object off:"
549 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
551 # no vtable pointer available
552 gdb_test "print derived_unavail" \
553 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
555 # vtable pointer available, but nothing else
556 gdb_test "print derived_partial" \
557 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
559 # whole object available
560 gdb_test "print derived_whole" \
561 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
563 set pf_prefix $old_pf_prefix_2
565 # An instance of a virtual class where we collected everything but
567 gdb_test "print virtual_partial" \
568 " = {_vptr.Virtual = <unavailable>, z = 0}"
570 gdb_test "tfind none" \
572 "cease trace debugging"
574 set pf_prefix $old_pf_prefix
577 proc gdb_trace_collection_test {} {
578 gdb_collect_globals_test
579 gdb_unavailable_registers_test
581 gdb_collect_args_test
582 gdb_collect_locals_test local_test_func "auto locals"
583 gdb_collect_locals_test reglocal_test_func "register locals"
584 gdb_collect_locals_test statlocal_test_func "static locals"
587 clean_restart $executable
590 # We generously give ourselves one "pass" if we successfully
591 # detect that this test cannot be run on this target!
592 if { ![gdb_target_supports_trace] } then {
593 pass "Current target does not support trace"
597 # Body of test encased in a proc so we can return prematurely.
598 gdb_trace_collection_test
601 gdb_test "tfind none" ".*" ""