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 [istarget "x86_64-*"] then {
37 } elseif [istarget "i?86-*"] then {
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" \
110 proc gdb_collect_args_test {} {
115 set old_pf_prefix $pf_prefix
116 set pf_prefix "$pf_prefix unavailable arguments:"
118 prepare_for_trace_test
120 gdb_test "trace args_test_func" \
121 "Tracepoint \[0-9\]+ at .*" \
125 run_trace_experiment args_test_func
127 # Test printing the variables, and also their addresses. We
128 # haven't collected any stack, so there's no way GDB can figure
131 gdb_test "print argc" " = <unavailable>"
132 gdb_test "print &argc" \
133 "Can't take address of \"argc\" which isn't an lvalue\."
135 gdb_test "print argi" " = <unavailable>"
136 gdb_test "print &argi" \
137 "Can't take address of \"argi\" which isn't an lvalue\."
139 gdb_test "print argf" " = <unavailable>"
140 gdb_test "print &argf" \
141 "Can't take address of \"argf\" which isn't an lvalue\."
143 gdb_test "print argd" " = <unavailable>"
144 gdb_test "print &argd" \
145 "Can't take address of \"argd\" which isn't an lvalue\."
147 # struct arg as one of several args (near end of list)
149 gdb_test "print argstruct" \
150 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
152 gdb_test "print argstruct.memberc" " = <unavailable>"
153 gdb_test "print argstruct.memberi" " = <unavailable>"
154 gdb_test "print argstruct.memberf" " = <unavailable>"
155 gdb_test "print argstruct.memberd" " = <unavailable>"
157 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
159 gdb_test "print &argarray" \
160 "Can't take address of \"argarray\" which isn't an lvalue\."
162 gdb_test "print argarray\[0\]" "value is not available"
166 set r "${r}argc = <unavailable>${cr}"
167 set r "${r}argi = <unavailable>${cr}"
168 set r "${r}argf = <unavailable>${cr}"
169 set r "${r}argd = <unavailable>${cr}"
170 set r "${r}argstruct = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
171 set r "${r}argarray = <unavailable>${cr}"
172 gdb_test "info args" "$r" "info args"
174 gdb_test "tfind none" \
176 "cease trace debugging"
178 set pf_prefix $old_pf_prefix
181 proc gdb_collect_locals_test { func msg } {
186 set old_pf_prefix $pf_prefix
187 set pf_prefix "$pf_prefix unavailable locals: $msg:"
189 prepare_for_trace_test
191 set testline [gdb_get_line_number "set $func tracepoint here"]
193 gdb_test "trace $testline" \
194 "Tracepoint \[0-9\]+ at .*" \
198 run_trace_experiment $func
200 gdb_test "print locc" " = <unavailable>"
201 gdb_test "print loci" " = <unavailable>"
202 gdb_test "print locf" " = <unavailable>"
203 gdb_test "print locd" " = <unavailable>"
205 gdb_test "print locst.memberc" " = <unavailable>"
206 gdb_test "print locst.memberi" " = <unavailable>"
207 gdb_test "print locst.memberf" " = <unavailable>"
208 gdb_test "print locst.memberd" " = <unavailable>"
210 gdb_test "print locar\[0\]" " = <unavailable>"
211 gdb_test "print locar\[1\]" " = <unavailable>"
212 gdb_test "print locar\[2\]" " = <unavailable>"
213 gdb_test "print locar\[3\]" " = <unavailable>"
217 set r "${r}locf = <unavailable>${cr}"
218 set r "${r}locd = <unavailable>${cr}"
219 set r "${r}locst = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
220 set r "${r}locar = {<unavailable>, <unavailable>, <unavailable>, <unavailable>}${cr}"
221 set r "${r}i = <unavailable>${cr}"
222 if { $func == "local_test_func" } {
223 set r "${r}locdefst = {<No data fields>}${cr}"
225 set r "${r}locc = <unavailable>${cr}"
226 set r "${r}loci = <unavailable>${cr}"
227 gdb_test "info locals" "$r" "info locals"
229 gdb_test "tfind none" \
231 "cease trace debugging"
233 set pf_prefix $old_pf_prefix
236 proc gdb_unavailable_registers_test { } {
242 set old_pf_prefix $pf_prefix
243 set pf_prefix "$pf_prefix unavailable registers:"
245 prepare_for_trace_test
247 # We'll simply re-use the globals_test_function for this test
248 gdb_test "trace globals_test_func" \
249 "Tracepoint \[0-9\]+ at .*" \
255 run_trace_experiment globals_test_func
257 # On some archs, the $sp/$pc are a real raw registers. On others,
258 # like x86, they're user registers. Test both variants.
259 test_register_unavailable "\$$spreg"
260 test_register_unavailable "\$sp"
262 # Test reading uncollected pseudo-registers. The set of which
264 if [istarget "x86_64-*"] then {
265 # Check the raw register first.
266 test_register_unavailable "\$rax"
267 test_register_unavailable "\$eax"
268 test_register_unavailable "\$ax"
269 } elseif [istarget "i?86-*"] then {
270 # Check the raw register first.
271 test_register_unavailable "\$eax"
272 test_register_unavailable "\$ax"
275 # GDBserver always provides the PC value of regular tracepoint
276 # hits, since it's the same as the tracepoint's address.
277 test_register "\$$pcreg"
280 gdb_test "info registers" \
281 "\\*value not available\\*.*\\*value not available\\*" \
282 "info registers, multiple registers not available"
284 gdb_test "info registers \$$spreg" \
285 "\\*value not available\\*" \
286 "info registers \$$spreg reports not available"
288 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
290 set pf_prefix $old_pf_prefix
293 proc gdb_collect_globals_test { } {
300 set old_pf_prefix $pf_prefix
301 set pf_prefix "$pf_prefix collect globals:"
303 prepare_for_trace_test
305 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
307 gdb_test "trace $testline" \
308 "Tracepoint \[0-9\]+ at .*" \
311 # We collect the initial sizeof(pointer) bytes of derived_partial
312 # in an attempt of collecting the vptr. Not portable, but should
313 # work everywhere we need to care.
314 gdb_trace_setactions "define actions" \
316 "collect struct_b.struct_a.array\[2\]" "^$" \
317 "collect struct_b.struct_a.array\[100\]" "^$" \
322 "collect tarray\[0\].a" "^$" \
323 "collect tarray\[1\].a" "^$" \
324 "collect tarray\[3\].a" "^$" \
325 "collect tarray\[3\].b" "^$" \
326 "collect tarray\[4\].b" "^$" \
327 "collect tarray\[5\].b" "^$" \
329 "collect g_string_p" "^$" \
330 "collect g_string_partial\[1\]" "^$" \
331 "collect g_string_partial\[2\]" "^$" \
333 "collect g_structref_p" "^$" \
335 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
336 "collect derived_whole" "^$" \
338 "collect virtual_partial.z" "^$"
341 run_trace_experiment globals_test_func
343 gdb_test "print globalc" " = <unavailable>"
344 gdb_test "print globali" " = <unavailable>"
345 gdb_test "print globalf" " = <unavailable>"
346 gdb_test "print globald" " = <unavailable>"
348 gdb_test "print globalstruct.memberc" " = <unavailable>"
349 gdb_test "print globalstruct.memberi" " = <unavailable>"
350 gdb_test "print globalstruct.memberf" " = <unavailable>"
351 gdb_test "print globalstruct.memberd" " = <unavailable>"
353 gdb_test "print globalstruct" \
354 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
356 gdb_test "print globalp == &globalstruct" \
357 "value is not available" \
358 "can't compare using non collected global pointer"
360 gdb_test "print globalarr\[1\]" " = <unavailable>"
361 gdb_test "print globalarr\[2\]" " = <unavailable>"
362 gdb_test "print globalarr\[3\]" " = <unavailable>"
364 gdb_test "print struct_b" \
365 " = {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>}"
367 gdb_test "print /x struct_b" \
368 " = {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>}"
370 gdb_test "print /x struct_b.struct_a" \
371 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
373 gdb_test "print /x struct_b.struct_a.array" \
374 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
376 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
378 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
380 # Check the target doesn't overcollect. GDB used to merge memory
381 # ranges to collect if they were close enough (collecting the hole
382 # as well), but does not do that anymore. It's plausible that a
383 # target may do this on its end, but as of this writing, no known
385 gdb_test "print {a, b, c}" \
386 " = \\{1, <unavailable>, 3\\}" \
387 "No overcollect of almost but not quite adjacent memory ranges"
389 # Check <unavailable> isn't confused with 0 in array element repetitions
391 gdb_test_no_output "set print repeat 1"
393 gdb_test "print /x tarray" \
394 " = \{\{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>\}" \
395 "<unavailable> is not the same as 0 in array element repetitions"
397 gdb_test_no_output "set print repeat 10"
399 # Check that value repeat handles unavailable-ness.
400 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
404 gdb_test "print struct_b.static_struct_a" \
405 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
409 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
413 gdb_test "print g_int" " = <unavailable>"
415 gdb_test "print g_ref" \
416 "\\(int &\\) @$hex: <unavailable>" \
417 "global reference shows address but not value"
419 gdb_test "print *&g_ref" \
420 "\\$\[0-9\]+ = <unavailable>$cr" \
421 "referenced integer was not collected (taking address of reference)"
423 gdb_test "print *g_structref_p" \
424 " = {d = <unavailable>, ref = <unavailable>}"
428 # Const string is always available, even when not collected.
429 gdb_test "print g_const_string" \
430 " = \"hello world\"$cr" \
431 "non collected const string is still printable"
433 gdb_test "print g_string_p" \
434 " = $hex \"hello world\"" \
435 "printing constant string through collected pointer"
437 gdb_test "print g_string_unavail" \
438 " = \{<unavailable> <repeats 12 times>\}" \
439 "printing non collected string"
441 # Incomplete strings print as an array.
442 gdb_test "print g_string_partial" \
443 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
444 "printing partially collected string"
446 # It is important for this test that the last examined value is
447 # <unavailable>, to exercise the case of the $__ convenience
448 # variable being set to <unavailable> without error.
449 set msg "examining partially collected object"
450 gdb_test_multiple "x /10x &struct_b" "$msg" {
451 -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 $" {
454 -re "value is not available" {
459 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
461 # This tests that building the array does not require accessing
463 gdb_test "print { 1, g_int, 3 }" \
464 " = \\{1, <unavailable>, 3\\}" \
465 "build array from unavailable value"
467 # Note, depends on previous test.
468 gdb_test "print \$\[1\]" \
470 "subscript a non-memory rvalue array, accessing an unvailable element"
472 # Access a field of a non-lazy value, making sure the
473 # unavailable-ness is propagated. History values are easy
474 # non-lazy values, so use those. The first test just sets up for
476 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
477 gdb_test "print \$.member" " = <unavailable>"
479 # Cast to baseclass, checking the unavailable-ness is propagated.
480 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
482 # Same cast, but starting from a non-lazy, value.
483 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
484 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
486 gdb_test_no_output "set print object on"
488 set old_pf_prefix_2 $pf_prefix
489 set pf_prefix "$pf_prefix print object on:"
491 # With print object on, printing a pointer may need to fetch the
492 # pointed-to object, to check its run-time type. Make sure that
493 # fails gracefully and transparently when the pointer itself is
495 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
497 # no vtable pointer available
498 gdb_test "print derived_unavail" \
499 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
501 # vtable pointer available, but nothing else
502 gdb_test "print derived_partial" \
503 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
505 # whole object available
506 gdb_test "print derived_whole" \
507 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
509 set pf_prefix $old_pf_prefix_2
511 gdb_test_no_output "set print object off"
513 set pf_prefix "$pf_prefix print object off:"
515 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
517 # no vtable pointer available
518 gdb_test "print derived_unavail" \
519 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
521 # vtable pointer available, but nothing else
522 gdb_test "print derived_partial" \
523 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
525 # whole object available
526 gdb_test "print derived_whole" \
527 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
529 set pf_prefix $old_pf_prefix_2
531 # An instance of a virtual class where we collected everything but
533 gdb_test "print virtual_partial" \
534 " = {_vptr.Virtual = <unavailable>, z = 0}"
536 gdb_test "tfind none" \
538 "cease trace debugging"
540 set pf_prefix $old_pf_prefix
543 proc gdb_trace_collection_test {} {
544 gdb_collect_globals_test
545 gdb_unavailable_registers_test
547 gdb_collect_args_test
548 gdb_collect_locals_test local_test_func "auto locals"
549 gdb_collect_locals_test reglocal_test_func "register locals"
550 gdb_collect_locals_test statlocal_test_func "static locals"
553 clean_restart $executable
556 # We generously give ourselves one "pass" if we successfully
557 # detect that this test cannot be run on this target!
558 if { ![gdb_target_supports_trace] } then {
559 pass "Current target does not support trace"
563 # Body of test encased in a proc so we can return prematurely.
564 gdb_trace_collection_test
567 gdb_test "tfind none" ".*" ""