]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 1998-2024 Free Software Foundation, Inc. |
06d72e16 PA |
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 | ||
497a5eb0 | 18 | standard_testfile unavailable.cc |
06d72e16 | 19 | set executable $testfile |
06d72e16 | 20 | |
5b362f04 | 21 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ |
ba22ff86 | 22 | {debug nowarnings c++ nopie}]} { |
06d72e16 PA |
23 | return -1 |
24 | } | |
25 | ||
26 | set ws "\[\r\n\t \]+" | |
06d72e16 PA |
27 | |
28 | # | |
29 | # Utility procs | |
30 | # | |
31 | ||
0fdb4f18 PA |
32 | proc test_register { reg } { |
33 | global gdb_prompt | |
34 | global hex | |
0fdb4f18 PA |
35 | |
36 | gdb_test_multiple "print /x $reg" "collected $reg" { | |
1f7f972f | 37 | -re "\\$\[0-9\]+ = \[x0\]+\r\n$gdb_prompt $" { |
0fdb4f18 PA |
38 | fail "collected $reg (zero)" |
39 | } | |
1f7f972f | 40 | -re "\\$\[0-9\]+ = $hex\r\n$gdb_prompt $" { |
0fdb4f18 PA |
41 | pass "collected $reg" |
42 | } | |
43 | -re "\[Ee\]rror.*$gdb_prompt $" { | |
44 | fail "collected $reg (error)" | |
45 | } | |
46 | } | |
47 | } | |
48 | ||
49 | proc test_register_unavailable { reg } { | |
50 | gdb_test "print /x $reg" \ | |
51 | "<unavailable>" \ | |
52 | "correctly report $reg as unavailable" | |
53 | } | |
54 | ||
06d72e16 PA |
55 | proc prepare_for_trace_test {} { |
56 | global executable | |
57 | ||
58 | clean_restart $executable | |
59 | ||
60 | runto_main | |
61 | ||
194ed413 AA |
62 | gdb_breakpoint "begin" qualified |
63 | gdb_breakpoint "end" qualified | |
06d72e16 PA |
64 | } |
65 | ||
66 | proc run_trace_experiment { test_func } { | |
67 | global gdb_prompt | |
68 | ||
69 | gdb_test "continue" \ | |
70 | ".*Breakpoint \[0-9\]+, begin .*" \ | |
71 | "advance to begin" | |
72 | ||
73 | gdb_test_no_output "tstart" "start trace experiment" | |
74 | ||
75 | gdb_test "continue" \ | |
76 | "Continuing.*Breakpoint \[0-9\]+, end.*" \ | |
77 | "run trace experiment" | |
1f7f972f | 78 | gdb_test_no_output "tstop" \ |
06d72e16 PA |
79 | "stop trace experiment" |
80 | gdb_test "tfind start" \ | |
81 | "#0 $test_func .*" \ | |
82 | "tfind test frame" | |
83 | } | |
84 | ||
af6e93b2 PA |
85 | # Test that "display VAR" works as expected, assuming VAR is wholly |
86 | # unavailable. | |
87 | ||
88 | proc test_maybe_regvar_display { var } { | |
89 | global gdb_prompt | |
90 | ||
91 | # Evaluating VAR's location description may throw an internal | |
92 | # "unavailable" exception, if for example, the value of a register | |
93 | # necessary for computing VAR's location is unavailable. Such an | |
94 | # exception is caught, and should not cause automatic disablement | |
95 | # of the current display being printed. (GDB used to disable the | |
96 | # current display whenever any exception was thrown.) | |
97 | set test "display $var" | |
98 | gdb_test_multiple "$test" "$test" { | |
99 | -re "Disabling display ? to avoid infinite recursion.*$gdb_prompt $" { | |
100 | fail "$test" | |
101 | } | |
102 | -re "display ${var}\r\n1: ${var} = <unavailable>\r\n$gdb_prompt $" { | |
103 | pass "$test" | |
104 | } | |
105 | } | |
106 | gdb_test "info display" ".*1:\[ \t\]+y\[ \t\]+${var}" "display ${var} is enabled" | |
107 | ||
108 | gdb_test "undisp" \ | |
109 | "" \ | |
110 | "delete $var display" \ | |
111 | ".*Delete all auto-display expressions.*y or n. $" \ | |
112 | "y" | |
113 | } | |
114 | ||
06d72e16 PA |
115 | # |
116 | # Test procs | |
117 | # | |
118 | ||
b5262cd0 | 119 | proc gdb_collect_args_test_1 {} { |
b5262cd0 YQ |
120 | # Test printing the variables, and also their addresses. We |
121 | # haven't collected any stack, so there's no way GDB can figure | |
122 | # out the latter. | |
8661b11b | 123 | |
b5262cd0 YQ |
124 | gdb_test "print argc" " = <unavailable>" |
125 | gdb_test "print &argc" \ | |
126 | "Can't take address of \"argc\" which isn't an lvalue\." | |
8661b11b | 127 | |
b5262cd0 YQ |
128 | gdb_test "print argi" " = <unavailable>" |
129 | gdb_test "print &argi" \ | |
130 | "Can't take address of \"argi\" which isn't an lvalue\." | |
8661b11b | 131 | |
b5262cd0 YQ |
132 | gdb_test "print argf" " = <unavailable>" |
133 | gdb_test "print &argf" \ | |
134 | "Can't take address of \"argf\" which isn't an lvalue\." | |
8661b11b | 135 | |
b5262cd0 YQ |
136 | gdb_test "print argd" " = <unavailable>" |
137 | gdb_test "print &argd" \ | |
138 | "Can't take address of \"argd\" which isn't an lvalue\." | |
8661b11b | 139 | |
b5262cd0 | 140 | # struct arg as one of several args (near end of list) |
8661b11b | 141 | |
b5262cd0 | 142 | gdb_test "print argstruct" " = <unavailable>" |
8661b11b | 143 | |
b5262cd0 YQ |
144 | gdb_test "print argstruct.memberc" " = <unavailable>" |
145 | gdb_test "print argstruct.memberi" " = <unavailable>" | |
146 | gdb_test "print argstruct.memberf" " = <unavailable>" | |
147 | gdb_test "print argstruct.memberd" " = <unavailable>" | |
8661b11b | 148 | |
b5262cd0 | 149 | gdb_test "print argarray" " = <unavailable>" |
8661b11b | 150 | |
b5262cd0 YQ |
151 | gdb_test "print &argarray" \ |
152 | "Can't take address of \"argarray\" which isn't an lvalue\." | |
8661b11b | 153 | |
b5262cd0 | 154 | gdb_test "print argarray\[0\]" "value is not available" |
8661b11b | 155 | |
b5262cd0 | 156 | # Test "info args" |
1f7f972f AB |
157 | set r [multi_line \ |
158 | "argc = <unavailable>" \ | |
159 | "argi = <unavailable>" \ | |
160 | "argf = <unavailable>" \ | |
161 | "argd = <unavailable>" \ | |
162 | "argstruct = <unavailable>" \ | |
163 | "argarray = <unavailable>"] | |
b5262cd0 | 164 | gdb_test "info args" "$r" "info args" |
8661b11b | 165 | |
b5262cd0 YQ |
166 | test_maybe_regvar_display "argc" |
167 | } | |
8661b11b | 168 | |
b5262cd0 YQ |
169 | proc gdb_collect_args_test {} { |
170 | with_test_prefix "unavailable arguments" { | |
171 | global gdb_prompt | |
290a839c YQ |
172 | global testfile srcdir subdir binfile |
173 | global trace_file_targets | |
8661b11b | 174 | |
b5262cd0 | 175 | prepare_for_trace_test |
8661b11b | 176 | |
b5262cd0 YQ |
177 | gdb_test "trace args_test_func" \ |
178 | "Tracepoint \[0-9\]+ at .*" \ | |
179 | "set tracepoint" | |
180 | ||
181 | # Begin the test. | |
182 | run_trace_experiment args_test_func | |
183 | ||
184 | gdb_collect_args_test_1 | |
af6e93b2 | 185 | |
0a251e08 YQ |
186 | gdb_test "tfind none" \ |
187 | "#0 end .*" \ | |
188 | "cease trace debugging" | |
290a839c YQ |
189 | |
190 | set tracefile [standard_output_file ${testfile}] | |
191 | gdb_test "tsave ${tracefile}.args.tfile" \ | |
1f7f972f | 192 | "Trace data saved to file '${tracefile}.args.tfile'\\." \ |
290a839c YQ |
193 | "tsave ${testfile}.args.tfile" |
194 | gdb_test "tsave -ctf ${tracefile}.args.ctf" \ | |
1f7f972f | 195 | "Trace data saved to directory '${tracefile}.args.ctf'\\." \ |
290a839c YQ |
196 | "save ctf trace file" |
197 | ||
198 | foreach target_name ${trace_file_targets} { | |
199 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
a7e727ae | 200 | clean_restart |
290a839c YQ |
201 | gdb_file_cmd $binfile |
202 | gdb_test "target ${target_name} ${tracefile}.args.${target_name}" ".*" \ | |
203 | "change to ${target_name} target" | |
204 | ||
205 | with_test_prefix "${target_name}" { | |
206 | gdb_test "tfind start" "#0 args_test_func .*" \ | |
207 | "tfind test frame" | |
208 | gdb_collect_args_test_1 | |
209 | } | |
210 | } | |
0a251e08 YQ |
211 | } |
212 | } | |
8661b11b | 213 | |
b5262cd0 | 214 | proc gdb_collect_locals_test_1 { func } { |
b5262cd0 YQ |
215 | gdb_test "print locc" " = <unavailable>" |
216 | gdb_test "print loci" " = <unavailable>" | |
217 | gdb_test "print locf" " = <unavailable>" | |
218 | gdb_test "print locd" " = <unavailable>" | |
219 | ||
220 | gdb_test "print locst.memberc" " = <unavailable>" | |
221 | gdb_test "print locst.memberi" " = <unavailable>" | |
222 | gdb_test "print locst.memberf" " = <unavailable>" | |
223 | gdb_test "print locst.memberd" " = <unavailable>" | |
224 | ||
225 | gdb_test "print locar\[0\]" " = <unavailable>" | |
226 | gdb_test "print locar\[1\]" " = <unavailable>" | |
227 | gdb_test "print locar\[2\]" " = <unavailable>" | |
228 | gdb_test "print locar\[3\]" " = <unavailable>" | |
229 | ||
230 | # Test "info locals" | |
231 | set r "" | |
1f7f972f AB |
232 | set r "${r}locf = <unavailable>" |
233 | set r "${r}locd = <unavailable>" | |
234 | set r "${r}locst = <unavailable>" | |
235 | set r "${r}locar = <unavailable>" | |
236 | set r "${r}i = <unavailable>" | |
b5262cd0 | 237 | if { $func == "local_test_func" } { |
1f7f972f | 238 | set r "${r}locdefst = <unavailable>" |
b5262cd0 | 239 | } |
1f7f972f AB |
240 | set r "${r}locc = <unavailable>" |
241 | set r "${r}loci = <unavailable>" | |
b5262cd0 YQ |
242 | gdb_test "info locals" "$r" "info locals" |
243 | ||
244 | test_maybe_regvar_display "loci" | |
245 | } | |
246 | ||
0a251e08 YQ |
247 | proc gdb_collect_locals_test { func msg } { |
248 | with_test_prefix "unavailable locals: $msg" { | |
0a251e08 | 249 | global gdb_prompt |
290a839c YQ |
250 | global testfile srcdir subdir binfile |
251 | global trace_file_targets | |
8661b11b | 252 | |
0a251e08 | 253 | prepare_for_trace_test |
8661b11b | 254 | |
0a251e08 | 255 | set testline [gdb_get_line_number "set $func tracepoint here"] |
8661b11b | 256 | |
0a251e08 | 257 | gdb_test "trace $testline" \ |
8661b11b PA |
258 | "Tracepoint \[0-9\]+ at .*" \ |
259 | "set tracepoint" | |
260 | ||
0a251e08 YQ |
261 | # Begin the test. |
262 | run_trace_experiment $func | |
263 | ||
b5262cd0 | 264 | gdb_collect_locals_test_1 $func |
af6e93b2 | 265 | |
0a251e08 YQ |
266 | gdb_test "tfind none" \ |
267 | "#0 end .*" \ | |
268 | "cease trace debugging" | |
290a839c YQ |
269 | |
270 | set tracefile [standard_output_file ${testfile}] | |
271 | gdb_test "tsave ${tracefile}.locals.tfile" \ | |
1f7f972f | 272 | "Trace data saved to file '${tracefile}.locals.tfile'\\." \ |
290a839c YQ |
273 | "tsave ${testfile}.locals.tfile" |
274 | gdb_test "tsave -ctf ${tracefile}.locals.ctf" \ | |
1f7f972f | 275 | "Trace data saved to directory '${tracefile}.locals.ctf'\\." \ |
290a839c YQ |
276 | "save ctf trace file" |
277 | ||
278 | foreach target_name ${trace_file_targets} { | |
279 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
a7e727ae | 280 | clean_restart |
290a839c YQ |
281 | gdb_file_cmd $binfile |
282 | gdb_test "target ${target_name} ${tracefile}.locals.${target_name}" ".*" \ | |
283 | "change to ${target_name} target" | |
284 | ||
285 | with_test_prefix "${target_name}" { | |
286 | gdb_test "tfind start" "#0 $func .*" \ | |
287 | "tfind test frame" | |
288 | gdb_collect_locals_test_1 $func | |
289 | } | |
290 | } | |
0a251e08 YQ |
291 | } |
292 | } | |
8661b11b | 293 | |
b5262cd0 YQ |
294 | proc gdb_unavailable_registers_test_1 { } { |
295 | global spreg | |
296 | global pcreg | |
297 | ||
298 | # On some archs, the $sp/$pc are a real raw registers. On others, | |
299 | # like x86, they're user registers. Test both variants. | |
300 | test_register_unavailable "\$$spreg" | |
301 | test_register_unavailable "\$sp" | |
302 | ||
303 | # Test reading uncollected pseudo-registers. The set of which | |
304 | # depends on target. | |
305 | if [is_amd64_regs_target] { | |
306 | # Check the raw register first. | |
307 | test_register_unavailable "\$rax" | |
308 | test_register_unavailable "\$eax" | |
309 | test_register_unavailable "\$ax" | |
310 | } elseif [is_x86_like_target] { | |
311 | # Check the raw register first. | |
312 | test_register_unavailable "\$eax" | |
313 | test_register_unavailable "\$ax" | |
314 | } | |
315 | ||
316 | # GDBserver always provides the PC value of regular tracepoint | |
317 | # hits, since it's the same as the tracepoint's address. | |
318 | test_register "\$$pcreg" | |
319 | test_register "\$pc" | |
320 | ||
321 | gdb_test "info registers" \ | |
4000e47e | 322 | ".*<unavailable>.*<unavailable>.*" \ |
b5262cd0 YQ |
323 | "info registers, multiple registers not available" |
324 | ||
325 | gdb_test "info registers \$$spreg" \ | |
326 | "<unavailable>" \ | |
327 | "info registers \$$spreg reports not available" | |
328 | } | |
329 | ||
0a251e08 YQ |
330 | proc gdb_unavailable_registers_test { } { |
331 | with_test_prefix "unavailable registers" { | |
290a839c YQ |
332 | global testfile srcdir subdir binfile |
333 | global trace_file_targets | |
0fdb4f18 | 334 | |
0a251e08 | 335 | prepare_for_trace_test |
0fdb4f18 | 336 | |
0a251e08 YQ |
337 | # We'll simply re-use the globals_test_function for this test |
338 | gdb_test "trace globals_test_func" \ | |
0fdb4f18 PA |
339 | "Tracepoint \[0-9\]+ at .*" \ |
340 | "set tracepoint" | |
341 | ||
0a251e08 YQ |
342 | # Collect nothing. |
343 | ||
344 | # Begin the test. | |
345 | run_trace_experiment globals_test_func | |
0fdb4f18 | 346 | |
b5262cd0 | 347 | gdb_unavailable_registers_test_1 |
0a251e08 YQ |
348 | |
349 | gdb_test "tfind none" "#0 end .*" "cease trace debugging" | |
290a839c YQ |
350 | |
351 | set tracefile [standard_output_file ${testfile}] | |
352 | gdb_test "tsave ${tracefile}.registers.tfile" \ | |
1f7f972f | 353 | "Trace data saved to file '${tracefile}.registers.tfile'\\." \ |
290a839c YQ |
354 | "tsave ${testfile}.registers.tfile" |
355 | gdb_test "tsave -ctf ${tracefile}.registers.ctf" \ | |
1f7f972f | 356 | "Trace data saved to directory '${tracefile}.registers.ctf'\\." \ |
290a839c YQ |
357 | "save ctf trace file" |
358 | ||
359 | foreach target_name ${trace_file_targets} { | |
360 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
a7e727ae | 361 | clean_restart |
290a839c YQ |
362 | gdb_file_cmd $binfile |
363 | gdb_test "target ${target_name} ${tracefile}.registers.${target_name}" ".*" \ | |
364 | "change to ${target_name} target" | |
365 | ||
366 | with_test_prefix "${target_name}" { | |
367 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
368 | "tfind test frame" | |
369 | gdb_unavailable_registers_test_1 | |
370 | } | |
371 | } | |
0a251e08 YQ |
372 | } |
373 | } | |
0fdb4f18 | 374 | |
b5262cd0 | 375 | proc gdb_unavailable_floats_1 { } { |
ad5f7d6e PA |
376 | global gdb_prompt |
377 | ||
b5262cd0 YQ |
378 | # Necessarily target specific. |
379 | if {[istarget "x86_64-*-*"] || [istarget i?86-*]} { | |
380 | send_gdb "info float\n" | |
381 | gdb_expect_list "info float" ".*$gdb_prompt $" { | |
382 | "Status Word: <unavailable>" | |
383 | "Control Word: <unavailable>" | |
384 | "Tag Word: <unavailable>" | |
385 | "Instruction Pointer: <unavailable>:<unavailable>" | |
386 | "Operand Pointer: <unavailable>:<unavailable>" | |
387 | "Opcode: <unavailable>" | |
388 | } | |
389 | } | |
390 | } | |
391 | ||
392 | proc gdb_unavailable_floats { } { | |
ad5f7d6e | 393 | with_test_prefix "unavailable floats" { |
290a839c YQ |
394 | global testfile srcdir subdir binfile |
395 | global trace_file_targets | |
396 | ||
ad5f7d6e PA |
397 | prepare_for_trace_test |
398 | ||
399 | # We'll simply re-use the globals_test_function for this test | |
400 | gdb_test "trace globals_test_func" \ | |
401 | "Tracepoint \[0-9\]+ at .*" \ | |
402 | "set tracepoint" | |
403 | ||
404 | # Collect nothing. | |
405 | ||
406 | # Begin the test. | |
407 | run_trace_experiment globals_test_func | |
408 | ||
b5262cd0 | 409 | gdb_unavailable_floats_1 |
ad5f7d6e PA |
410 | |
411 | gdb_test "tfind none" "#0 end .*" "cease trace debugging" | |
290a839c YQ |
412 | |
413 | set tracefile [standard_output_file ${testfile}] | |
414 | gdb_test "tsave ${tracefile}.floats.tfile" \ | |
1f7f972f | 415 | "Trace data saved to file '${tracefile}.floats.tfile'\\." \ |
290a839c YQ |
416 | "tsave ${testfile}.floats.tfile" |
417 | gdb_test "tsave -ctf ${tracefile}.floats.ctf" \ | |
1f7f972f | 418 | "Trace data saved to directory '${tracefile}.floats.ctf'\\." \ |
290a839c YQ |
419 | "save ctf trace file" |
420 | ||
421 | foreach target_name ${trace_file_targets} { | |
422 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
a7e727ae | 423 | clean_restart |
290a839c YQ |
424 | gdb_file_cmd $binfile |
425 | gdb_test "target ${target_name} ${tracefile}.floats.${target_name}" ".*" \ | |
426 | "change to ${target_name} target" | |
427 | ||
428 | with_test_prefix "${target_name}" { | |
429 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
430 | "tfind test frame" | |
431 | gdb_unavailable_floats_1 | |
432 | } | |
433 | } | |
ad5f7d6e PA |
434 | } |
435 | } | |
436 | ||
b5262cd0 YQ |
437 | proc gdb_collect_globals_test_1 { } { |
438 | global ws | |
b5262cd0 YQ |
439 | global gdb_prompt |
440 | global hex | |
06d72e16 | 441 | |
b5262cd0 YQ |
442 | gdb_test "print globalc" " = <unavailable>" |
443 | gdb_test "print globali" " = <unavailable>" | |
444 | gdb_test "print globalf" " = <unavailable>" | |
445 | gdb_test "print globald" " = <unavailable>" | |
06d72e16 | 446 | |
b5262cd0 YQ |
447 | gdb_test "print globalstruct.memberc" " = <unavailable>" |
448 | gdb_test "print globalstruct.memberi" " = <unavailable>" | |
449 | gdb_test "print globalstruct.memberf" " = <unavailable>" | |
450 | gdb_test "print globalstruct.memberd" " = <unavailable>" | |
06d72e16 | 451 | |
b5262cd0 | 452 | gdb_test "print globalstruct" " = <unavailable>" |
06d72e16 | 453 | |
b5262cd0 YQ |
454 | gdb_test "print globalp == &globalstruct" \ |
455 | "value is not available" \ | |
456 | "can't compare using non collected global pointer" | |
0a251e08 | 457 | |
b5262cd0 YQ |
458 | gdb_test "print globalarr\[1\]" " = <unavailable>" |
459 | gdb_test "print globalarr\[2\]" " = <unavailable>" | |
460 | gdb_test "print globalarr\[3\]" " = <unavailable>" | |
0a251e08 | 461 | |
b5262cd0 YQ |
462 | gdb_test "print struct_b" \ |
463 | " = {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>}" | |
0a251e08 | 464 | |
b5262cd0 YQ |
465 | gdb_test "print /x struct_b" \ |
466 | " = {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>}" | |
0a251e08 | 467 | |
b5262cd0 YQ |
468 | gdb_test "print /x struct_b.struct_a" \ |
469 | " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}" | |
06d72e16 | 470 | |
b5262cd0 YQ |
471 | gdb_test "print /x struct_b.struct_a.array" \ |
472 | " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}" | |
06d72e16 | 473 | |
b5262cd0 | 474 | gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>" |
06d72e16 | 475 | |
b5262cd0 | 476 | gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa" |
06d72e16 | 477 | |
b5262cd0 YQ |
478 | # Check the target doesn't overcollect. GDB used to merge memory |
479 | # ranges to collect if they were close enough (collecting the hole | |
480 | # as well), but does not do that anymore. It's plausible that a | |
481 | # target may do this on its end, but as of this writing, no known | |
482 | # target does it. | |
483 | gdb_test "print {a, b, c}" \ | |
484 | " = \\{1, <unavailable>, 3\\}" \ | |
485 | "No overcollect of almost but not quite adjacent memory ranges" | |
06d72e16 | 486 | |
b5262cd0 | 487 | # Check <unavailable> isn't confused with 0 in array element repetitions |
06d72e16 | 488 | |
b5262cd0 | 489 | gdb_test_no_output "set print repeat 1" |
06d72e16 | 490 | |
b5262cd0 YQ |
491 | gdb_test "print /x tarray" \ |
492 | " = \{\{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>\}" \ | |
493 | "<unavailable> is not the same as 0 in array element repetitions" | |
06d72e16 | 494 | |
b5262cd0 | 495 | gdb_test_no_output "set print repeat 10" |
06d72e16 | 496 | |
b5262cd0 YQ |
497 | # Check that value repeat handles unavailable-ness. |
498 | gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}" | |
1b28d0b3 | 499 | |
b5262cd0 | 500 | # Static fields |
06d72e16 | 501 | |
b5262cd0 | 502 | gdb_test "print struct_b.static_struct_a" " = <unavailable>" |
06d72e16 | 503 | |
b5262cd0 | 504 | # Bitfields |
06d72e16 | 505 | |
b5262cd0 | 506 | gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>" |
06d72e16 | 507 | |
b5262cd0 | 508 | # References |
24e6bcee | 509 | |
b5262cd0 | 510 | gdb_test "print g_int" " = <unavailable>" |
06d72e16 | 511 | |
b5262cd0 YQ |
512 | gdb_test "print g_ref" \ |
513 | "\\(int &\\) @$hex: <unavailable>" \ | |
514 | "global reference shows address but not value" | |
06d72e16 | 515 | |
b5262cd0 | 516 | gdb_test "print *&g_ref" \ |
1f7f972f | 517 | "\\$\[0-9\]+ = <unavailable>" \ |
b5262cd0 | 518 | "referenced integer was not collected (taking address of reference)" |
06d72e16 | 519 | |
b5262cd0 | 520 | gdb_test "print *g_structref_p" " = <unavailable>" |
06d72e16 | 521 | |
b5262cd0 | 522 | # Strings |
06d72e16 | 523 | |
b5262cd0 YQ |
524 | # Const string is always available, even when not collected. |
525 | gdb_test "print g_const_string" \ | |
1f7f972f | 526 | " = \"hello world\"" \ |
b5262cd0 | 527 | "non collected const string is still printable" |
06d72e16 | 528 | |
b5262cd0 YQ |
529 | gdb_test "print g_string_p" \ |
530 | " = $hex <g_const_string> \"hello world\"" \ | |
531 | "printing constant string through collected pointer" | |
06d72e16 | 532 | |
b5262cd0 YQ |
533 | gdb_test "print g_string_unavail" \ |
534 | " = <unavailable>" \ | |
535 | "printing non collected string" | |
06d72e16 | 536 | |
b5262cd0 YQ |
537 | # Incomplete strings print as an array. |
538 | gdb_test "print g_string_partial" \ | |
539 | "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \ | |
540 | "printing partially collected string" | |
06d72e16 | 541 | |
b5262cd0 YQ |
542 | # It is important for this test that the last examined value is |
543 | # <unavailable>, to exercise the case of the $__ convenience | |
544 | # variable being set to <unavailable> without error. | |
545 | set msg "examining partially collected object" | |
546 | gdb_test_multiple "x /10x &struct_b" "$msg" { | |
1f7f972f | 547 | -re "$hex <struct_b>:${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>${ws}<unavailable>\r\n$hex <struct_b\\+16>:${ws}<unavailable>${ws}<unavailable>${ws}0xaaaaaaaa${ws}<unavailable>\r\n$hex <struct_b\\+32>:${ws}<unavailable>${ws}<unavailable>\r\n$gdb_prompt $" { |
b5262cd0 YQ |
548 | pass "$msg" |
549 | } | |
550 | -re "value is not available" { | |
551 | fail "$msg" | |
552 | } | |
553 | } | |
06d72e16 | 554 | |
b5262cd0 | 555 | gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>" |
06d72e16 | 556 | |
b5262cd0 YQ |
557 | # This tests that building the array does not require accessing |
558 | # g_int's contents. | |
559 | gdb_test "print { 1, g_int, 3 }" \ | |
560 | " = \\{1, <unavailable>, 3\\}" \ | |
561 | "build array from unavailable value" | |
06d72e16 | 562 | |
b5262cd0 YQ |
563 | # Note, depends on previous test. |
564 | gdb_test "print \$\[1\]" \ | |
565 | " = <unavailable>" \ | |
566 | "subscript a non-memory rvalue array, accessing an unvailable element" | |
06d72e16 | 567 | |
b5262cd0 YQ |
568 | # Access a field of a non-lazy value, making sure the |
569 | # unavailable-ness is propagated. History values are easy | |
570 | # non-lazy values, so use those. The first test just sets up for | |
571 | # the second. | |
572 | gdb_test "print g_smallstruct" " = <unavailable>" | |
573 | gdb_test "print \$.member" " = <unavailable>" | |
06d72e16 | 574 | |
b5262cd0 YQ |
575 | # Cast to baseclass, checking the unavailable-ness is propagated. |
576 | gdb_test "print (small_struct) g_smallstruct_b" " = <unavailable>" | |
06d72e16 | 577 | |
b5262cd0 YQ |
578 | # Same cast, but starting from a non-lazy, value. |
579 | gdb_test "print g_smallstruct_b" " = <unavailable>" | |
580 | gdb_test "print (small_struct) \$" " = <unavailable>" | |
0a251e08 | 581 | |
b5262cd0 | 582 | gdb_test_no_output "set print object on" |
0a251e08 | 583 | |
b5262cd0 YQ |
584 | with_test_prefix "print object on" { |
585 | # With print object on, printing a pointer may need to fetch | |
586 | # the pointed-to object, to check its run-time type. Make | |
587 | # sure that fails gracefully and transparently when the | |
588 | # pointer itself is unavailable. | |
589 | gdb_test "print virtualp" " = <unavailable>" | |
0a251e08 | 590 | |
b5262cd0 YQ |
591 | # no vtable pointer available |
592 | gdb_test "print derived_unavail" " = <unavailable>" | |
0a251e08 | 593 | |
b5262cd0 YQ |
594 | # vtable pointer available, but nothing else |
595 | gdb_test "print derived_partial" \ | |
596 | " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}" | |
0a251e08 | 597 | |
b5262cd0 YQ |
598 | # whole object available |
599 | gdb_test "print derived_whole" \ | |
0a5d52f0 | 600 | " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = ${hex}( <\[^>]*>)?, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}" |
b5262cd0 | 601 | } |
0a251e08 | 602 | |
b5262cd0 | 603 | gdb_test_no_output "set print object off" |
0a251e08 | 604 | |
b5262cd0 YQ |
605 | with_test_prefix "print object off" { |
606 | gdb_test "print virtualp" " = <unavailable>" | |
0a251e08 | 607 | |
b5262cd0 YQ |
608 | # no vtable pointer available |
609 | gdb_test "print derived_unavail" \ | |
610 | " = <unavailable>" | |
0a251e08 | 611 | |
b5262cd0 YQ |
612 | # vtable pointer available, but nothing else |
613 | gdb_test "print derived_partial" \ | |
614 | " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex <vtable for Derived.*>, z = <unavailable>}" | |
0a251e08 | 615 | |
b5262cd0 YQ |
616 | # whole object available |
617 | gdb_test "print derived_whole" \ | |
0a5d52f0 | 618 | " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = ${hex}( <\[^>]*>)?, y = 3}, _vptr.Derived = $hex <vtable for Derived.*>, z = 4}" |
b5262cd0 YQ |
619 | } |
620 | ||
621 | # An instance of a virtual class where we collected everything but | |
622 | # the vptr. | |
623 | gdb_test "print virtual_partial" \ | |
624 | " = {_vptr.Virtual = <unavailable>, z = 0}" | |
625 | } | |
8af8e3bc | 626 | |
b5262cd0 YQ |
627 | proc gdb_collect_globals_test { } { |
628 | with_test_prefix "collect globals" { | |
290a839c YQ |
629 | global testfile binfile srcdir subdir |
630 | global trace_file_targets | |
631 | ||
b5262cd0 | 632 | prepare_for_trace_test |
ec0a52e1 | 633 | |
b5262cd0 | 634 | set testline [gdb_get_line_number "set globals_test_func tracepoint here"] |
8af8e3bc | 635 | |
b5262cd0 YQ |
636 | gdb_test "trace $testline" \ |
637 | "Tracepoint \[0-9\]+ at .*" \ | |
638 | "set tracepoint" | |
8af8e3bc | 639 | |
b5262cd0 YQ |
640 | # We collect the initial sizeof(pointer) bytes of derived_partial |
641 | # in an attempt of collecting the vptr. Not portable, but should | |
642 | # work everywhere we need to care. | |
643 | gdb_trace_setactions "define actions" \ | |
644 | "" \ | |
645 | "collect struct_b.struct_a.array\[2\]" "^$" \ | |
646 | "collect struct_b.struct_a.array\[100\]" "^$" \ | |
647 | \ | |
648 | "collect a" "^$" \ | |
649 | "collect c" "^$" \ | |
650 | \ | |
651 | "collect tarray\[0\].a" "^$" \ | |
652 | "collect tarray\[1\].a" "^$" \ | |
653 | "collect tarray\[3\].a" "^$" \ | |
654 | "collect tarray\[3\].b" "^$" \ | |
655 | "collect tarray\[4\].b" "^$" \ | |
656 | "collect tarray\[5\].b" "^$" \ | |
657 | \ | |
658 | "collect g_string_p" "^$" \ | |
659 | "collect g_string_partial\[1\]" "^$" \ | |
660 | "collect g_string_partial\[2\]" "^$" \ | |
661 | \ | |
662 | "collect g_structref_p" "^$" \ | |
663 | \ | |
664 | "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \ | |
665 | "collect derived_whole" "^$" \ | |
666 | \ | |
667 | "collect virtual_partial.z" "^$" | |
8af8e3bc | 668 | |
b5262cd0 YQ |
669 | # Begin the test. |
670 | run_trace_experiment globals_test_func | |
8af8e3bc | 671 | |
b5262cd0 | 672 | gdb_collect_globals_test_1 |
8af8e3bc | 673 | |
0a251e08 YQ |
674 | gdb_test "tfind none" \ |
675 | "#0 end .*" \ | |
676 | "cease trace debugging" | |
290a839c YQ |
677 | |
678 | set tracefile [standard_output_file ${testfile}] | |
679 | gdb_test "tsave ${tracefile}.globals.tfile" \ | |
1f7f972f | 680 | "Trace data saved to file '${tracefile}.globals.tfile'\\." \ |
290a839c YQ |
681 | "tsave ${testfile}.globals.tfile" |
682 | gdb_test "tsave -ctf ${tracefile}.globals.ctf" \ | |
1f7f972f | 683 | "Trace data saved to directory '${tracefile}.globals.ctf'\\." \ |
290a839c YQ |
684 | "save ctf trace file" |
685 | ||
686 | foreach target_name ${trace_file_targets} { | |
687 | # Restart GDB and read the trace data in ${TARGET_NAME} target. | |
a7e727ae | 688 | clean_restart |
290a839c YQ |
689 | gdb_file_cmd $binfile |
690 | gdb_test "target ${target_name} ${tracefile}.globals.${target_name}" ".*" \ | |
691 | "change to ${target_name} target" | |
692 | ||
693 | with_test_prefix "${target_name}" { | |
694 | gdb_test "tfind start" "#0 globals_test_func .*" \ | |
695 | "tfind test frame" | |
696 | gdb_collect_globals_test_1 | |
697 | } | |
698 | } | |
699 | ||
0a251e08 YQ |
700 | } |
701 | } | |
06d72e16 PA |
702 | |
703 | proc gdb_trace_collection_test {} { | |
704 | gdb_collect_globals_test | |
0fdb4f18 | 705 | gdb_unavailable_registers_test |
ad5f7d6e | 706 | gdb_unavailable_floats |
8661b11b PA |
707 | |
708 | gdb_collect_args_test | |
709 | gdb_collect_locals_test local_test_func "auto locals" | |
710 | gdb_collect_locals_test reglocal_test_func "register locals" | |
711 | gdb_collect_locals_test statlocal_test_func "static locals" | |
06d72e16 PA |
712 | } |
713 | ||
06d72e16 PA |
714 | runto_main |
715 | ||
89c6d320 | 716 | if {![gdb_target_supports_trace]} { |
bc6c7af4 | 717 | unsupported "current target does not support trace" |
ae59b1da | 718 | return 1 |
06d72e16 PA |
719 | } |
720 | ||
290a839c YQ |
721 | set trace_file_targets [list "tfile"] |
722 | gdb_test_multiple "target ctf" "" { | |
723 | -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" { | |
724 | } | |
725 | -re "No CTF directory specified.*\r\n$gdb_prompt $" { | |
726 | lappend trace_file_targets "ctf" | |
727 | } | |
728 | } | |
729 | ||
06d72e16 PA |
730 | # Body of test encased in a proc so we can return prematurely. |
731 | gdb_trace_collection_test | |
732 | ||
733 | # Finished! | |
734 | gdb_test "tfind none" ".*" "" |