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" " = <unavailable>"
174 gdb_test "print argstruct.memberc" " = <unavailable>"
175 gdb_test "print argstruct.memberi" " = <unavailable>"
176 gdb_test "print argstruct.memberf" " = <unavailable>"
177 gdb_test "print argstruct.memberd" " = <unavailable>"
179 gdb_test "print argarray" " = <unavailable>"
181 gdb_test "print &argarray" \
182 "Can't take address of \"argarray\" which isn't an lvalue\."
184 gdb_test "print argarray\[0\]" "value is not available"
188 set r "${r}argc = <unavailable>${cr}"
189 set r "${r}argi = <unavailable>${cr}"
190 set r "${r}argf = <unavailable>${cr}"
191 set r "${r}argd = <unavailable>${cr}"
192 set r "${r}argstruct = <unavailable>${cr}"
193 set r "${r}argarray = <unavailable>${cr}"
194 gdb_test "info args" "$r" "info args"
196 test_maybe_regvar_display "argc"
198 gdb_test "tfind none" \
200 "cease trace debugging"
204 proc gdb_collect_locals_test { func msg } {
205 with_test_prefix "unavailable locals: $msg" {
209 prepare_for_trace_test
211 set testline [gdb_get_line_number "set $func tracepoint here"]
213 gdb_test "trace $testline" \
214 "Tracepoint \[0-9\]+ at .*" \
218 run_trace_experiment $func
220 gdb_test "print locc" " = <unavailable>"
221 gdb_test "print loci" " = <unavailable>"
222 gdb_test "print locf" " = <unavailable>"
223 gdb_test "print locd" " = <unavailable>"
225 gdb_test "print locst.memberc" " = <unavailable>"
226 gdb_test "print locst.memberi" " = <unavailable>"
227 gdb_test "print locst.memberf" " = <unavailable>"
228 gdb_test "print locst.memberd" " = <unavailable>"
230 gdb_test "print locar\[0\]" " = <unavailable>"
231 gdb_test "print locar\[1\]" " = <unavailable>"
232 gdb_test "print locar\[2\]" " = <unavailable>"
233 gdb_test "print locar\[3\]" " = <unavailable>"
237 set r "${r}locf = <unavailable>${cr}"
238 set r "${r}locd = <unavailable>${cr}"
239 set r "${r}locst = <unavailable>${cr}"
240 set r "${r}locar = <unavailable>${cr}"
241 set r "${r}i = <unavailable>${cr}"
242 if { $func == "local_test_func" } {
243 set r "${r}locdefst = <unavailable>${cr}"
245 set r "${r}locc = <unavailable>${cr}"
246 set r "${r}loci = <unavailable>${cr}"
247 gdb_test "info locals" "$r" "info locals"
249 test_maybe_regvar_display "loci"
251 gdb_test "tfind none" \
253 "cease trace debugging"
257 proc gdb_unavailable_registers_test { } {
258 with_test_prefix "unavailable registers" {
263 prepare_for_trace_test
265 # We'll simply re-use the globals_test_function for this test
266 gdb_test "trace globals_test_func" \
267 "Tracepoint \[0-9\]+ at .*" \
273 run_trace_experiment globals_test_func
275 # On some archs, the $sp/$pc are a real raw registers. On others,
276 # like x86, they're user registers. Test both variants.
277 test_register_unavailable "\$$spreg"
278 test_register_unavailable "\$sp"
280 # Test reading uncollected pseudo-registers. The set of which
282 if [is_amd64_regs_target] {
283 # Check the raw register first.
284 test_register_unavailable "\$rax"
285 test_register_unavailable "\$eax"
286 test_register_unavailable "\$ax"
287 } elseif [is_x86_like_target] {
288 # Check the raw register first.
289 test_register_unavailable "\$eax"
290 test_register_unavailable "\$ax"
293 # GDBserver always provides the PC value of regular tracepoint
294 # hits, since it's the same as the tracepoint's address.
295 test_register "\$$pcreg"
298 gdb_test "info registers" \
299 "<unavailable>.*<unavailable>" \
300 "info registers, multiple registers not available"
302 gdb_test "info registers \$$spreg" \
304 "info registers \$$spreg reports not available"
306 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
310 proc gdb_unavailable_floats { } {
313 with_test_prefix "unavailable floats" {
314 prepare_for_trace_test
316 # We'll simply re-use the globals_test_function for this test
317 gdb_test "trace globals_test_func" \
318 "Tracepoint \[0-9\]+ at .*" \
324 run_trace_experiment globals_test_func
326 # Necessarily target specific.
327 if {[istarget "x86_64-*-*"] || [istarget i?86-*]} {
328 send_gdb "info float\n"
329 gdb_expect_list "info float" ".*$gdb_prompt $" {
330 "Status Word: <unavailable>"
331 "Control Word: <unavailable>"
332 "Tag Word: <unavailable>"
333 "Instruction Pointer: <unavailable>:<unavailable>"
334 "Operand Pointer: <unavailable>:<unavailable>"
335 "Opcode: <unavailable>"
339 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
343 proc gdb_collect_globals_test { } {
344 with_test_prefix "collect globals" {
350 prepare_for_trace_test
352 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
354 gdb_test "trace $testline" \
355 "Tracepoint \[0-9\]+ at .*" \
358 # We collect the initial sizeof(pointer) bytes of derived_partial
359 # in an attempt of collecting the vptr. Not portable, but should
360 # work everywhere we need to care.
361 gdb_trace_setactions "define actions" \
363 "collect struct_b.struct_a.array\[2\]" "^$" \
364 "collect struct_b.struct_a.array\[100\]" "^$" \
369 "collect tarray\[0\].a" "^$" \
370 "collect tarray\[1\].a" "^$" \
371 "collect tarray\[3\].a" "^$" \
372 "collect tarray\[3\].b" "^$" \
373 "collect tarray\[4\].b" "^$" \
374 "collect tarray\[5\].b" "^$" \
376 "collect g_string_p" "^$" \
377 "collect g_string_partial\[1\]" "^$" \
378 "collect g_string_partial\[2\]" "^$" \
380 "collect g_structref_p" "^$" \
382 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
383 "collect derived_whole" "^$" \
385 "collect virtual_partial.z" "^$"
388 run_trace_experiment globals_test_func
390 gdb_test "print globalc" " = <unavailable>"
391 gdb_test "print globali" " = <unavailable>"
392 gdb_test "print globalf" " = <unavailable>"
393 gdb_test "print globald" " = <unavailable>"
395 gdb_test "print globalstruct.memberc" " = <unavailable>"
396 gdb_test "print globalstruct.memberi" " = <unavailable>"
397 gdb_test "print globalstruct.memberf" " = <unavailable>"
398 gdb_test "print globalstruct.memberd" " = <unavailable>"
400 gdb_test "print globalstruct" " = <unavailable>"
402 gdb_test "print globalp == &globalstruct" \
403 "value is not available" \
404 "can't compare using non collected global pointer"
406 gdb_test "print globalarr\[1\]" " = <unavailable>"
407 gdb_test "print globalarr\[2\]" " = <unavailable>"
408 gdb_test "print globalarr\[3\]" " = <unavailable>"
410 gdb_test "print struct_b" \
411 " = {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>}"
413 gdb_test "print /x struct_b" \
414 " = {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>}"
416 gdb_test "print /x struct_b.struct_a" \
417 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
419 gdb_test "print /x struct_b.struct_a.array" \
420 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
422 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
424 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
426 # Check the target doesn't overcollect. GDB used to merge memory
427 # ranges to collect if they were close enough (collecting the hole
428 # as well), but does not do that anymore. It's plausible that a
429 # target may do this on its end, but as of this writing, no known
431 gdb_test "print {a, b, c}" \
432 " = \\{1, <unavailable>, 3\\}" \
433 "No overcollect of almost but not quite adjacent memory ranges"
435 # Check <unavailable> isn't confused with 0 in array element repetitions
437 gdb_test_no_output "set print repeat 1"
439 gdb_test "print /x tarray" \
440 " = \{\{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>\}" \
441 "<unavailable> is not the same as 0 in array element repetitions"
443 gdb_test_no_output "set print repeat 10"
445 # Check that value repeat handles unavailable-ness.
446 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
450 gdb_test "print struct_b.static_struct_a" " = <unavailable>"
454 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
458 gdb_test "print g_int" " = <unavailable>"
460 gdb_test "print g_ref" \
461 "\\(int &\\) @$hex: <unavailable>" \
462 "global reference shows address but not value"
464 gdb_test "print *&g_ref" \
465 "\\$\[0-9\]+ = <unavailable>$cr" \
466 "referenced integer was not collected (taking address of reference)"
468 gdb_test "print *g_structref_p" " = <unavailable>"
472 # Const string is always available, even when not collected.
473 gdb_test "print g_const_string" \
474 " = \"hello world\"$cr" \
475 "non collected const string is still printable"
477 gdb_test "print g_string_p" \
478 " = $hex <g_const_string> \"hello world\"" \
479 "printing constant string through collected pointer"
481 gdb_test "print g_string_unavail" \
483 "printing non collected string"
485 # Incomplete strings print as an array.
486 gdb_test "print g_string_partial" \
487 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
488 "printing partially collected string"
490 # It is important for this test that the last examined value is
491 # <unavailable>, to exercise the case of the $__ convenience
492 # variable being set to <unavailable> without error.
493 set msg "examining partially collected object"
494 gdb_test_multiple "x /10x &struct_b" "$msg" {
495 -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 $" {
498 -re "value is not available" {
503 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
505 # This tests that building the array does not require accessing
507 gdb_test "print { 1, g_int, 3 }" \
508 " = \\{1, <unavailable>, 3\\}" \
509 "build array from unavailable value"
511 # Note, depends on previous test.
512 gdb_test "print \$\[1\]" \
514 "subscript a non-memory rvalue array, accessing an unvailable element"
516 # Access a field of a non-lazy value, making sure the
517 # unavailable-ness is propagated. History values are easy
518 # non-lazy values, so use those. The first test just sets up for
520 gdb_test "print g_smallstruct" " = <unavailable>"
521 gdb_test "print \$.member" " = <unavailable>"
523 # Cast to baseclass, checking the unavailable-ness is propagated.
524 gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>"
526 # Same cast, but starting from a non-lazy, value.
527 gdb_test "print g_smallstruct_b" " = <unavailable>"
528 gdb_test "print (small_struct) \$" " = <unavailable>"
530 gdb_test_no_output "set print object on"
532 with_test_prefix "print object on" {
533 # With print object on, printing a pointer may need to fetch
534 # the pointed-to object, to check its run-time type. Make
535 # sure that fails gracefully and transparently when the
536 # pointer itself is unavailable.
537 gdb_test "print virtualp" " = <unavailable>"
539 # no vtable pointer available
540 gdb_test "print derived_unavail" " = <unavailable>"
542 # vtable pointer available, but nothing else
543 gdb_test "print derived_partial" \
544 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
546 # whole object available
547 gdb_test "print derived_whole" \
548 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
551 gdb_test_no_output "set print object off"
553 with_test_prefix "print object off" {
554 gdb_test "print virtualp" " = <unavailable>"
556 # no vtable pointer available
557 gdb_test "print derived_unavail" \
560 # vtable pointer available, but nothing else
561 gdb_test "print derived_partial" \
562 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}"
564 # whole object available
565 gdb_test "print derived_whole" \
566 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}"
569 # An instance of a virtual class where we collected everything but
571 gdb_test "print virtual_partial" \
572 " = {_vptr.Virtual = <unavailable>, z = 0}"
574 gdb_test "tfind none" \
576 "cease trace debugging"
580 proc gdb_trace_collection_test {} {
581 gdb_collect_globals_test
582 gdb_unavailable_registers_test
583 gdb_unavailable_floats
585 gdb_collect_args_test
586 gdb_collect_locals_test local_test_func "auto locals"
587 gdb_collect_locals_test reglocal_test_func "register locals"
588 gdb_collect_locals_test statlocal_test_func "static locals"
593 if { ![gdb_target_supports_trace] } then {
594 unsupported "Current target does not support trace"
598 # Body of test encased in a proc so we can return prematurely.
599 gdb_trace_collection_test
602 gdb_test "tfind none" ".*" ""