1 # Copyright 1998, 1999, 2000, 2007, 2008 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file is part of the gdb testsuite
18 # file written by Elena Zannoni (ezannoni@cygnus.com)
21 # tests for expressions with struct/array elements and mixed operator types
22 # with elementary types
29 # By default, the datastructures are allocated on the stack. For targets
30 # with very small stack, that will not work. In that case, just set
31 # storage to `-DSTORAGE=static' which changes the datastructures to be
32 # allocated in data segment.
33 set storage "-DSTORAGE="
34 if [target_info exists gdb,small_stack_section] {
35 set storage "-DSTORAGE=static"
38 set additional_flags "additional_flags=${storage}"
41 # test running programs
46 set testfile "miscexprs"
47 set srcfile ${testfile}.c
48 set binfile ${objdir}/${subdir}/${testfile}
50 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
51 untested miscexprs.exp
55 if [get_compiler_info ${binfile}] {
61 gdb_reinitialize_dir $srcdir/$subdir
66 # set it up at a breakpoint so we can play with the variable values
68 if ![runto_main] then {
69 perror "couldn't run to breakpoint"
73 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
77 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
80 -re ".*main.*$gdb_prompt $" {
81 pass "up from marker1"
83 -re ".*$gdb_prompt $" {
84 fail "up from marker1"
86 timeout { fail "up from marker1 (timeout)" }
89 -re "$gdb_prompt $" { fail "continue to marker1" }
90 timeout { fail "(timeout) continue to marker1" }
95 send_gdb "print &ibig.i\[0\]\n"
97 -re ".\[0-9\]* = \\(int \\*\\) $hex.*$gdb_prompt $" {
98 pass "print value of &ibig.i\[0\]"
100 -re ".*$gdb_prompt $" { fail "print value of &ibig.i\[0\]" }
101 timeout { fail "(timeout) print value of &ibig.i\[0\]" }
104 send_gdb "print &cbig.c\[0\]\n"
106 -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
107 pass "print value of &cbig.c\[0\]"
109 -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
110 pass "print value of &cbig.c\[0\]"
112 -re ".*$gdb_prompt $" { fail "print value of &cbig.c\[0\]" }
113 timeout { fail "(timeout) print value of &cbig.c\[0\]" }
116 send_gdb "print &fbig.f\[0\]\n"
118 -re ".\[0-9\]* = \\(float \\*\\) $hex.*$gdb_prompt $" {
119 pass "print value of &fbig.f\[0\]"
121 -re ".*$gdb_prompt $" { fail "print value of &fbig.f\[0\]" }
122 timeout { fail "(timeout) print value of &fbig.f\[0\]" }
125 send_gdb "print &dbig.d\[0\]\n"
127 -re ".\[0-9\]* = \\(double \\*\\) $hex.*$gdb_prompt $" {
128 pass "print value of &dbig.d\[0\]"
130 -re ".*$gdb_prompt $" { fail "print value of &dbig.d\[0\]" }
131 timeout { fail "(timeout) print value of &dbig.d\[0\]" }
134 send_gdb "print &sbig.s\[0\]\n"
136 -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
137 pass "print value of &sbig.s\[0\]"
139 -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
140 pass "print value of &sbig.s\[0\]"
142 -re ".*$gdb_prompt $" { fail "print value of &sbig.s\[0\]" }
143 timeout { fail "(timeout) print value of &sbig.s\[0\]" }
146 send_gdb "print &lbig.l\[0\]\n"
148 -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
149 pass "print value of &lbig.l\[0\]"
151 -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
152 pass "print value of &lbig.l\[0\]"
154 -re ".*$gdb_prompt $" { fail "print value of &lbig.l\[0\]" }
155 timeout { fail "(timeout) print value of &lbig.l\[0\]" }
159 send_gdb "print ibig.i\[100\] | 1\n"
161 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
162 pass "print value of ibig.i\[100\] | 1"
164 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] | 1" }
165 timeout { fail "(timeout) print value of ibig.i\[100\] | 1" }
169 send_gdb "print sbig.s\[90\] & 127\n"
171 -re ".\[0-9\]* = 127.*$gdb_prompt $" {
172 pass "print value of sbig.s\[90\] & 127"
174 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] & 127" }
175 timeout { fail "(timeout) print value of sbig.s\[90\] & 127" }
178 send_gdb "print !ibig.i\[100\]\n"
180 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
181 pass "print value of !ibig.i\[100\]"
183 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
184 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
187 send_gdb "print !sbig.s\[90\]\n"
189 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
190 pass "print value of !sbig.s\[90\]"
192 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\]" }
193 timeout { fail "(timeout) print value of !sbig.s\[90\]" }
197 send_gdb "print !fbig.f\[100\]\n"
199 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
200 pass "print value of !ibig.i\[100\]"
202 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
203 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
206 send_gdb "print !dbig.d\[202\]\n"
208 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
209 pass "print value of !ibig.i\[100\]"
211 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
212 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
217 send_gdb "print sbig.s\[90\] * 10\n"
219 -re ".\[0-9\]* = 2550.*$gdb_prompt $" {
220 pass "print value of !sbig.s\[90\] * 10"
222 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\] * 10" }
223 timeout { fail "(timeout) print value of !sbig.s\[90\] * 10" }
226 send_gdb "print ibig.i\[100\] * sbig.s\[90\]\n"
228 -re ".\[0-9\]* = 1275.*$gdb_prompt $" {
229 pass "print value of ibig.i\[100\] * sbig.s\[90\]"
231 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] * sbig.s\[90\]" }
232 timeout { fail "(timeout) print value of ibig.i\[100\] * sbig.s\[90\]" }
235 send_gdb "print fbig.f\[100\] * dbig.d\[202\]\n"
237 -re ".\[0-9\]* = 119.99\[0-9\]*.*$gdb_prompt $" {
238 pass "print value of fbig.f\[100\] * dbig.d\[202\]"
240 -re ".*$gdb_prompt $" { fail "print value of fbig.f\[100\] * dbig.d\[202\]" }
241 timeout { fail "(timeout) print value of fbig.f\[100\] * dbig.d\[202\]" }
244 send_gdb "print !(sbig.s\[90\] * 2)\n"
246 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
247 pass "print value of !(sbig.s\[90\] * 2)"
249 -re ".*$gdb_prompt $" { fail "print value of !(sbig.s\[90\] * 2)" }
250 timeout { fail "(timeout) print value of !(sbig.s\[90\] * 2)" }
254 send_gdb "print sizeof(sbig)\n"
256 -re ".\[0-9\]* = 800.*$gdb_prompt $" {
257 pass "print value of sizeof(sbig)"
259 -re ".*$gdb_prompt $" { fail "print value of sizeof(sbig)" }
260 timeout { fail "(timeout) print value of sizeof(sbig)" }
264 send_gdb "print sizeof(cbig)\n"
266 -re ".\[0-9\]* = 100.*$gdb_prompt $" {
267 pass "print value of sizeof(cbig)"
269 -re ".*$gdb_prompt $" { fail "print value of sizeof(cbig)" }
270 timeout { fail "(timeout) print value of sizeof(cbig)" }
274 send_gdb "print sizeof(lbig)/sizeof(long)\n"
276 -re ".\[0-9\]* = 900.*$gdb_prompt $" {
277 pass "print value of sizeof(lbig)/sizeof(long)"
279 -re ".*$gdb_prompt $" { fail "print value of sizeof(lbig)/sizeof(long)" }
280 timeout { fail "(timeout) print value of sizeof(lbig)/sizeof(long)" }
283 send_gdb "print ibig.i\[100\] << 2\n"
285 -re ".\[0-9\]* = 20.*$gdb_prompt $" {
286 pass "print value of ibig.i\[100\] << 2"
288 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] << 2" }
289 timeout { fail "(timeout) print value of ibig.i\[100\] << 2" }
292 send_gdb "print sbig.s\[90\] >> 4\n"
294 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
295 pass "print value of sbig.s\[90\] >> 4"
297 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] >> 4" }
298 timeout { fail "(timeout) print value of sbig.s\[90\] >> 4" }
301 send_gdb "print lbig.l\[333\] >> 6\n"
303 -re ".\[0-9\]* = 15624999.*$gdb_prompt $" {
304 pass "print value of lbig.l\[333\] >> 6"
306 -re ".*$gdb_prompt $" { fail "print value of lbig.l\[333\] >> 6" }
307 timeout { fail "(timeout) print value of lbig.l\[333\] >> 6" }