1 # Copyright 1998, 2005, 2007-2012 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 set testfile "unavailable"
19 set srcfile ${testfile}.cc
20 set executable $testfile
21 set binfile $objdir/$subdir/$executable
23 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
24 executable {debug nowarnings c++}] != "" } {
25 untested unavailable.exp
32 if [is_amd64_regs_target] {
36 } elseif [is_x86_like_target] {
50 proc test_register { reg } {
55 gdb_test_multiple "print /x $reg" "collected $reg" {
56 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
57 fail "collected $reg (zero)"
59 -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
62 -re "\[Ee\]rror.*$gdb_prompt $" {
63 fail "collected $reg (error)"
68 proc test_register_unavailable { reg } {
69 gdb_test "print /x $reg" \
71 "correctly report $reg as unavailable"
74 proc prepare_for_trace_test {} {
77 clean_restart $executable
81 gdb_test "break begin" ".*" ""
82 gdb_test "break end" ".*" ""
85 proc run_trace_experiment { test_func } {
89 ".*Breakpoint \[0-9\]+, begin .*" \
92 gdb_test_no_output "tstart" "start trace experiment"
95 "Continuing.*Breakpoint \[0-9\]+, end.*" \
96 "run trace experiment"
99 "stop trace experiment"
100 gdb_test "tfind start" \
105 # Test that "display VAR" works as expected, assuming VAR is wholly
108 proc test_maybe_regvar_display { var } {
111 # Evaluating VAR's location description may throw an internal
112 # "unavailable" exception, if for example, the value of a register
113 # necessary for computing VAR's location is unavailable. Such an
114 # exception is caught, and should not cause automatic disablement
115 # of the current display being printed. (GDB used to disable the
116 # current display whenever any exception was thrown.)
117 set test "display $var"
118 gdb_test_multiple "$test" "$test" {
119 -re "Disabling display ? to avoid infinite recursion.*$gdb_prompt $" {
122 -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
126 gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
130 "delete $var display" \
131 ".*Delete all auto-display expressions.*y or n. $" \
139 proc gdb_collect_args_test {} { with_test_prefix "unavailable arguments" {
143 prepare_for_trace_test
145 gdb_test "trace args_test_func" \
146 "Tracepoint \[0-9\]+ at .*" \
150 run_trace_experiment args_test_func
152 # Test printing the variables, and also their addresses. We
153 # haven't collected any stack, so there's no way GDB can figure
156 gdb_test "print argc" " = <unavailable>"
157 gdb_test "print &argc" \
158 "Can't take address of \"argc\" which isn't an lvalue\."
160 gdb_test "print argi" " = <unavailable>"
161 gdb_test "print &argi" \
162 "Can't take address of \"argi\" which isn't an lvalue\."
164 gdb_test "print argf" " = <unavailable>"
165 gdb_test "print &argf" \
166 "Can't take address of \"argf\" which isn't an lvalue\."
168 gdb_test "print argd" " = <unavailable>"
169 gdb_test "print &argd" \
170 "Can't take address of \"argd\" which isn't an lvalue\."
172 # struct arg as one of several args (near end of list)
174 gdb_test "print argstruct" \
175 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
177 gdb_test "print argstruct.memberc" " = <unavailable>"
178 gdb_test "print argstruct.memberi" " = <unavailable>"
179 gdb_test "print argstruct.memberf" " = <unavailable>"
180 gdb_test "print argstruct.memberd" " = <unavailable>"
182 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
184 gdb_test "print &argarray" \
185 "Can't take address of \"argarray\" which isn't an lvalue\."
187 gdb_test "print argarray\[0\]" "value is not available"
191 set r "${r}argc = <unavailable>${cr}"
192 set r "${r}argi = <unavailable>${cr}"
193 set r "${r}argf = <unavailable>${cr}"
194 set r "${r}argd = <unavailable>${cr}"
195 set r "${r}argstruct = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
196 set r "${r}argarray = <unavailable>${cr}"
197 gdb_test "info args" "$r" "info args"
199 test_maybe_regvar_display "argc"
201 gdb_test "tfind none" \
203 "cease trace debugging"
206 proc gdb_collect_locals_test { func msg } { 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"
257 proc gdb_unavailable_registers_test { } { with_test_prefix "unavailable registers" {
262 prepare_for_trace_test
264 # We'll simply re-use the globals_test_function for this test
265 gdb_test "trace globals_test_func" \
266 "Tracepoint \[0-9\]+ at .*" \
272 run_trace_experiment globals_test_func
274 # On some archs, the $sp/$pc are a real raw registers. On others,
275 # like x86, they're user registers. Test both variants.
276 test_register_unavailable "\$$spreg"
277 test_register_unavailable "\$sp"
279 # Test reading uncollected pseudo-registers. The set of which
281 if [is_amd64_regs_target] {
282 # Check the raw register first.
283 test_register_unavailable "\$rax"
284 test_register_unavailable "\$eax"
285 test_register_unavailable "\$ax"
286 } elseif [is_x86_like_target] {
287 # Check the raw register first.
288 test_register_unavailable "\$eax"
289 test_register_unavailable "\$ax"
292 # GDBserver always provides the PC value of regular tracepoint
293 # hits, since it's the same as the tracepoint's address.
294 test_register "\$$pcreg"
297 gdb_test "info registers" \
298 "\\*value not available\\*.*\\*value not available\\*" \
299 "info registers, multiple registers not available"
301 gdb_test "info registers \$$spreg" \
302 "\\*value not available\\*" \
303 "info registers \$$spreg reports not available"
305 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
308 proc gdb_collect_globals_test { } { with_test_prefix "collect globals" {
314 prepare_for_trace_test
316 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
318 gdb_test "trace $testline" \
319 "Tracepoint \[0-9\]+ at .*" \
322 # We collect the initial sizeof(pointer) bytes of derived_partial
323 # in an attempt of collecting the vptr. Not portable, but should
324 # work everywhere we need to care.
325 gdb_trace_setactions "define actions" \
327 "collect struct_b.struct_a.array\[2\]" "^$" \
328 "collect struct_b.struct_a.array\[100\]" "^$" \
333 "collect tarray\[0\].a" "^$" \
334 "collect tarray\[1\].a" "^$" \
335 "collect tarray\[3\].a" "^$" \
336 "collect tarray\[3\].b" "^$" \
337 "collect tarray\[4\].b" "^$" \
338 "collect tarray\[5\].b" "^$" \
340 "collect g_string_p" "^$" \
341 "collect g_string_partial\[1\]" "^$" \
342 "collect g_string_partial\[2\]" "^$" \
344 "collect g_structref_p" "^$" \
346 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
347 "collect derived_whole" "^$" \
349 "collect virtual_partial.z" "^$"
352 run_trace_experiment globals_test_func
354 gdb_test "print globalc" " = <unavailable>"
355 gdb_test "print globali" " = <unavailable>"
356 gdb_test "print globalf" " = <unavailable>"
357 gdb_test "print globald" " = <unavailable>"
359 gdb_test "print globalstruct.memberc" " = <unavailable>"
360 gdb_test "print globalstruct.memberi" " = <unavailable>"
361 gdb_test "print globalstruct.memberf" " = <unavailable>"
362 gdb_test "print globalstruct.memberd" " = <unavailable>"
364 gdb_test "print globalstruct" \
365 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
367 gdb_test "print globalp == &globalstruct" \
368 "value is not available" \
369 "can't compare using non collected global pointer"
371 gdb_test "print globalarr\[1\]" " = <unavailable>"
372 gdb_test "print globalarr\[2\]" " = <unavailable>"
373 gdb_test "print globalarr\[3\]" " = <unavailable>"
375 gdb_test "print struct_b" \
376 " = {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>}"
378 gdb_test "print /x struct_b" \
379 " = {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>}"
381 gdb_test "print /x struct_b.struct_a" \
382 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
384 gdb_test "print /x struct_b.struct_a.array" \
385 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
387 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
389 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
391 # Check the target doesn't overcollect. GDB used to merge memory
392 # ranges to collect if they were close enough (collecting the hole
393 # as well), but does not do that anymore. It's plausible that a
394 # target may do this on its end, but as of this writing, no known
396 gdb_test "print {a, b, c}" \
397 " = \\{1, <unavailable>, 3\\}" \
398 "No overcollect of almost but not quite adjacent memory ranges"
400 # Check <unavailable> isn't confused with 0 in array element repetitions
402 gdb_test_no_output "set print repeat 1"
404 gdb_test "print /x tarray" \
405 " = \{\{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>\}" \
406 "<unavailable> is not the same as 0 in array element repetitions"
408 gdb_test_no_output "set print repeat 10"
410 # Check that value repeat handles unavailable-ness.
411 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
415 gdb_test "print struct_b.static_struct_a" \
416 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
420 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
424 gdb_test "print g_int" " = <unavailable>"
426 gdb_test "print g_ref" \
427 "\\(int &\\) @$hex: <unavailable>" \
428 "global reference shows address but not value"
430 gdb_test "print *&g_ref" \
431 "\\$\[0-9\]+ = <unavailable>$cr" \
432 "referenced integer was not collected (taking address of reference)"
434 gdb_test "print *g_structref_p" \
435 " = {d = <unavailable>, ref = <unavailable>}"
439 # Const string is always available, even when not collected.
440 gdb_test "print g_const_string" \
441 " = \"hello world\"$cr" \
442 "non collected const string is still printable"
444 gdb_test "print g_string_p" \
445 " = $hex \"hello world\"" \
446 "printing constant string through collected pointer"
448 gdb_test "print g_string_unavail" \
449 " = \{<unavailable> <repeats 12 times>\}" \
450 "printing non collected string"
452 # Incomplete strings print as an array.
453 gdb_test "print g_string_partial" \
454 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
455 "printing partially collected string"
457 # It is important for this test that the last examined value is
458 # <unavailable>, to exercise the case of the $__ convenience
459 # variable being set to <unavailable> without error.
460 set msg "examining partially collected object"
461 gdb_test_multiple "x /10x &struct_b" "$msg" {
462 -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 $" {
465 -re "value is not available" {
470 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
472 # This tests that building the array does not require accessing
474 gdb_test "print { 1, g_int, 3 }" \
475 " = \\{1, <unavailable>, 3\\}" \
476 "build array from unavailable value"
478 # Note, depends on previous test.
479 gdb_test "print \$\[1\]" \
481 "subscript a non-memory rvalue array, accessing an unvailable element"
483 # Access a field of a non-lazy value, making sure the
484 # unavailable-ness is propagated. History values are easy
485 # non-lazy values, so use those. The first test just sets up for
487 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
488 gdb_test "print \$.member" " = <unavailable>"
490 # Cast to baseclass, checking the unavailable-ness is propagated.
491 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
493 # Same cast, but starting from a non-lazy, value.
494 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
495 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
497 gdb_test_no_output "set print object on"
500 set old_pf_prefix $pf_prefix
501 append pf_prefix " print object on:"
503 # With print object on, printing a pointer may need to fetch the
504 # pointed-to object, to check its run-time type. Make sure that
505 # fails gracefully and transparently when the pointer itself is
507 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
509 # no vtable pointer available
510 gdb_test "print derived_unavail" \
511 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
513 # vtable pointer available, but nothing else
514 gdb_test "print derived_partial" \
515 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
517 # whole object available
518 gdb_test "print derived_whole" \
519 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
521 set pf_prefix $old_pf_prefix
523 gdb_test_no_output "set print object off"
525 append pf_prefix " print object off:"
527 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
529 # no vtable pointer available
530 gdb_test "print derived_unavail" \
531 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
533 # vtable pointer available, but nothing else
534 gdb_test "print derived_partial" \
535 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
537 # whole object available
538 gdb_test "print derived_whole" \
539 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
541 set pf_prefix $old_pf_prefix
543 # An instance of a virtual class where we collected everything but
545 gdb_test "print virtual_partial" \
546 " = {_vptr.Virtual = <unavailable>, z = 0}"
548 gdb_test "tfind none" \
550 "cease trace debugging"
553 proc gdb_trace_collection_test {} {
554 gdb_collect_globals_test
555 gdb_unavailable_registers_test
557 gdb_collect_args_test
558 gdb_collect_locals_test local_test_func "auto locals"
559 gdb_collect_locals_test reglocal_test_func "register locals"
560 gdb_collect_locals_test statlocal_test_func "static locals"
563 clean_restart $executable
566 if { ![gdb_target_supports_trace] } then {
567 unsupported "Current target does not support trace"
571 # Body of test encased in a proc so we can return prematurely.
572 gdb_trace_collection_test
575 gdb_test "tfind none" ".*" ""