gdb/testuite/
[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 gdb_trace_setactions "define actions" \
91 "" \
92 "collect struct_b.struct_a.array\[2\]" "^$" \
93 "collect struct_b.struct_a.array\[100\]" "^$" \
94 \
95 "collect a" "^$" \
96 "collect c" "^$" \
97 \
98 "collect tarray\[0\].a" "^$" \
99 "collect tarray\[1\].a" "^$" \
100 "collect tarray\[3\].a" "^$" \
101 "collect tarray\[3\].b" "^$" \
102 "collect tarray\[4\].b" "^$" \
103 "collect tarray\[5\].b" "^$" \
104 \
105 "collect g_string_p" "^$" \
106 "collect g_string_partial\[1\]" "^$" \
107 "collect g_string_partial\[2\]" "^$" \
108 \
109 "collect g_structref_p" "^$"
110
111 # Begin the test.
112 run_trace_experiment globals_test_func
113
114 gdb_test "print globalc" " = <unavailable>"
115 gdb_test "print globali" " = <unavailable>"
116 gdb_test "print globalf" " = <unavailable>"
117 gdb_test "print globald" " = <unavailable>"
118
119 gdb_test "print globalstruct.memberc" " = <unavailable>"
120 gdb_test "print globalstruct.memberi" " = <unavailable>"
121 gdb_test "print globalstruct.memberf" " = <unavailable>"
122 gdb_test "print globalstruct.memberd" " = <unavailable>"
123
124 gdb_test "print globalstruct" \
125 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
126
127 gdb_test "print globalp == &globalstruct" \
128 "value is not available" \
129 "can't compare using non collected global pointer"
130
131 gdb_test "print globalarr\[1\]" " = <unavailable>"
132 gdb_test "print globalarr\[2\]" " = <unavailable>"
133 gdb_test "print globalarr\[3\]" " = <unavailable>"
134
135 gdb_test "print struct_b" \
136 " = {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>}"
137
138 gdb_test "print /x struct_b" \
139 " = {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>}"
140
141 gdb_test "print /x struct_b.struct_a" \
142 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
143
144 gdb_test "print /x struct_b.struct_a.array" \
145 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
146
147 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
148
149 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
150
151 # Check the target doesn't overcollect. GDB used to merge memory
152 # ranges to collect if they were close enough (collecting the hole
153 # as well), but does not do that anymore. It's plausible that a
154 # target may do this on its end, but as of this writing, no known
155 # target does it.
156 gdb_test "print {a, b, c}" \
157 " = \\{1, <unavailable>, 3\\}" \
158 "No overcollect of almost but not quite adjacent memory ranges"
159
160 # Check <unavailable> isn't confused with 0 in array element repetitions
161
162 gdb_test_no_output "set print repeat 1"
163
164 gdb_test "print /x tarray" \
165 " = \{\{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>\}" \
166 "<unavailable> is not the same as 0 in array element repetitions"
167
168 gdb_test_no_output "set print repeat 10"
169
170 # Check that value repeat handles unavailable-ness.
171 gdb_test "print *tarray@3" " = \\{\\{a = 0, b = <unavailable>\\}, \\{a = 0, b = <unavailable>\\}, \\{a = <unavailable>, b = <unavailable>\\}\\}"
172
173 # Static fields
174
175 gdb_test "print struct_b.static_struct_a" \
176 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
177
178 # Bitfields
179
180 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
181
182 # References
183
184 gdb_test "print g_int" " = <unavailable>"
185
186 gdb_test "print g_ref" \
187 "\\(int &\\) @$hex: <unavailable>" \
188 "global reference shows address but not value"
189
190 gdb_test "print *&g_ref" \
191 "\\$\[0-9\]+ = <unavailable>$cr" \
192 "referenced integer was not collected (taking address of reference)"
193
194 gdb_test "print *g_structref_p" \
195 " = {d = <unavailable>, ref = <unavailable>}"
196
197 # Strings
198
199 # Const string is always available, even when not collected.
200 gdb_test "print g_const_string" \
201 " = \"hello world\"$cr" \
202 "non collected const string is still printable"
203
204 gdb_test "print g_string_p" \
205 " = $hex \"hello world\"" \
206 "printing constant string through collected pointer"
207
208 gdb_test "print g_string_unavail" \
209 " = \{<unavailable> <repeats 12 times>\}" \
210 "printing non collected string"
211
212 # Incomplete strings print as an array.
213 gdb_test "print g_string_partial" \
214 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
215 "printing partially collected string"
216
217 # It is important for this test that the last examined value is
218 # <unavailable>, to exercise the case of the $__ convenience
219 # variable being set to <unavailable> without error.
220 set msg "examining partially collected object"
221 gdb_test_multiple "x /10x &struct_b" "$msg" {
222 -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 $" {
223 pass "$msg"
224 }
225 -re "value is not available" {
226 fail "$msg"
227 }
228 }
229
230 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
231
232 # This tests that building the array does not require accessing
233 # g_int's contents.
234 gdb_test "print { 1, g_int, 3 }" \
235 " = \\{1, <unavailable>, 3\\}" \
236 "build array from unavailable value"
237
238 # Note, depends on previous test.
239 gdb_test "print \$\[1\]" \
240 " = <unavailable>" \
241 "subscript a non-memory rvalue array, accessing an unvailable element"
242
243 # Access a field of a non-lazy value, making sure the
244 # unavailable-ness is propagated. History values are easy
245 # non-lazy values, so use those. The first test just sets up for
246 # the second.
247 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
248 gdb_test "print \$.member" " = <unavailable>"
249
250 # Cast to baseclass, checking the unavailable-ness is propagated.
251 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
252
253 # Same cast, but starting from a non-lazy, value.
254 gdb_test "print g_smallstruct_b" " = \\{<small_struct> = \\{member = <unavailable>\\}, <No data fields>\\}"
255 gdb_test "print (small_struct) \$" " = \\{member = <unavailable>\\}"
256
257 gdb_test_no_output "set print object on"
258
259 # With print object on, printing a pointer may need to fetch the
260 # pointed-to object, to check its run-time type. Make sure that
261 # fails gracefully and transparently when the pointer itself is
262 # unavailable.
263 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
264
265 gdb_test_no_output "set print object off"
266
267 gdb_test "tfind none" \
268 "#0 end .*" \
269 "cease trace debugging"
270
271 set pf_prefix $old_pf_prefix
272 }
273
274 proc gdb_trace_collection_test {} {
275 gdb_collect_globals_test
276 }
277
278 clean_restart $executable
279 runto_main
280
281 # We generously give ourselves one "pass" if we successfully
282 # detect that this test cannot be run on this target!
283 if { ![gdb_target_supports_trace] } then {
284 pass "Current target does not support trace"
285 return 1;
286 }
287
288 # Body of test encased in a proc so we can return prematurely.
289 gdb_trace_collection_test
290
291 # Finished!
292 gdb_test "tfind none" ".*" ""
This page took 0.0371 seconds and 5 git commands to generate.