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\]" "^$" \
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" "^$" \
102 "collect g_string_p" "^$" \
103 "collect g_string_partial\[1\]" "^$" \
104 "collect g_string_partial\[2\]" "^$" \
106 "collect g_structref_p" "^$" \
109 run_trace_experiment globals_test_func
111 gdb_test "print globalc" " = <unavailable>"
112 gdb_test "print globali" " = <unavailable>"
113 gdb_test "print globalf" " = <unavailable>"
114 gdb_test "print globald" " = <unavailable>"
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>"
121 gdb_test "print globalstruct" \
122 " = {memberc = <unavailable>, memberi = <unavailable>, memberf = <unavailable>, memberd = <unavailable>}"
124 gdb_test "print globalp == &globalstruct" \
125 "value is not available" \
126 "can't compare using non collected global pointer"
128 gdb_test "print globalarr\[1\]" " = <unavailable>"
129 gdb_test "print globalarr\[2\]" " = <unavailable>"
130 gdb_test "print globalarr\[3\]" " = <unavailable>"
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>}"
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>}"
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>}"
141 gdb_test "print /x struct_b.struct_a.array" \
142 " = {<unavailable>, <unavailable>, 0xaaaaaaaa, <unavailable> <repeats 97 times>, 0xaaaaaaaa, <unavailable> <repeats 9899 times>}"
144 gdb_test "print /x struct_b.struct_a.array\[0\]" " = <unavailable>"
146 gdb_test "print /x struct_b.struct_a.array\[2\]" " = 0xaaaaaaaa"
148 # Check <unavailable> isn't confused with 0 in array element repetitions
150 gdb_test_no_output "set print repeat 1"
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"
156 gdb_test_no_output "set print repeat 10"
160 gdb_test "print struct_b.static_struct_a" \
161 " = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>, bitfield = <unavailable>}"
165 gdb_test "print struct_b.struct_a.bitfield" " = <unavailable>"
169 gdb_test "print g_int" " = <unavailable>"
171 gdb_test "print g_ref" \
172 "\\(int &\\) @$hex: <unavailable>" \
173 "global reference shows address but not value"
175 gdb_test "print *&g_ref" \
176 "\\$\[0-9\]+ = <unavailable>$cr" \
177 "referenced integer was not collected (taking address of reference)"
179 gdb_test "print *g_structref_p" \
180 " = {d = <unavailable>, ref = <unavailable>}"
184 # Const string is always available, even when not collected.
185 gdb_test "print g_const_string" \
186 " = \"hello world\"$cr" \
187 "non collected const string is still printable"
189 gdb_test "print g_string_p" \
190 " = $hex \"hello world\"" \
191 "printing constant string through collected pointer"
193 gdb_test "print g_string_unavail" \
194 " = \{<unavailable> <repeats 12 times>\}" \
195 "printing non collected string"
197 # Incomplete strings print as an array.
198 gdb_test "print g_string_partial" \
199 "\\$\[0-9\]+ = \{<unavailable>, 101 'e', 108 'l', <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>, <unavailable>\}" \
200 "printing partially collected string"
202 # It is important for this test that the last examined value is
203 # <unavailable>, to exercise the case of the $__ convenience
204 # variable being set to <unavailable> without error.
205 set msg "examining partially collected object"
206 gdb_test_multiple "x /10x &struct_b" "$msg" {
207 -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 $" {
210 -re "value is not available" {
215 gdb_test "p \$__" " = <unavailable>" "last examined value was <unavailable>"
217 gdb_test "tfind none" \
219 "cease trace debugging"
221 set pf_prefix $old_pf_prefix
224 proc gdb_trace_collection_test {} {
225 gdb_collect_globals_test
228 clean_restart $executable
231 # We generously give ourselves one "pass" if we successfully
232 # detect that this test cannot be run on this target!
233 if { ![gdb_target_supports_trace] } then {
234 pass "Current target does not support trace"
238 # Body of test encased in a proc so we can return prematurely.
239 gdb_trace_collection_test
242 gdb_test "tfind none" ".*" ""