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