1 # Copyright 1998-2013 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 {} {
137 with_test_prefix "unavailable arguments" {
141 prepare_for_trace_test
143 gdb_test "trace args_test_func" \
144 "Tracepoint \[0-9\]+ at .*" \
148 run_trace_experiment args_test_func
150 # Test printing the variables, and also their addresses. We
151 # haven't collected any stack, so there's no way GDB can figure
154 gdb_test "print argc" " = <unavailable>"
155 gdb_test "print &argc" \
156 "Can't take address of \"argc\" which isn't an lvalue\."
158 gdb_test "print argi" " = <unavailable>"
159 gdb_test "print &argi" \
160 "Can't take address of \"argi\" which isn't an lvalue\."
162 gdb_test "print argf" " = <unavailable>"
163 gdb_test "print &argf" \
164 "Can't take address of \"argf\" which isn't an lvalue\."
166 gdb_test "print argd" " = <unavailable>"
167 gdb_test "print &argd" \
168 "Can't take address of \"argd\" which isn't an lvalue\."
170 # struct arg as one of several args (near end of list)
172 gdb_test "print argstruct" \
173 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
175 gdb_test "print argstruct.memberc" " = <unavailable>"
176 gdb_test "print argstruct.memberi" " = <unavailable>"
177 gdb_test "print argstruct.memberf" " = <unavailable>"
178 gdb_test "print argstruct.memberd" " = <unavailable>"
180 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
182 gdb_test "print &argarray" \
183 "Can't take address of \"argarray\" which isn't an lvalue\."
185 gdb_test "print argarray\[0\]" "value is not available"
189 set r "${r}argc = <unavailable>${cr}"
190 set r "${r}argi = <unavailable>${cr}"
191 set r "${r}argf = <unavailable>${cr}"
192 set r "${r}argd = <unavailable>${cr}"
193 set r "${r}argstruct = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
194 set r "${r}argarray = <unavailable>${cr}"
195 gdb_test "info args" "$r" "info args"
197 test_maybe_regvar_display "argc"
199 gdb_test "tfind none" \
201 "cease trace debugging"
205 proc gdb_collect_locals_test { func msg } {
206 with_test_prefix "unavailable locals: $msg" {
210 prepare_for_trace_test
212 set testline [gdb_get_line_number "set $func tracepoint here"]
214 gdb_test "trace $testline" \
215 "Tracepoint \[0-9\]+ at .*" \
219 run_trace_experiment $func
221 gdb_test "print locc" " = <unavailable>"
222 gdb_test "print loci" " = <unavailable>"
223 gdb_test "print locf" " = <unavailable>"
224 gdb_test "print locd" " = <unavailable>"
226 gdb_test "print locst.memberc" " = <unavailable>"
227 gdb_test "print locst.memberi" " = <unavailable>"
228 gdb_test "print locst.memberf" " = <unavailable>"
229 gdb_test "print locst.memberd" " = <unavailable>"
231 gdb_test "print locar\[0\]" " = <unavailable>"
232 gdb_test "print locar\[1\]" " = <unavailable>"
233 gdb_test "print locar\[2\]" " = <unavailable>"
234 gdb_test "print locar\[3\]" " = <unavailable>"
238 set r "${r}locf = <unavailable>${cr}"
239 set r "${r}locd = <unavailable>${cr}"
240 set r "${r}locst = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
241 set r "${r}locar = {<unavailable>, <unavailable>, <unavailable>, <unavailable>}${cr}"
242 set r "${r}i = <unavailable>${cr}"
243 if { $func == "local_test_func" } {
244 set r "${r}locdefst = {<No data fields>}${cr}"
246 set r "${r}locc = <unavailable>${cr}"
247 set r "${r}loci = <unavailable>${cr}"
248 gdb_test "info locals" "$r" "info locals"
250 test_maybe_regvar_display "loci"
252 gdb_test "tfind none" \
254 "cease trace debugging"
258 proc gdb_unavailable_registers_test { } {
259 with_test_prefix "unavailable registers" {
264 prepare_for_trace_test
266 # We'll simply re-use the globals_test_function for this test
267 gdb_test "trace globals_test_func" \
268 "Tracepoint \[0-9\]+ at .*" \
274 run_trace_experiment globals_test_func
276 # On some archs, the $sp/$pc are a real raw registers. On others,
277 # like x86, they're user registers. Test both variants.
278 test_register_unavailable "\$$spreg"
279 test_register_unavailable "\$sp"
281 # Test reading uncollected pseudo-registers. The set of which
283 if [is_amd64_regs_target] {
284 # Check the raw register first.
285 test_register_unavailable "\$rax"
286 test_register_unavailable "\$eax"
287 test_register_unavailable "\$ax"
288 } elseif [is_x86_like_target] {
289 # Check the raw register first.
290 test_register_unavailable "\$eax"
291 test_register_unavailable "\$ax"
294 # GDBserver always provides the PC value of regular tracepoint
295 # hits, since it's the same as the tracepoint's address.
296 test_register "\$$pcreg"
299 gdb_test "info registers" \
300 "<unavailable>.*<unavailable>" \
301 "info registers, multiple registers not available"
303 gdb_test "info registers \$$spreg" \
305 "info registers \$$spreg reports not available"
307 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
311 proc gdb_unavailable_floats { } {
314 with_test_prefix "unavailable floats" {
315 prepare_for_trace_test
317 # We'll simply re-use the globals_test_function for this test
318 gdb_test "trace globals_test_func" \
319 "Tracepoint \[0-9\]+ at .*" \
325 run_trace_experiment globals_test_func
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>"
340 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
344 proc gdb_collect_globals_test { } {
345 with_test_prefix "collect globals" {
351 prepare_for_trace_test
353 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
355 gdb_test "trace $testline" \
356 "Tracepoint \[0-9\]+ at .*" \
359 # We collect the initial sizeof(pointer) bytes of derived_partial
360 # in an attempt of collecting the vptr. Not portable, but should
361 # work everywhere we need to care.
362 gdb_trace_setactions "define actions" \
364 "collect struct_b.struct_a.array\[2\]" "^$" \
365 "collect struct_b.struct_a.array\[100\]" "^$" \
370 "collect tarray\[0\].a" "^$" \
371 "collect tarray\[1\].a" "^$" \
372 "collect tarray\[3\].a" "^$" \
373 "collect tarray\[3\].b" "^$" \
374 "collect tarray\[4\].b" "^$" \
375 "collect tarray\[5\].b" "^$" \
377 "collect g_string_p" "^$" \
378 "collect g_string_partial\[1\]" "^$" \
379 "collect g_string_partial\[2\]" "^$" \
381 "collect g_structref_p" "^$" \
383 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
384 "collect derived_whole" "^$" \
386 "collect virtual_partial.z" "^$"
389 run_trace_experiment globals_test_func
391 gdb_test "print globalc" " = <unavailable>"
392 gdb_test "print globali" " = <unavailable>"
393 gdb_test "print globalf" " = <unavailable>"
394 gdb_test "print globald" " = <unavailable>"
396 gdb_test "print globalstruct.memberc" " = <unavailable>"
397 gdb_test "print globalstruct.memberi" " = <unavailable>"
398 gdb_test "print globalstruct.memberf" " = <unavailable>"
399 gdb_test "print globalstruct.memberd" " = <unavailable>"
401 gdb_test "print globalstruct" \
402 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
404 gdb_test "print globalp == &globalstruct" \
405 "value is not available" \
406 "can't compare using non collected global pointer"
408 gdb_test "print globalarr\[1\]" " = <unavailable>"
409 gdb_test "print globalarr\[2\]" " = <unavailable>"
410 gdb_test "print globalarr\[3\]" " = <unavailable>"
412 gdb_test "print struct_b" \
413 " = {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>}"
415 gdb_test "print /x struct_b" \
416 " = {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>}"
418 gdb_test "print /x struct_b.struct_a" \
419 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
421 gdb_test "print /x struct_b.struct_a.array" \
422 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
424 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
426 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
428 # Check the target doesn't overcollect. GDB used to merge memory
429 # ranges to collect if they were close enough (collecting the hole
430 # as well), but does not do that anymore. It's plausible that a
431 # target may do this on its end, but as of this writing, no known
433 gdb_test "print {a, b, c}" \
434 " = \\{1, <unavailable>, 3\\}" \
435 "No overcollect of almost but not quite adjacent memory ranges"
437 # Check <unavailable> isn't confused with 0 in array element repetitions
439 gdb_test_no_output "set print repeat 1"
441 gdb_test "print /x tarray" \
442 " = \{\{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>\}" \
443 "<unavailable> is not the same as 0 in array element repetitions"
445 gdb_test_no_output "set print repeat 10"
447 # Check that value repeat handles unavailable-ness.
448 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
452 gdb_test "print struct_b.static_struct_a" \
453 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
457 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
461 gdb_test "print g_int" " = <unavailable>"
463 gdb_test "print g_ref" \
464 "\\(int &\\) @$hex: <unavailable>" \
465 "global reference shows address but not value"
467 gdb_test "print *&g_ref" \
468 "\\$\[0-9\]+ = <unavailable>$cr" \
469 "referenced integer was not collected (taking address of reference)"
471 gdb_test "print *g_structref_p" \
472 " = {d = <unavailable>, ref = <unavailable>}"
476 # Const string is always available, even when not collected.
477 gdb_test "print g_const_string" \
478 " = \"hello world\"$cr" \
479 "non collected const string is still printable"
481 gdb_test "print g_string_p" \
482 " = $hex <g_const_string> \"hello world\"" \
483 "printing constant string through collected pointer"
485 gdb_test "print g_string_unavail" \
486 " = \{<unavailable> <repeats 12 times>\}" \
487 "printing non collected string"
489 # Incomplete strings print as an array.
490 gdb_test "print g_string_partial" \
491 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
492 "printing partially collected string"
494 # It is important for this test that the last examined value is
495 # <unavailable>, to exercise the case of the $__ convenience
496 # variable being set to <unavailable> without error.
497 set msg "examining partially collected object"
498 gdb_test_multiple "x /10x &struct_b" "$msg" {
499 -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 $" {
502 -re "value is not available" {
507 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
509 # This tests that building the array does not require accessing
511 gdb_test "print { 1, g_int, 3 }" \
512 " = \\{1, <unavailable>, 3\\}" \
513 "build array from unavailable value"
515 # Note, depends on previous test.
516 gdb_test "print \$\[1\]" \
518 "subscript a non-memory rvalue array, accessing an unvailable element"
520 # Access a field of a non-lazy value, making sure the
521 # unavailable-ness is propagated. History values are easy
522 # non-lazy values, so use those. The first test just sets up for
524 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
525 gdb_test "print \$.member" " = <unavailable>"
527 # Cast to baseclass, checking the unavailable-ness is propagated.
528 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
530 # Same cast, but starting from a non-lazy, value.
531 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
532 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
534 gdb_test_no_output "set print object on"
536 with_test_prefix "print object on" {
537 # With print object on, printing a pointer may need to fetch
538 # the pointed-to object, to check its run-time type. Make
539 # sure that fails gracefully and transparently when the
540 # pointer itself is unavailable.
541 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
543 # no vtable pointer available
544 gdb_test "print derived_unavail" \
545 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
547 # vtable pointer available, but nothing else
548 gdb_test "print derived_partial" \
549 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
551 # whole object available
552 gdb_test "print derived_whole" \
553 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
556 gdb_test_no_output "set print object off"
558 with_test_prefix "print object off" {
559 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
561 # no vtable pointer available
562 gdb_test "print derived_unavail" \
563 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
565 # vtable pointer available, but nothing else
566 gdb_test "print derived_partial" \
567 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
569 # whole object available
570 gdb_test "print derived_whole" \
571 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
574 # An instance of a virtual class where we collected everything but
576 gdb_test "print virtual_partial" \
577 " = {_vptr.Virtual = <unavailable>, z = 0}"
579 gdb_test "tfind none" \
581 "cease trace debugging"
585 proc gdb_trace_collection_test {} {
586 gdb_collect_globals_test
587 gdb_unavailable_registers_test
588 gdb_unavailable_floats
590 gdb_collect_args_test
591 gdb_collect_locals_test local_test_func "auto locals"
592 gdb_collect_locals_test reglocal_test_func "register locals"
593 gdb_collect_locals_test statlocal_test_func "static locals"
598 if { ![gdb_target_supports_trace] } then {
599 unsupported "Current target does not support trace"
603 # Body of test encased in a proc so we can return prematurely.
604 gdb_trace_collection_test
607 gdb_test "tfind none" ".*" ""