gdb/
[deliverable/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 #
34 # Utility procs
35 #
36
37 proc prepare_for_trace_test {} {
38 global executable
39
40 clean_restart $executable
41
42 runto_main
43
44 gdb_test "break begin" ".*" ""
45 gdb_test "break end" ".*" ""
46 }
47
48 proc run_trace_experiment { test_func } {
49 global gdb_prompt
50
51 gdb_test "continue" \
52 ".*Breakpoint \[0-9\]+, begin .*" \
53 "advance to begin"
54
55 gdb_test_no_output "tstart" "start trace experiment"
56
57 gdb_test "continue" \
58 "Continuing.*Breakpoint \[0-9\]+, end.*" \
59 "run trace experiment"
60 gdb_test "tstop" \
61 "\[\r\n\]+" \
62 "stop trace experiment"
63 gdb_test "tfind start" \
64 "#0 $test_func .*" \
65 "tfind test frame"
66 }
67
68 #
69 # Test procs
70 #
71
72 proc gdb_collect_globals_test { } {
73 global ws
74 global cr
75 global gdb_prompt
76 global hex
77 global pf_prefix
78
79 set old_pf_prefix $pf_prefix
80 set pf_prefix "$pf_prefix collect globals:"
81
82 prepare_for_trace_test
83
84 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
85
86 gdb_test "trace $testline" \
87 "Tracepoint \[0-9\]+ at .*" \
88 "set tracepoint"
89
90 # We collect the initial sizeof(pointer) bytes of derived_partial
91 # in an attempt of collecting the vptr. Not portable, but should
92 # work everywhere we need to care.
93 gdb_trace_setactions "define actions" \
94 "" \
95 "collect struct_b.struct_a.array\[2\]" "^$" \
96 "collect struct_b.struct_a.array\[100\]" "^$" \
97 \
98 "collect a" "^$" \
99 "collect c" "^$" \
100 \
101 "collect tarray\[0\].a" "^$" \
102 "collect tarray\[1\].a" "^$" \
103 "collect tarray\[3\].a" "^$" \
104 "collect tarray\[3\].b" "^$" \
105 "collect tarray\[4\].b" "^$" \
106 "collect tarray\[5\].b" "^$" \
107 \
108 "collect g_string_p" "^$" \
109 "collect g_string_partial\[1\]" "^$" \
110 "collect g_string_partial\[2\]" "^$" \
111 \
112 "collect g_structref_p" "^$" \
113 \
114 "collect *((char *)&derived_partial)@sizeof\(void *\)" "^$" \
115 "collect derived_whole" "^$" \
116 \
117 "collect virtual_partial.z" "^$"
118
119 # Begin the test.
120 run_trace_experiment globals_test_func
121
122 gdb_test "print globalc" " = <unavailable>"
123 gdb_test "print globali" " = <unavailable>"
124 gdb_test "print globalf" " = <unavailable>"
125 gdb_test "print globald" " = <unavailable>"
126
127 gdb_test "print globalstruct.memberc" " = <unavailable>"
128 gdb_test "print globalstruct.memberi" " = <unavailable>"
129 gdb_test "print globalstruct.memberf" " = <unavailable>"
130 gdb_test "print globalstruct.memberd" " = <unavailable>"
131
132 gdb_test "print globalstruct" \
133 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
134
135 gdb_test "print globalp == &globalstruct" \
136 "value is not available" \
137 "can't compare using non collected global pointer"
138
139 gdb_test "print globalarr\[1\]" " = <unavailable>"
140 gdb_test "print globalarr\[2\]" " = <unavailable>"
141 gdb_test "print globalarr\[3\]" " = <unavailable>"
142
143 gdb_test "print struct_b" \
144 " = {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>}"
145
146 gdb_test "print /x struct_b" \
147 " = {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>}"
148
149 gdb_test "print /x struct_b.struct_a" \
150 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
151
152 gdb_test "print /x struct_b.struct_a.array" \
153 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
154
155 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
156
157 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
158
159 # Check the target doesn't overcollect. GDB used to merge memory
160 # ranges to collect if they were close enough (collecting the hole
161 # as well), but does not do that anymore. It's plausible that a
162 # target may do this on its end, but as of this writing, no known
163 # target does it.
164 gdb_test "print {a, b, c}" \
165 " = \\{1, <unavailable>, 3\\}" \
166 "No overcollect of almost but not quite adjacent memory ranges"
167
168 # Check <unavailable> isn't confused with 0 in array element repetitions
169
170 gdb_test_no_output "set print repeat 1"
171
172 gdb_test "print /x tarray" \
173 " = \{\{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>\}" \
174 "<unavailable> is not the same as 0 in array element repetitions"
175
176 gdb_test_no_output "set print repeat 10"
177
178 # Check that value repeat handles unavailable-ness.
179 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
180
181 # Static fields
182
183 gdb_test "print struct_b.static_struct_a" \
184 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
185
186 # Bitfields
187
188 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
189
190 # References
191
192 gdb_test "print g_int" " = <unavailable>"
193
194 gdb_test "print g_ref" \
195 "\\(int &\\) @$hex: <unavailable>" \
196 "global reference shows address but not value"
197
198 gdb_test "print *&g_ref" \
199 "\\$\[0-9\]+ = <unavailable>$cr" \
200 "referenced integer was not collected (taking address of reference)"
201
202 gdb_test "print *g_structref_p" \
203 " = {d = <unavailable>, ref = <unavailable>}"
204
205 # Strings
206
207 # Const string is always available, even when not collected.
208 gdb_test "print g_const_string" \
209 " = \"hello world\"$cr" \
210 "non collected const string is still printable"
211
212 gdb_test "print g_string_p" \
213 " = $hex \"hello world\"" \
214 "printing constant string through collected pointer"
215
216 gdb_test "print g_string_unavail" \
217 " = \{<unavailable> <repeats 12 times>\}" \
218 "printing non collected string"
219
220 # Incomplete strings print as an array.
221 gdb_test "print g_string_partial" \
222 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
223 "printing partially collected string"
224
225 # It is important for this test that the last examined value is
226 # <unavailable>, to exercise the case of the $__ convenience
227 # variable being set to <unavailable> without error.
228 set msg "examining partially collected object"
229 gdb_test_multiple "x /10x &struct_b" "$msg" {
230 -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 $" {
231 pass "$msg"
232 }
233 -re "value is not available" {
234 fail "$msg"
235 }
236 }
237
238 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
239
240 # This tests that building the array does not require accessing
241 # g_int's contents.
242 gdb_test "print { 1, g_int, 3 }" \
243 " = \\{1, <unavailable>, 3\\}" \
244 "build array from unavailable value"
245
246 # Note, depends on previous test.
247 gdb_test "print \$\[1\]" \
248 " = <unavailable>" \
249 "subscript a non-memory rvalue array, accessing an unvailable element"
250
251 # Access a field of a non-lazy value, making sure the
252 # unavailable-ness is propagated. History values are easy
253 # non-lazy values, so use those. The first test just sets up for
254 # the second.
255 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
256 gdb_test "print \$.member" " = <unavailable>"
257
258 # Cast to baseclass, checking the unavailable-ness is propagated.
259 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
260
261 # Same cast, but starting from a non-lazy, value.
262 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
263 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
264
265 gdb_test_no_output "set print object on"
266
267 set old_pf_prefix_2 $pf_prefix
268 set pf_prefix "$pf_prefix print object on:"
269
270 # With print object on, printing a pointer may need to fetch the
271 # pointed-to object, to check its run-time type. Make sure that
272 # fails gracefully and transparently when the pointer itself is
273 # unavailable.
274 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
275
276 # no vtable pointer available
277 gdb_test "print derived_unavail" \
278 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
279
280 # vtable pointer available, but nothing else
281 gdb_test "print derived_partial" \
282 " = \\(Derived\\) {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
283
284 # whole object available
285 gdb_test "print derived_whole" \
286 " = \\(Derived\\) {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
287
288 set pf_prefix $old_pf_prefix_2
289
290 gdb_test_no_output "set print object off"
291
292 set pf_prefix "$pf_prefix print object off:"
293
294 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
295
296 # no vtable pointer available
297 gdb_test "print derived_unavail" \
298 " = {<Middle> = <unavailable>, _vptr.Derived = <unavailable>, z = <unavailable>}"
299
300 # vtable pointer available, but nothing else
301 gdb_test "print derived_partial" \
302 " = {<Middle> = {<Base> = <unavailable>, _vptr.Middle = <unavailable>, y = <unavailable>}, _vptr.Derived = $hex, z = <unavailable>}"
303
304 # whole object available
305 gdb_test "print derived_whole" \
306 " = {<Middle> = {<Base> = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}"
307
308 set pf_prefix $old_pf_prefix_2
309
310 # An instance of a virtual class where we collected everything but
311 # the vptr.
312 gdb_test "print virtual_partial" \
313 " = {_vptr.Virtual = <unavailable>, z = 0}"
314
315 gdb_test "tfind none" \
316 "#0 end .*" \
317 "cease trace debugging"
318
319 set pf_prefix $old_pf_prefix
320 }
321
322 proc gdb_trace_collection_test {} {
323 gdb_collect_globals_test
324 }
325
326 clean_restart $executable
327 runto_main
328
329 # We generously give ourselves one "pass" if we successfully
330 # detect that this test cannot be run on this target!
331 if { ![gdb_target_supports_trace] } then {
332 pass "Current target does not support trace"
333 return 1;
334 }
335
336 # Body of test encased in a proc so we can return prematurely.
337 gdb_trace_collection_test
338
339 # Finished!
340 gdb_test "tfind none" ".*" ""
This page took 0.051 seconds and 5 git commands to generate.