]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/unavailable.exp
gdb/testsuite/
[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 [istarget "x86_64-*"] then {
34 set fpreg "rbp"
35 set spreg "rsp"
36 set pcreg "rip"
37 } elseif [istarget "i?86-*"] then {
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 #
107 # Test procs
108 #
109
110 proc gdb_collect_args_test {} {
111 global cr
112 global gdb_prompt
113 global pf_prefix
114
115 set old_pf_prefix $pf_prefix
116 set pf_prefix "$pf_prefix unavailable arguments:"
117
118 prepare_for_trace_test
119
120 gdb_test "trace args_test_func" \
121 "Tracepoint \[0-9\]+ at .*" \
122 "set tracepoint"
123
124 # Begin the test.
125 run_trace_experiment args_test_func
126
127 # Test printing the variables, and also their addresses. We
128 # haven't collected any stack, so there's no way GDB can figure
129 # out the latter.
130
131 gdb_test "print argc" " = <unavailable>"
132 gdb_test "print &argc" \
133 "Can't take address of \"argc\" which isn't an lvalue\."
134
135 gdb_test "print argi" " = <unavailable>"
136 gdb_test "print &argi" \
137 "Can't take address of \"argi\" which isn't an lvalue\."
138
139 gdb_test "print argf" " = <unavailable>"
140 gdb_test "print &argf" \
141 "Can't take address of \"argf\" which isn't an lvalue\."
142
143 gdb_test "print argd" " = <unavailable>"
144 gdb_test "print &argd" \
145 "Can't take address of \"argd\" which isn't an lvalue\."
146
147 # struct arg as one of several args (near end of list)
148
149 gdb_test "print argstruct" \
150 " = \{memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>\}"
151
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>"
156
157 gdb_test "print argarray" " = \\(int \\*\\) <unavailable>"
158
159 gdb_test "print &argarray" \
160 "Can't take address of \"argarray\" which isn't an lvalue\."
161
162 gdb_test "print argarray\[0\]" "value is not available"
163
164 # Test "info args"
165 set r ""
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"
173
174 gdb_test "tfind none" \
175 "#0 end .*" \
176 "cease trace debugging"
177
178 set pf_prefix $old_pf_prefix
179 }
180
181 proc gdb_collect_locals_test { func msg } {
182 global cr
183 global gdb_prompt
184 global pf_prefix
185
186 set old_pf_prefix $pf_prefix
187 set pf_prefix "$pf_prefix unavailable locals: $msg:"
188
189 prepare_for_trace_test
190
191 set testline [gdb_get_line_number "set $func tracepoint here"]
192
193 gdb_test "trace $testline" \
194 "Tracepoint \[0-9\]+ at .*" \
195 "set tracepoint"
196
197 # Begin the test.
198 run_trace_experiment $func
199
200 gdb_test "print locc" " = <unavailable>"
201 gdb_test "print loci" " = <unavailable>"
202 gdb_test "print locf" " = <unavailable>"
203 gdb_test "print locd" " = <unavailable>"
204
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>"
209
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>"
214
215 # Test "info locals"
216 set r ""
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}"
224 }
225 set r "${r}locc = <unavailable>${cr}"
226 set r "${r}loci = <unavailable>${cr}"
227 gdb_test "info locals" "$r" "info locals"
228
229 gdb_test "tfind none" \
230 "#0 end .*" \
231 "cease trace debugging"
232
233 set pf_prefix $old_pf_prefix
234 }
235
236 proc gdb_unavailable_registers_test { } {
237 global gdb_prompt
238 global spreg
239 global pcreg
240 global pf_prefix
241
242 set old_pf_prefix $pf_prefix
243 set pf_prefix "$pf_prefix unavailable registers:"
244
245 prepare_for_trace_test
246
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 .*" \
250 "set tracepoint"
251
252 # Collect nothing.
253
254 # Begin the test.
255 run_trace_experiment globals_test_func
256
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"
261
262 # Test reading uncollected pseudo-registers. The set of which
263 # depends on target.
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"
273 }
274
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"
278 test_register "\$pc"
279
280 gdb_test "info registers" \
281 "\\*value not available\\*.*\\*value not available\\*" \
282 "info registers, multiple registers not available"
283
284 gdb_test "info registers \$$spreg" \
285 "\\*value not available\\*" \
286 "info registers \$$spreg reports not available"
287
288 gdb_test "tfind none" "#0 end .*" "cease trace debugging"
289
290 set pf_prefix $old_pf_prefix
291 }
292
293 proc gdb_collect_globals_test { } {
294 global ws
295 global cr
296 global gdb_prompt
297 global hex
298 global pf_prefix
299
300 set old_pf_prefix $pf_prefix
301 set pf_prefix "$pf_prefix collect globals:"
302
303 prepare_for_trace_test
304
305 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
306
307 gdb_test "trace $testline" \
308 "Tracepoint \[0-9\]+ at .*" \
309 "set tracepoint"
310
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" \
315 "" \
316 "collect struct_b.struct_a.array\[2\]" "^$" \
317 "collect struct_b.struct_a.array\[100\]" "^$" \
318 \
319 "collect a" "^$" \
320 "collect c" "^$" \
321 \
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" "^$" \
328 \
329 "collect g_string_p" "^$" \
330 "collect g_string_partial\[1\]" "^$" \
331 "collect g_string_partial\[2\]" "^$" \
332 \
333 "collect g_structref_p" "^$" \
334 \
335 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
336 "collect derived_whole" "^$" \
337 \
338 "collect virtual_partial.z" "^$"
339
340 # Begin the test.
341 run_trace_experiment globals_test_func
342
343 gdb_test "print globalc" " = <unavailable>"
344 gdb_test "print globali" " = <unavailable>"
345 gdb_test "print globalf" " = <unavailable>"
346 gdb_test "print globald" " = <unavailable>"
347
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>"
352
353 gdb_test "print globalstruct" \
354 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
355
356 gdb_test "print globalp == &globalstruct" \
357 "value is not available" \
358 "can't compare using non collected global pointer"
359
360 gdb_test "print globalarr\[1\]" " = <unavailable>"
361 gdb_test "print globalarr\[2\]" " = <unavailable>"
362 gdb_test "print globalarr\[3\]" " = <unavailable>"
363
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>}"
366
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>}"
369
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>}"
372
373 gdb_test "print /x struct_b.struct_a.array" \
374 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
375
376 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
377
378 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
379
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
384 # target does it.
385 gdb_test "print {a, b, c}" \
386 " = \\{1, <unavailable>, 3\\}" \
387 "No overcollect of almost but not quite adjacent memory ranges"
388
389 # Check <unavailable> isn't confused with 0 in array element repetitions
390
391 gdb_test_no_output "set print repeat 1"
392
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"
396
397 gdb_test_no_output "set print repeat 10"
398
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>\\}\\}"
401
402 # Static fields
403
404 gdb_test "print struct_b.static_struct_a" \
405 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
406
407 # Bitfields
408
409 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
410
411 # References
412
413 gdb_test "print g_int" " = <unavailable>"
414
415 gdb_test "print g_ref" \
416 "\\(int &\\) @$hex: <unavailable>" \
417 "global reference shows address but not value"
418
419 gdb_test "print *&g_ref" \
420 "\\$\[0-9\]+ = <unavailable>$cr" \
421 "referenced integer was not collected (taking address of reference)"
422
423 gdb_test "print *g_structref_p" \
424 " = {d = <unavailable>, ref = <unavailable>}"
425
426 # Strings
427
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"
432
433 gdb_test "print g_string_p" \
434 " = $hex \"hello world\"" \
435 "printing constant string through collected pointer"
436
437 gdb_test "print g_string_unavail" \
438 " = \{<unavailable> <repeats 12 times>\}" \
439 "printing non collected string"
440
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"
445
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 $" {
452 pass "$msg"
453 }
454 -re "value is not available" {
455 fail "$msg"
456 }
457 }
458
459 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
460
461 # This tests that building the array does not require accessing
462 # g_int's contents.
463 gdb_test "print { 1, g_int, 3 }" \
464 " = \\{1, <unavailable>, 3\\}" \
465 "build array from unavailable value"
466
467 # Note, depends on previous test.
468 gdb_test "print \$\[1\]" \
469 " = <unavailable>" \
470 "subscript a non-memory rvalue array, accessing an unvailable element"
471
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
475 # the second.
476 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
477 gdb_test "print \$.member" " = <unavailable>"
478
479 # Cast to baseclass, checking the unavailable-ness is propagated.
480 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
481
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>\\}"
485
486 gdb_test_no_output "set print object on"
487
488 set old_pf_prefix_2 $pf_prefix
489 set pf_prefix "$pf_prefix print object on:"
490
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
494 # unavailable.
495 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
496
497 # no vtable pointer available
498 gdb_test "print derived_unavail" \
499 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
500
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>}"
504
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}"
508
509 set pf_prefix $old_pf_prefix_2
510
511 gdb_test_no_output "set print object off"
512
513 set pf_prefix "$pf_prefix print object off:"
514
515 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
516
517 # no vtable pointer available
518 gdb_test "print derived_unavail" \
519 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
520
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>}"
524
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}"
528
529 set pf_prefix $old_pf_prefix_2
530
531 # An instance of a virtual class where we collected everything but
532 # the vptr.
533 gdb_test "print virtual_partial" \
534 " = {_vptr.Virtual = <unavailable>, z = 0}"
535
536 gdb_test "tfind none" \
537 "#0 end .*" \
538 "cease trace debugging"
539
540 set pf_prefix $old_pf_prefix
541 }
542
543 proc gdb_trace_collection_test {} {
544 gdb_collect_globals_test
545 gdb_unavailable_registers_test
546
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"
551 }
552
553 clean_restart $executable
554 runto_main
555
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"
560 return 1;
561 }
562
563 # Body of test encased in a proc so we can return prematurely.
564 gdb_trace_collection_test
565
566 # Finished!
567 gdb_test "tfind none" ".*" ""