1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 load_lib "trace-support.exp"
19 set testfile "unavailable"
20 set srcfile ${testfile}.cc
21 set executable $testfile
22 set binfile $objdir/$subdir/$executable
24 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
25 executable {debug nowarnings c++}] != "" } {
26 untested unavailable.exp
37 proc prepare_for_trace_test {} {
40 clean_restart $executable
44 gdb_test "break begin" ".*" ""
45 gdb_test "break end" ".*" ""
48 proc run_trace_experiment { test_func } {
52 ".*Breakpoint \[0-9\]+, begin .*" \
55 gdb_test_no_output "tstart" "start trace experiment"
58 "Continuing.*Breakpoint \[0-9\]+, end.*" \
59 "run trace experiment"
62 "stop trace experiment"
63 gdb_test "tfind start" \
72 proc gdb_collect_globals_test { } {
79 set old_pf_prefix $pf_prefix
80 set pf_prefix "$pf_prefix collect globals:"
82 prepare_for_trace_test
84 set testline [gdb_get_line_number "set globals_test_func tracepoint here"]
86 gdb_test "trace $testline" \
87 "Tracepoint \[0-9\]+ at .*" \
90 gdb_trace_setactions "define actions" \
92 "collect struct_b.struct_a.array\[2\]" "^$" \
93 "collect struct_b.struct_a.array\[100\]" "^$" \
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" "^$" \
105 "collect g_string_p" "^$" \
106 "collect g_string_partial\[1\]" "^$" \
107 "collect g_string_partial\[2\]" "^$" \
109 "collect g_structref_p" "^$"
112 run_trace_experiment globals_test_func
114 gdb_test "print globalc" " = <unavailable>"
115 gdb_test "print globali" " = <unavailable>"
116 gdb_test "print globalf" " = <unavailable>"
117 gdb_test "print globald" " = <unavailable>"
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>"
124 gdb_test "print globalstruct" \
125 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
127 gdb_test "print globalp == &globalstruct" \
128 "value is not available" \
129 "can't compare using non collected global pointer"
131 gdb_test "print globalarr\[1\]" " = <unavailable>"
132 gdb_test "print globalarr\[2\]" " = <unavailable>"
133 gdb_test "print globalarr\[3\]" " = <unavailable>"
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>}"
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>}"
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>}"
144 gdb_test "print /x struct_b.struct_a.array" \
145 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
147 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
149 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
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
156 gdb_test "print {a, b, c}" \
157 " = \\{1, <unavailable>, 3\\}" \
158 "No overcollect of almost but not quite adjacent memory ranges"
160 # Check <unavailable> isn't confused with 0 in array element repetitions
162 gdb_test_no_output "set print repeat 1"
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"
168 gdb_test_no_output "set print repeat 10"
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>\\}\\}"
175 gdb_test "print struct_b.static_struct_a" \
176 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
180 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
184 gdb_test "print g_int" " = <unavailable>"
186 gdb_test "print g_ref" \
187 "\\(int &\\) @$hex: <unavailable>" \
188 "global reference shows address but not value"
190 gdb_test "print *&g_ref" \
191 "\\$\[0-9\]+ = <unavailable>$cr" \
192 "referenced integer was not collected (taking address of reference)"
194 gdb_test "print *g_structref_p" \
195 " = {d = <unavailable>, ref = <unavailable>}"
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"
204 gdb_test "print g_string_p" \
205 " = $hex \"hello world\"" \
206 "printing constant string through collected pointer"
208 gdb_test "print g_string_unavail" \
209 " = \{<unavailable> <repeats 12 times>\}" \
210 "printing non collected string"
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"
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 $" {
225 -re "value is not available" {
230 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
232 # This tests that building the array does not require accessing
234 gdb_test "print { 1, g_int, 3 }" \
235 " = \\{1, <unavailable>, 3\\}" \
236 "build array from unavailable value"
238 # Note, depends on previous test.
239 gdb_test "print \$\[1\]" \
241 "subscript a non-memory rvalue array, accessing an unvailable element"
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
247 gdb_test "print g_smallstruct" " = \\{member = <unavailable>\\}"
248 gdb_test "print \$.member" " = <unavailable>"
250 # Cast to baseclass, checking the unavailable-ness is propagated.
251 gdb_test "print (small_struct) g_smallstruct_b" " = \\{member = <unavailable>\\}"
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>\\}"
257 gdb_test_no_output "set print object on"
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
263 gdb_test "print virtualp" " = \\(Virtual \\*\\) <unavailable>"
265 gdb_test_no_output "set print object off"
267 gdb_test "tfind none" \
269 "cease trace debugging"
271 set pf_prefix $old_pf_prefix
274 proc gdb_trace_collection_test {} {
275 gdb_collect_globals_test
278 clean_restart $executable
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"
288 # Body of test encased in a proc so we can return prematurely.
289 gdb_trace_collection_test
292 gdb_test "tfind none" ".*" ""