]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/unavailable.exp
2012-02-21 Pedro Alves <palves@redhat.com>
[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 {} { with_test_prefix "unavailable arguments" {
140 global cr
141 global gdb_prompt
142
143 prepare_for_trace_test
144
145 gdb_test "trace args_test_func" \
146 "Tracepoint \[0-9\]+ at .*" \
147 "set tracepoint"
148
149 # Begin the test.
150 run_trace_experiment args_test_func
151
152 # Test printing the variables, and also their addresses. We
153 # haven't collected any stack, so there's no way GDB can figure
154 # out the latter.
155
156 gdb_test "print argc" " = <unavailable>"
157 gdb_test "print &argc" \
158 "Can't take address of \"argc\" which isn't an lvalue\."
159
160 gdb_test "print argi" " = <unavailable>"
161 gdb_test "print &argi" \
162 "Can't take address of \"argi\" which isn't an lvalue\."
163
164 gdb_test "print argf" " = <unavailable>"
165 gdb_test "print &argf" \
166 "Can't take address of \"argf\" which isn't an lvalue\."
167
168 gdb_test "print argd" " = <unavailable>"
169 gdb_test "print &argd" \
170 "Can't take address of \"argd\" which isn't an lvalue\."
171
172 # struct arg as one of several args (near end of list)
173
174 gdb_test "print argstruct" \
175 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
176
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>"
181
182 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
183
184 gdb_test "print &argarray" \
185 "Can't take address of \"argarray\" which isn't an lvalue\."
186
187 gdb_test "print argarray\[0\]" "value is not available"
188
189 # Test "info args"
190 set r ""
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"
198
199 test_maybe_regvar_display "argc"
200
201 gdb_test "tfind none" \
202 "#0 end .*" \
203 "cease trace debugging"
204 }}
205
206 proc gdb_collect_locals_test { func msg } { with_test_prefix "unavailable locals: $msg" {
207 global cr
208 global gdb_prompt
209
210 prepare_for_trace_test
211
212 set testline [gdb_get_line_number "set $func tracepoint here"]
213
214 gdb_test "trace $testline" \
215 "Tracepoint \[0-9\]+ at .*" \
216 "set tracepoint"
217
218 # Begin the test.
219 run_trace_experiment $func
220
221 gdb_test "print locc" " = <unavailable>"
222 gdb_test "print loci" " = <unavailable>"
223 gdb_test "print locf" " = <unavailable>"
224 gdb_test "print locd" " = <unavailable>"
225
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>"
230
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>"
235
236 # Test "info locals"
237 set r ""
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}"
245 }
246 set r "${r}locc = <unavailable>${cr}"
247 set r "${r}loci = <unavailable>${cr}"
248 gdb_test "info locals" "$r" "info locals"
249
250 test_maybe_regvar_display "loci"
251
252 gdb_test "tfind none" \
253 "#0 end .*" \
254 "cease trace debugging"
255 }}
256
257 proc gdb_unavailable_registers_test { } { with_test_prefix "unavailable registers" {
258 global gdb_prompt
259 global spreg
260 global pcreg
261
262 prepare_for_trace_test
263
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 .*" \
267 "set tracepoint"
268
269 # Collect nothing.
270
271 # Begin the test.
272 run_trace_experiment globals_test_func
273
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"
278
279 # Test reading uncollected pseudo-registers. The set of which
280 # depends on target.
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"
290 }
291
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"
295 test_register "\$pc"
296
297 gdb_test "info registers" \
298 "\\*value not available\\*.*\\*value not available\\*" \
299 "info registers, multiple registers not available"
300
301 gdb_test "info registers \$$spreg" \
302 "\\*value not available\\*" \
303 "info registers \$$spreg reports not available"
304
305 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
306 }}
307
308 proc gdb_collect_globals_test { } { with_test_prefix "collect globals" {
309 global ws
310 global cr
311 global gdb_prompt
312 global hex
313
314 prepare_for_trace_test
315
316 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
317
318 gdb_test "trace $testline" \
319 "Tracepoint \[0-9\]+ at .*" \
320 "set tracepoint"
321
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" \
326 "" \
327 "collect struct_b.struct_a.array\[2\]" "^$" \
328 "collect struct_b.struct_a.array\[100\]" "^$" \
329 \
330 "collect a" "^$" \
331 "collect c" "^$" \
332 \
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" "^$" \
339 \
340 "collect g_string_p" "^$" \
341 "collect g_string_partial\[1\]" "^$" \
342 "collect g_string_partial\[2\]" "^$" \
343 \
344 "collect g_structref_p" "^$" \
345 \
346 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
347 "collect derived_whole" "^$" \
348 \
349 "collect virtual_partial.z" "^$"
350
351 # Begin the test.
352 run_trace_experiment globals_test_func
353
354 gdb_test "print globalc" " = <unavailable>"
355 gdb_test "print globali" " = <unavailable>"
356 gdb_test "print globalf" " = <unavailable>"
357 gdb_test "print globald" " = <unavailable>"
358
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>"
363
364 gdb_test "print globalstruct" \
365 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
366
367 gdb_test "print globalp == &globalstruct" \
368 "value is not available" \
369 "can't compare using non collected global pointer"
370
371 gdb_test "print globalarr\[1\]" " = <unavailable>"
372 gdb_test "print globalarr\[2\]" " = <unavailable>"
373 gdb_test "print globalarr\[3\]" " = <unavailable>"
374
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>}"
377
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>}"
380
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>}"
383
384 gdb_test "print /x struct_b.struct_a.array" \
385 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
386
387 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
388
389 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
390
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
395 # target does it.
396 gdb_test "print {a, b, c}" \
397 " = \\{1, <unavailable>, 3\\}" \
398 "No overcollect of almost but not quite adjacent memory ranges"
399
400 # Check <unavailable> isn't confused with 0 in array element repetitions
401
402 gdb_test_no_output "set print repeat 1"
403
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"
407
408 gdb_test_no_output "set print repeat 10"
409
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>\\}\\}"
412
413 # Static fields
414
415 gdb_test "print struct_b.static_struct_a" \
416 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
417
418 # Bitfields
419
420 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
421
422 # References
423
424 gdb_test "print g_int" " = <unavailable>"
425
426 gdb_test "print g_ref" \
427 "\\(int &\\) @$hex: <unavailable>" \
428 "global reference shows address but not value"
429
430 gdb_test "print *&g_ref" \
431 "\\$\[0-9\]+ = <unavailable>$cr" \
432 "referenced integer was not collected (taking address of reference)"
433
434 gdb_test "print *g_structref_p" \
435 " = {d = <unavailable>, ref = <unavailable>}"
436
437 # Strings
438
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"
443
444 gdb_test "print g_string_p" \
445 " = $hex \"hello world\"" \
446 "printing constant string through collected pointer"
447
448 gdb_test "print g_string_unavail" \
449 " = \{<unavailable> <repeats 12 times>\}" \
450 "printing non collected string"
451
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"
456
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 $" {
463 pass "$msg"
464 }
465 -re "value is not available" {
466 fail "$msg"
467 }
468 }
469
470 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
471
472 # This tests that building the array does not require accessing
473 # g_int's contents.
474 gdb_test "print { 1, g_int, 3 }" \
475 " = \\{1, <unavailable>, 3\\}" \
476 "build array from unavailable value"
477
478 # Note, depends on previous test.
479 gdb_test "print \$\[1\]" \
480 " = <unavailable>" \
481 "subscript a non-memory rvalue array, accessing an unvailable element"
482
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
486 # the second.
487 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
488 gdb_test "print \$.member" " = <unavailable>"
489
490 # Cast to baseclass, checking the unavailable-ness is propagated.
491 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
492
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>\\}"
496
497 gdb_test_no_output "set print object on"
498
499 with_test_prefix "print object on" {
500 # With print object on, printing a pointer may need to fetch
501 # the pointed-to object, to check its run-time type. Make
502 # sure that fails gracefully and transparently when the
503 # pointer itself is unavailable.
504 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
505
506 # no vtable pointer available
507 gdb_test "print derived_unavail" \
508 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
509
510 # vtable pointer available, but nothing else
511 gdb_test "print derived_partial" \
512 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
513
514 # whole object available
515 gdb_test "print derived_whole" \
516 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
517 }
518
519 gdb_test_no_output "set print object off"
520
521 with_test_prefix "print object off" {
522 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
523
524 # no vtable pointer available
525 gdb_test "print derived_unavail" \
526 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
527
528 # vtable pointer available, but nothing else
529 gdb_test "print derived_partial" \
530 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
531
532 # whole object available
533 gdb_test "print derived_whole" \
534 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
535 }
536
537 # An instance of a virtual class where we collected everything but
538 # the vptr.
539 gdb_test "print virtual_partial" \
540 " = {_vptr.Virtual = <unavailable>, z = 0}"
541
542 gdb_test "tfind none" \
543 "#0 end .*" \
544 "cease trace debugging"
545 }}
546
547 proc gdb_trace_collection_test {} {
548 gdb_collect_globals_test
549 gdb_unavailable_registers_test
550
551 gdb_collect_args_test
552 gdb_collect_locals_test local_test_func "auto locals"
553 gdb_collect_locals_test reglocal_test_func "register locals"
554 gdb_collect_locals_test statlocal_test_func "static locals"
555 }
556
557 clean_restart $executable
558 runto_main
559
560 if { ![gdb_target_supports_trace] } then {
561 unsupported "Current target does not support trace"
562 return 1;
563 }
564
565 # Body of test encased in a proc so we can return prematurely.
566 gdb_trace_collection_test
567
568 # Finished!
569 gdb_test "tfind none" ".*" ""