]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/unavailable.exp
Copyright year update in most files of the GDB Project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / unavailable.exp
1 # Copyright 1998, 2005, 2007-2012 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 load_lib "trace-support.exp"
17
18 set testfile "unavailable"
19 set srcfile ${testfile}.cc
20 set executable $testfile
21 set binfile $objdir/$subdir/$executable
22
23 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
24 executable {debug nowarnings c++}] != "" } {
25 untested unavailable.exp
26 return -1
27 }
28
29 set ws "\[\r\n\t \]+"
30 set cr "\[\r\n\]+"
31
32 if [is_amd64_regs_target] {
33 set fpreg "rbp"
34 set spreg "rsp"
35 set pcreg "rip"
36 } elseif [is_x86_like_target] {
37 set fpreg "ebp"
38 set spreg "esp"
39 set pcreg "eip"
40 } else {
41 set fpreg "fp"
42 set spreg "sp"
43 set pcreg "pc"
44 }
45
46 #
47 # Utility procs
48 #
49
50 proc test_register { reg } {
51 global gdb_prompt
52 global hex
53 global cr
54
55 gdb_test_multiple "print /x $reg" "collected $reg" {
56 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
57 fail "collected $reg (zero)"
58 }
59 -re "\\$\[0-9\]+ = $hex$cr$gdb_prompt $" {
60 pass "collected $reg"
61 }
62 -re "\[Ee\]rror.*$gdb_prompt $" {
63 fail "collected $reg (error)"
64 }
65 }
66 }
67
68 proc test_register_unavailable { reg } {
69 gdb_test "print /x $reg" \
70 "<unavailable>" \
71 "correctly report $reg as unavailable"
72 }
73
74 proc prepare_for_trace_test {} {
75 global executable
76
77 clean_restart $executable
78
79 runto_main
80
81 gdb_test "break begin" ".*" ""
82 gdb_test "break end" ".*" ""
83 }
84
85 proc run_trace_experiment { test_func } {
86 global gdb_prompt
87
88 gdb_test "continue" \
89 ".*Breakpoint \[0-9\]+, begin .*" \
90 "advance to begin"
91
92 gdb_test_no_output "tstart" "start trace experiment"
93
94 gdb_test "continue" \
95 "Continuing.*Breakpoint \[0-9\]+, end.*" \
96 "run trace experiment"
97 gdb_test "tstop" \
98 "\[\r\n\]+" \
99 "stop trace experiment"
100 gdb_test "tfind start" \
101 "#0 $test_func .*" \
102 "tfind test frame"
103 }
104
105 # Test that "display VAR" works as expected, assuming VAR is wholly
106 # unavailable.
107
108 proc test_maybe_regvar_display { var } {
109 global gdb_prompt
110
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 $" {
120 fail "$test"
121 }
122 -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" {
123 pass "$test"
124 }
125 }
126 gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled"
127
128 gdb_test "undisp" \
129 "" \
130 "delete $var display" \
131 ".*Delete all auto-display expressions.*y or n. $" \
132 "y"
133 }
134
135 #
136 # Test procs
137 #
138
139 proc gdb_collect_args_test {} {
140 global cr
141 global gdb_prompt
142 global pf_prefix
143
144 set old_pf_prefix $pf_prefix
145 set pf_prefix "$pf_prefix unavailable arguments:"
146
147 prepare_for_trace_test
148
149 gdb_test "trace args_test_func" \
150 "Tracepoint \[0-9\]+ at .*" \
151 "set tracepoint"
152
153 # Begin the test.
154 run_trace_experiment args_test_func
155
156 # Test printing the variables, and also their addresses. We
157 # haven't collected any stack, so there's no way GDB can figure
158 # out the latter.
159
160 gdb_test "print argc" " = <unavailable>"
161 gdb_test "print &argc" \
162 "Can't take address of \"argc\" which isn't an lvalue\."
163
164 gdb_test "print argi" " = <unavailable>"
165 gdb_test "print &argi" \
166 "Can't take address of \"argi\" which isn't an lvalue\."
167
168 gdb_test "print argf" " = <unavailable>"
169 gdb_test "print &argf" \
170 "Can't take address of \"argf\" which isn't an lvalue\."
171
172 gdb_test "print argd" " = <unavailable>"
173 gdb_test "print &argd" \
174 "Can't take address of \"argd\" which isn't an lvalue\."
175
176 # struct arg as one of several args (near end of list)
177
178 gdb_test "print argstruct" \
179 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
180
181 gdb_test "print argstruct.memberc" " = <unavailable>"
182 gdb_test "print argstruct.memberi" " = <unavailable>"
183 gdb_test "print argstruct.memberf" " = <unavailable>"
184 gdb_test "print argstruct.memberd" " = <unavailable>"
185
186 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
187
188 gdb_test "print &argarray" \
189 "Can't take address of \"argarray\" which isn't an lvalue\."
190
191 gdb_test "print argarray\[0\]" "value is not available"
192
193 # Test "info args"
194 set r ""
195 set r "${r}argc = <unavailable>${cr}"
196 set r "${r}argi = <unavailable>${cr}"
197 set r "${r}argf = <unavailable>${cr}"
198 set r "${r}argd = <unavailable>${cr}"
199 set r "${r}argstruct = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
200 set r "${r}argarray = <unavailable>${cr}"
201 gdb_test "info args" "$r" "info args"
202
203 test_maybe_regvar_display "argc"
204
205 gdb_test "tfind none" \
206 "#0 end .*" \
207 "cease trace debugging"
208
209 set pf_prefix $old_pf_prefix
210 }
211
212 proc gdb_collect_locals_test { func msg } {
213 global cr
214 global gdb_prompt
215 global pf_prefix
216
217 set old_pf_prefix $pf_prefix
218 set pf_prefix "$pf_prefix unavailable locals: $msg:"
219
220 prepare_for_trace_test
221
222 set testline [gdb_get_line_number "set $func tracepoint here"]
223
224 gdb_test "trace $testline" \
225 "Tracepoint \[0-9\]+ at .*" \
226 "set tracepoint"
227
228 # Begin the test.
229 run_trace_experiment $func
230
231 gdb_test "print locc" " = <unavailable>"
232 gdb_test "print loci" " = <unavailable>"
233 gdb_test "print locf" " = <unavailable>"
234 gdb_test "print locd" " = <unavailable>"
235
236 gdb_test "print locst.memberc" " = <unavailable>"
237 gdb_test "print locst.memberi" " = <unavailable>"
238 gdb_test "print locst.memberf" " = <unavailable>"
239 gdb_test "print locst.memberd" " = <unavailable>"
240
241 gdb_test "print locar\[0\]" " = <unavailable>"
242 gdb_test "print locar\[1\]" " = <unavailable>"
243 gdb_test "print locar\[2\]" " = <unavailable>"
244 gdb_test "print locar\[3\]" " = <unavailable>"
245
246 # Test "info locals"
247 set r ""
248 set r "${r}locf = <unavailable>${cr}"
249 set r "${r}locd = <unavailable>${cr}"
250 set r "${r}locst = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}${cr}"
251 set r "${r}locar = {<unavailable>, <unavailable>, <unavailable>, <unavailable>}${cr}"
252 set r "${r}i = <unavailable>${cr}"
253 if { $func == "local_test_func" } {
254 set r "${r}locdefst = {<No data fields>}${cr}"
255 }
256 set r "${r}locc = <unavailable>${cr}"
257 set r "${r}loci = <unavailable>${cr}"
258 gdb_test "info locals" "$r" "info locals"
259
260 test_maybe_regvar_display "loci"
261
262 gdb_test "tfind none" \
263 "#0 end .*" \
264 "cease trace debugging"
265
266 set pf_prefix $old_pf_prefix
267 }
268
269 proc gdb_unavailable_registers_test { } {
270 global gdb_prompt
271 global spreg
272 global pcreg
273 global pf_prefix
274
275 set old_pf_prefix $pf_prefix
276 set pf_prefix "$pf_prefix unavailable registers:"
277
278 prepare_for_trace_test
279
280 # We'll simply re-use the globals_test_function for this test
281 gdb_test "trace globals_test_func" \
282 "Tracepoint \[0-9\]+ at .*" \
283 "set tracepoint"
284
285 # Collect nothing.
286
287 # Begin the test.
288 run_trace_experiment globals_test_func
289
290 # On some archs, the $sp/$pc are a real raw registers. On others,
291 # like x86, they're user registers. Test both variants.
292 test_register_unavailable "\$$spreg"
293 test_register_unavailable "\$sp"
294
295 # Test reading uncollected pseudo-registers. The set of which
296 # depends on target.
297 if [is_amd64_regs_target] {
298 # Check the raw register first.
299 test_register_unavailable "\$rax"
300 test_register_unavailable "\$eax"
301 test_register_unavailable "\$ax"
302 } elseif [is_x86_like_target] {
303 # Check the raw register first.
304 test_register_unavailable "\$eax"
305 test_register_unavailable "\$ax"
306 }
307
308 # GDBserver always provides the PC value of regular tracepoint
309 # hits, since it's the same as the tracepoint's address.
310 test_register "\$$pcreg"
311 test_register "\$pc"
312
313 gdb_test "info registers" \
314 "\\*value not available\\*.*\\*value not available\\*" \
315 "info registers, multiple registers not available"
316
317 gdb_test "info registers \$$spreg" \
318 "\\*value not available\\*" \
319 "info registers \$$spreg reports not available"
320
321 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
322
323 set pf_prefix $old_pf_prefix
324 }
325
326 proc gdb_collect_globals_test { } {
327 global ws
328 global cr
329 global gdb_prompt
330 global hex
331 global pf_prefix
332
333 set old_pf_prefix $pf_prefix
334 set pf_prefix "$pf_prefix collect globals:"
335
336 prepare_for_trace_test
337
338 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
339
340 gdb_test "trace $testline" \
341 "Tracepoint \[0-9\]+ at .*" \
342 "set tracepoint"
343
344 # We collect the initial sizeof(pointer) bytes of derived_partial
345 # in an attempt of collecting the vptr. Not portable, but should
346 # work everywhere we need to care.
347 gdb_trace_setactions "define actions" \
348 "" \
349 "collect struct_b.struct_a.array\[2\]" "^$" \
350 "collect struct_b.struct_a.array\[100\]" "^$" \
351 \
352 "collect a" "^$" \
353 "collect c" "^$" \
354 \
355 "collect tarray\[0\].a" "^$" \
356 "collect tarray\[1\].a" "^$" \
357 "collect tarray\[3\].a" "^$" \
358 "collect tarray\[3\].b" "^$" \
359 "collect tarray\[4\].b" "^$" \
360 "collect tarray\[5\].b" "^$" \
361 \
362 "collect g_string_p" "^$" \
363 "collect g_string_partial\[1\]" "^$" \
364 "collect g_string_partial\[2\]" "^$" \
365 \
366 "collect g_structref_p" "^$" \
367 \
368 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
369 "collect derived_whole" "^$" \
370 \
371 "collect virtual_partial.z" "^$"
372
373 # Begin the test.
374 run_trace_experiment globals_test_func
375
376 gdb_test "print globalc" " = <unavailable>"
377 gdb_test "print globali" " = <unavailable>"
378 gdb_test "print globalf" " = <unavailable>"
379 gdb_test "print globald" " = <unavailable>"
380
381 gdb_test "print globalstruct.memberc" " = <unavailable>"
382 gdb_test "print globalstruct.memberi" " = <unavailable>"
383 gdb_test "print globalstruct.memberf" " = <unavailable>"
384 gdb_test "print globalstruct.memberd" " = <unavailable>"
385
386 gdb_test "print globalstruct" \
387 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
388
389 gdb_test "print globalp == &globalstruct" \
390 "value is not available" \
391 "can't compare using non collected global pointer"
392
393 gdb_test "print globalarr\[1\]" " = <unavailable>"
394 gdb_test "print globalarr\[2\]" " = <unavailable>"
395 gdb_test "print globalarr\[3\]" " = <unavailable>"
396
397 gdb_test "print struct_b" \
398 " = {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>}"
399
400 gdb_test "print /x struct_b" \
401 " = {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>}"
402
403 gdb_test "print /x struct_b.struct_a" \
404 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
405
406 gdb_test "print /x struct_b.struct_a.array" \
407 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
408
409 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
410
411 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
412
413 # Check the target doesn't overcollect. GDB used to merge memory
414 # ranges to collect if they were close enough (collecting the hole
415 # as well), but does not do that anymore. It's plausible that a
416 # target may do this on its end, but as of this writing, no known
417 # target does it.
418 gdb_test "print {a, b, c}" \
419 " = \\{1, <unavailable>, 3\\}" \
420 "No overcollect of almost but not quite adjacent memory ranges"
421
422 # Check <unavailable> isn't confused with 0 in array element repetitions
423
424 gdb_test_no_output "set print repeat 1"
425
426 gdb_test "print /x tarray" \
427 " = \{\{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>\}" \
428 "<unavailable> is not the same as 0 in array element repetitions"
429
430 gdb_test_no_output "set print repeat 10"
431
432 # Check that value repeat handles unavailable-ness.
433 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
434
435 # Static fields
436
437 gdb_test "print struct_b.static_struct_a" \
438 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
439
440 # Bitfields
441
442 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
443
444 # References
445
446 gdb_test "print g_int" " = <unavailable>"
447
448 gdb_test "print g_ref" \
449 "\\(int &\\) @$hex: <unavailable>" \
450 "global reference shows address but not value"
451
452 gdb_test "print *&g_ref" \
453 "\\$\[0-9\]+ = <unavailable>$cr" \
454 "referenced integer was not collected (taking address of reference)"
455
456 gdb_test "print *g_structref_p" \
457 " = {d = <unavailable>, ref = <unavailable>}"
458
459 # Strings
460
461 # Const string is always available, even when not collected.
462 gdb_test "print g_const_string" \
463 " = \"hello world\"$cr" \
464 "non collected const string is still printable"
465
466 gdb_test "print g_string_p" \
467 " = $hex \"hello world\"" \
468 "printing constant string through collected pointer"
469
470 gdb_test "print g_string_unavail" \
471 " = \{<unavailable> <repeats 12 times>\}" \
472 "printing non collected string"
473
474 # Incomplete strings print as an array.
475 gdb_test "print g_string_partial" \
476 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
477 "printing partially collected string"
478
479 # It is important for this test that the last examined value is
480 # <unavailable>, to exercise the case of the $__ convenience
481 # variable being set to <unavailable> without error.
482 set msg "examining partially collected object"
483 gdb_test_multiple "x /10x &struct_b" "$msg" {
484 -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 $" {
485 pass "$msg"
486 }
487 -re "value is not available" {
488 fail "$msg"
489 }
490 }
491
492 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
493
494 # This tests that building the array does not require accessing
495 # g_int's contents.
496 gdb_test "print { 1, g_int, 3 }" \
497 " = \\{1, <unavailable>, 3\\}" \
498 "build array from unavailable value"
499
500 # Note, depends on previous test.
501 gdb_test "print \$\[1\]" \
502 " = <unavailable>" \
503 "subscript a non-memory rvalue array, accessing an unvailable element"
504
505 # Access a field of a non-lazy value, making sure the
506 # unavailable-ness is propagated. History values are easy
507 # non-lazy values, so use those. The first test just sets up for
508 # the second.
509 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
510 gdb_test "print \$.member" " = <unavailable>"
511
512 # Cast to baseclass, checking the unavailable-ness is propagated.
513 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
514
515 # Same cast, but starting from a non-lazy, value.
516 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
517 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
518
519 gdb_test_no_output "set print object on"
520
521 set old_pf_prefix_2 $pf_prefix
522 set pf_prefix "$pf_prefix print object on:"
523
524 # With print object on, printing a pointer may need to fetch the
525 # pointed-to object, to check its run-time type. Make sure that
526 # fails gracefully and transparently when the pointer itself is
527 # unavailable.
528 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
529
530 # no vtable pointer available
531 gdb_test "print derived_unavail" \
532 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
533
534 # vtable pointer available, but nothing else
535 gdb_test "print derived_partial" \
536 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
537
538 # whole object available
539 gdb_test "print derived_whole" \
540 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
541
542 set pf_prefix $old_pf_prefix_2
543
544 gdb_test_no_output "set print object off"
545
546 set pf_prefix "$pf_prefix print object off:"
547
548 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
549
550 # no vtable pointer available
551 gdb_test "print derived_unavail" \
552 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
553
554 # vtable pointer available, but nothing else
555 gdb_test "print derived_partial" \
556 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
557
558 # whole object available
559 gdb_test "print derived_whole" \
560 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
561
562 set pf_prefix $old_pf_prefix_2
563
564 # An instance of a virtual class where we collected everything but
565 # the vptr.
566 gdb_test "print virtual_partial" \
567 " = {_vptr.Virtual = <unavailable>, z = 0}"
568
569 gdb_test "tfind none" \
570 "#0 end .*" \
571 "cease trace debugging"
572
573 set pf_prefix $old_pf_prefix
574 }
575
576 proc gdb_trace_collection_test {} {
577 gdb_collect_globals_test
578 gdb_unavailable_registers_test
579
580 gdb_collect_args_test
581 gdb_collect_locals_test local_test_func "auto locals"
582 gdb_collect_locals_test reglocal_test_func "register locals"
583 gdb_collect_locals_test statlocal_test_func "static locals"
584 }
585
586 clean_restart $executable
587 runto_main
588
589 # We generously give ourselves one "pass" if we successfully
590 # detect that this test cannot be run on this target!
591 if { ![gdb_target_supports_trace] } then {
592 pass "Current target does not support trace"
593 return 1;
594 }
595
596 # Body of test encased in a proc so we can return prematurely.
597 gdb_trace_collection_test
598
599 # Finished!
600 gdb_test "tfind none" ".*" ""