]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/unavailable.exp
7278ebf8558d173131347c2cb8ea2ccf79a193a9
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / unavailable.exp
1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
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.
8 #
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.
13 #
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/>.
16
17 load_lib "trace-support.exp"
18
19 set testfile "unavailable"
20 set srcfile ${testfile}.cc
21 set executable $testfile
22 set binfile $objdir/$subdir/$executable
23
24 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
25 executable {debug nowarnings c++}] != "" } {
26 untested unavailable.exp
27 return -1
28 }
29
30 set ws "\[\r\n\t \]+"
31 set cr "\[\r\n\]+"
32
33 if [is_amd64_regs_target] {
34 set fpreg "rbp"
35 set spreg "rsp"
36 set pcreg "rip"
37 } elseif [is_x86_like_target] {
38 set fpreg "ebp"
39 set spreg "esp"
40 set pcreg "eip"
41 } else {
42 set fpreg "fp"
43 set spreg "sp"
44 set pcreg "pc"
45 }
46
47 #
48 # Utility procs
49 #
50
51 proc test_register { reg } {
52 global gdb_prompt
53 global hex
54 global cr
55
56 gdb_test_multiple "print /x $reg" "collected $reg" {
57 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
58 fail "collected $reg (zero)"
59 }
60 -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
61 pass "collected $reg"
62 }
63 -re "\[Ee\]rror.*$gdb_prompt $" {
64 fail "collected $reg (error)"
65 }
66 }
67 }
68
69 proc test_register_unavailable { reg } {
70 gdb_test "print /x $reg" \
71 "<unavailable>" \
72 "correctly report $reg as unavailable"
73 }
74
75 proc prepare_for_trace_test {} {
76 global executable
77
78 clean_restart $executable
79
80 runto_main
81
82 gdb_test "break begin" ".*" ""
83 gdb_test "break end" ".*" ""
84 }
85
86 proc run_trace_experiment { test_func } {
87 global gdb_prompt
88
89 gdb_test "continue" \
90 ".*Breakpoint \[0-9\]+, begin .*" \
91 "advance to begin"
92
93 gdb_test_no_output "tstart" "start trace experiment"
94
95 gdb_test "continue" \
96 "Continuing.*Breakpoint \[0-9\]+, end.*" \
97 "run trace experiment"
98 gdb_test "tstop" \
99 "\[\r\n\]+" \
100 "stop trace experiment"
101 gdb_test "tfind start" \
102 "#0 $test_func .*" \
103 "tfind test frame"
104 }
105
106 # Test that "display VAR" works as expected, assuming VAR is wholly
107 # unavailable.
108
109 proc test_maybe_regvar_display { var } {
110 global gdb_prompt
111
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 $" {
121 fail "$test"
122 }
123 -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
124 pass "$test"
125 }
126 }
127 gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
128
129 gdb_test "undisp" \
130 "" \
131 "delete $var display" \
132 ".*Delete all auto-display expressions.*y or n. $" \
133 "y"
134 }
135
136 #
137 # Test procs
138 #
139
140 proc gdb_collect_args_test {} {
141 global cr
142 global gdb_prompt
143 global pf_prefix
144
145 set old_pf_prefix $pf_prefix
146 set pf_prefix "$pf_prefix unavailable arguments:"
147
148 prepare_for_trace_test
149
150 gdb_test "trace args_test_func" \
151 "Tracepoint \[0-9\]+ at .*" \
152 "set tracepoint"
153
154 # Begin the test.
155 run_trace_experiment args_test_func
156
157 # Test printing the variables, and also their addresses. We
158 # haven't collected any stack, so there's no way GDB can figure
159 # out the latter.
160
161 gdb_test "print argc" " = <unavailable>"
162 gdb_test "print &argc" \
163 "Can't take address of \"argc\" which isn't an lvalue\."
164
165 gdb_test "print argi" " = <unavailable>"
166 gdb_test "print &argi" \
167 "Can't take address of \"argi\" which isn't an lvalue\."
168
169 gdb_test "print argf" " = <unavailable>"
170 gdb_test "print &argf" \
171 "Can't take address of \"argf\" which isn't an lvalue\."
172
173 gdb_test "print argd" " = <unavailable>"
174 gdb_test "print &argd" \
175 "Can't take address of \"argd\" which isn't an lvalue\."
176
177 # struct arg as one of several args (near end of list)
178
179 gdb_test "print argstruct" \
180 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
181
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>"
186
187 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
188
189 gdb_test "print &argarray" \
190 "Can't take address of \"argarray\" which isn't an lvalue\."
191
192 gdb_test "print argarray\[0\]" "value is not available"
193
194 # Test "info args"
195 set r ""
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"
203
204 test_maybe_regvar_display "argc"
205
206 gdb_test "tfind none" \
207 "#0 end .*" \
208 "cease trace debugging"
209
210 set pf_prefix $old_pf_prefix
211 }
212
213 proc gdb_collect_locals_test { func msg } {
214 global cr
215 global gdb_prompt
216 global pf_prefix
217
218 set old_pf_prefix $pf_prefix
219 set pf_prefix "$pf_prefix unavailable locals: $msg:"
220
221 prepare_for_trace_test
222
223 set testline [gdb_get_line_number "set $func tracepoint here"]
224
225 gdb_test "trace $testline" \
226 "Tracepoint \[0-9\]+ at .*" \
227 "set tracepoint"
228
229 # Begin the test.
230 run_trace_experiment $func
231
232 gdb_test "print locc" " = <unavailable>"
233 gdb_test "print loci" " = <unavailable>"
234 gdb_test "print locf" " = <unavailable>"
235 gdb_test "print locd" " = <unavailable>"
236
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>"
241
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>"
246
247 # Test "info locals"
248 set r ""
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}"
256 }
257 set r "${r}locc = <unavailable>${cr}"
258 set r "${r}loci = <unavailable>${cr}"
259 gdb_test "info locals" "$r" "info locals"
260
261 test_maybe_regvar_display "loci"
262
263 gdb_test "tfind none" \
264 "#0 end .*" \
265 "cease trace debugging"
266
267 set pf_prefix $old_pf_prefix
268 }
269
270 proc gdb_unavailable_registers_test { } {
271 global gdb_prompt
272 global spreg
273 global pcreg
274 global pf_prefix
275
276 set old_pf_prefix $pf_prefix
277 set pf_prefix "$pf_prefix unavailable registers:"
278
279 prepare_for_trace_test
280
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 .*" \
284 "set tracepoint"
285
286 # Collect nothing.
287
288 # Begin the test.
289 run_trace_experiment globals_test_func
290
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"
295
296 # Test reading uncollected pseudo-registers. The set of which
297 # depends on target.
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"
307 }
308
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"
312 test_register "\$pc"
313
314 gdb_test "info registers" \
315 "\\*value not available\\*.*\\*value not available\\*" \
316 "info registers, multiple registers not available"
317
318 gdb_test "info registers \$$spreg" \
319 "\\*value not available\\*" \
320 "info registers \$$spreg reports not available"
321
322 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
323
324 set pf_prefix $old_pf_prefix
325 }
326
327 proc gdb_collect_globals_test { } {
328 global ws
329 global cr
330 global gdb_prompt
331 global hex
332 global pf_prefix
333
334 set old_pf_prefix $pf_prefix
335 set pf_prefix "$pf_prefix collect globals:"
336
337 prepare_for_trace_test
338
339 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
340
341 gdb_test "trace $testline" \
342 "Tracepoint \[0-9\]+ at .*" \
343 "set tracepoint"
344
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" \
349 "" \
350 "collect struct_b.struct_a.array\[2\]" "^$" \
351 "collect struct_b.struct_a.array\[100\]" "^$" \
352 \
353 "collect a" "^$" \
354 "collect c" "^$" \
355 \
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" "^$" \
362 \
363 "collect g_string_p" "^$" \
364 "collect g_string_partial\[1\]" "^$" \
365 "collect g_string_partial\[2\]" "^$" \
366 \
367 "collect g_structref_p" "^$" \
368 \
369 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
370 "collect derived_whole" "^$" \
371 \
372 "collect virtual_partial.z" "^$"
373
374 # Begin the test.
375 run_trace_experiment globals_test_func
376
377 gdb_test "print globalc" " = <unavailable>"
378 gdb_test "print globali" " = <unavailable>"
379 gdb_test "print globalf" " = <unavailable>"
380 gdb_test "print globald" " = <unavailable>"
381
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>"
386
387 gdb_test "print globalstruct" \
388 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
389
390 gdb_test "print globalp == &globalstruct" \
391 "value is not available" \
392 "can't compare using non collected global pointer"
393
394 gdb_test "print globalarr\[1\]" " = <unavailable>"
395 gdb_test "print globalarr\[2\]" " = <unavailable>"
396 gdb_test "print globalarr\[3\]" " = <unavailable>"
397
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>}"
400
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>}"
403
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>}"
406
407 gdb_test "print /x struct_b.struct_a.array" \
408 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
409
410 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
411
412 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
413
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
418 # target does it.
419 gdb_test "print {a, b, c}" \
420 " = \\{1, <unavailable>, 3\\}" \
421 "No overcollect of almost but not quite adjacent memory ranges"
422
423 # Check <unavailable> isn't confused with 0 in array element repetitions
424
425 gdb_test_no_output "set print repeat 1"
426
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"
430
431 gdb_test_no_output "set print repeat 10"
432
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>\\}\\}"
435
436 # Static fields
437
438 gdb_test "print struct_b.static_struct_a" \
439 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
440
441 # Bitfields
442
443 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
444
445 # References
446
447 gdb_test "print g_int" " = <unavailable>"
448
449 gdb_test "print g_ref" \
450 "\\(int &\\) @$hex: <unavailable>" \
451 "global reference shows address but not value"
452
453 gdb_test "print *&g_ref" \
454 "\\$\[0-9\]+ = <unavailable>$cr" \
455 "referenced integer was not collected (taking address of reference)"
456
457 gdb_test "print *g_structref_p" \
458 " = {d = <unavailable>, ref = <unavailable>}"
459
460 # Strings
461
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"
466
467 gdb_test "print g_string_p" \
468 " = $hex \"hello world\"" \
469 "printing constant string through collected pointer"
470
471 gdb_test "print g_string_unavail" \
472 " = \{<unavailable> <repeats 12 times>\}" \
473 "printing non collected string"
474
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"
479
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 $" {
486 pass "$msg"
487 }
488 -re "value is not available" {
489 fail "$msg"
490 }
491 }
492
493 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
494
495 # This tests that building the array does not require accessing
496 # g_int's contents.
497 gdb_test "print { 1, g_int, 3 }" \
498 " = \\{1, <unavailable>, 3\\}" \
499 "build array from unavailable value"
500
501 # Note, depends on previous test.
502 gdb_test "print \$\[1\]" \
503 " = <unavailable>" \
504 "subscript a non-memory rvalue array, accessing an unvailable element"
505
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
509 # the second.
510 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
511 gdb_test "print \$.member" " = <unavailable>"
512
513 # Cast to baseclass, checking the unavailable-ness is propagated.
514 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
515
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>\\}"
519
520 gdb_test_no_output "set print object on"
521
522 set old_pf_prefix_2 $pf_prefix
523 set pf_prefix "$pf_prefix print object on:"
524
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
528 # unavailable.
529 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
530
531 # no vtable pointer available
532 gdb_test "print derived_unavail" \
533 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
534
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>}"
538
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}"
542
543 set pf_prefix $old_pf_prefix_2
544
545 gdb_test_no_output "set print object off"
546
547 set pf_prefix "$pf_prefix print object off:"
548
549 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
550
551 # no vtable pointer available
552 gdb_test "print derived_unavail" \
553 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
554
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>}"
558
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}"
562
563 set pf_prefix $old_pf_prefix_2
564
565 # An instance of a virtual class where we collected everything but
566 # the vptr.
567 gdb_test "print virtual_partial" \
568 " = {_vptr.Virtual = <unavailable>, z = 0}"
569
570 gdb_test "tfind none" \
571 "#0 end .*" \
572 "cease trace debugging"
573
574 set pf_prefix $old_pf_prefix
575 }
576
577 proc gdb_trace_collection_test {} {
578 gdb_collect_globals_test
579 gdb_unavailable_registers_test
580
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"
585 }
586
587 clean_restart $executable
588 runto_main
589
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"
594 return 1;
595 }
596
597 # Body of test encased in a proc so we can return prematurely.
598 gdb_trace_collection_test
599
600 # Finished!
601 gdb_test "tfind none" ".*" ""