1 # Copyright 1998, 1999, 2000, 2007, 2008, 2009, 2010
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/>.
18 # This file is part of the gdb testsuite
19 # file written by Elena Zannoni (ezannoni@cygnus.com)
22 # tests for expressions with struct/array elements and mixed operator types
23 # with elementary types
30 # By default, the datastructures are allocated on the stack. For targets
31 # with very small stack, that will not work. In that case, just set
32 # storage to `-DSTORAGE=static' which changes the datastructures to be
33 # allocated in data segment.
34 set storage "-DSTORAGE="
35 if [target_info exists gdb,small_stack_section] {
36 set storage "-DSTORAGE=static"
39 set additional_flags "additional_flags=${storage}"
42 # test running programs
47 set testfile "miscexprs"
48 set srcfile ${testfile}.c
49 set binfile ${objdir}/${subdir}/${testfile}
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
52 untested miscexprs.exp
56 if [get_compiler_info ${binfile}] {
62 gdb_reinitialize_dir $srcdir/$subdir
67 # set it up at a breakpoint so we can play with the variable values
69 if ![runto_main] then {
70 perror "couldn't run to breakpoint"
74 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
78 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
81 -re ".*main.*$gdb_prompt $" {
82 pass "up from marker1"
84 -re ".*$gdb_prompt $" {
85 fail "up from marker1"
87 timeout { fail "up from marker1 (timeout)" }
90 -re "$gdb_prompt $" { fail "continue to marker1" }
91 timeout { fail "(timeout) continue to marker1" }
96 send_gdb "print &ibig.i\[0\]\n"
98 -re ".\[0-9\]* = \\(int \\*\\) $hex.*$gdb_prompt $" {
99 pass "print value of &ibig.i\[0\]"
101 -re ".*$gdb_prompt $" { fail "print value of &ibig.i\[0\]" }
102 timeout { fail "(timeout) print value of &ibig.i\[0\]" }
105 send_gdb "print &cbig.c\[0\]\n"
107 -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
108 pass "print value of &cbig.c\[0\]"
110 -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
111 pass "print value of &cbig.c\[0\]"
113 -re ".*$gdb_prompt $" { fail "print value of &cbig.c\[0\]" }
114 timeout { fail "(timeout) print value of &cbig.c\[0\]" }
117 send_gdb "print &fbig.f\[0\]\n"
119 -re ".\[0-9\]* = \\(float \\*\\) $hex.*$gdb_prompt $" {
120 pass "print value of &fbig.f\[0\]"
122 -re ".*$gdb_prompt $" { fail "print value of &fbig.f\[0\]" }
123 timeout { fail "(timeout) print value of &fbig.f\[0\]" }
126 send_gdb "print &dbig.d\[0\]\n"
128 -re ".\[0-9\]* = \\(double \\*\\) $hex.*$gdb_prompt $" {
129 pass "print value of &dbig.d\[0\]"
131 -re ".*$gdb_prompt $" { fail "print value of &dbig.d\[0\]" }
132 timeout { fail "(timeout) print value of &dbig.d\[0\]" }
135 send_gdb "print &sbig.s\[0\]\n"
137 -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
138 pass "print value of &sbig.s\[0\]"
140 -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
141 pass "print value of &sbig.s\[0\]"
143 -re ".*$gdb_prompt $" { fail "print value of &sbig.s\[0\]" }
144 timeout { fail "(timeout) print value of &sbig.s\[0\]" }
147 send_gdb "print &lbig.l\[0\]\n"
149 -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
150 pass "print value of &lbig.l\[0\]"
152 -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
153 pass "print value of &lbig.l\[0\]"
155 -re ".*$gdb_prompt $" { fail "print value of &lbig.l\[0\]" }
156 timeout { fail "(timeout) print value of &lbig.l\[0\]" }
160 send_gdb "print ibig.i\[100\] | 1\n"
162 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
163 pass "print value of ibig.i\[100\] | 1"
165 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] | 1" }
166 timeout { fail "(timeout) print value of ibig.i\[100\] | 1" }
170 send_gdb "print sbig.s\[90\] & 127\n"
172 -re ".\[0-9\]* = 127.*$gdb_prompt $" {
173 pass "print value of sbig.s\[90\] & 127"
175 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] & 127" }
176 timeout { fail "(timeout) print value of sbig.s\[90\] & 127" }
179 send_gdb "print !ibig.i\[100\]\n"
181 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
182 pass "print value of !ibig.i\[100\]"
184 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
185 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
188 send_gdb "print !sbig.s\[90\]\n"
190 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
191 pass "print value of !sbig.s\[90\]"
193 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\]" }
194 timeout { fail "(timeout) print value of !sbig.s\[90\]" }
198 send_gdb "print !fbig.f\[100\]\n"
200 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
201 pass "print value of !ibig.i\[100\]"
203 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
204 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
207 send_gdb "print !dbig.d\[202\]\n"
209 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
210 pass "print value of !ibig.i\[100\]"
212 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
213 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
218 send_gdb "print sbig.s\[90\] * 10\n"
220 -re ".\[0-9\]* = 2550.*$gdb_prompt $" {
221 pass "print value of !sbig.s\[90\] * 10"
223 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\] * 10" }
224 timeout { fail "(timeout) print value of !sbig.s\[90\] * 10" }
227 send_gdb "print ibig.i\[100\] * sbig.s\[90\]\n"
229 -re ".\[0-9\]* = 1275.*$gdb_prompt $" {
230 pass "print value of ibig.i\[100\] * sbig.s\[90\]"
232 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] * sbig.s\[90\]" }
233 timeout { fail "(timeout) print value of ibig.i\[100\] * sbig.s\[90\]" }
236 send_gdb "print fbig.f\[100\] * dbig.d\[202\]\n"
238 -re ".\[0-9\]* = 119.99\[0-9\]*.*$gdb_prompt $" {
239 pass "print value of fbig.f\[100\] * dbig.d\[202\]"
241 -re ".*$gdb_prompt $" { fail "print value of fbig.f\[100\] * dbig.d\[202\]" }
242 timeout { fail "(timeout) print value of fbig.f\[100\] * dbig.d\[202\]" }
245 send_gdb "print !(sbig.s\[90\] * 2)\n"
247 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
248 pass "print value of !(sbig.s\[90\] * 2)"
250 -re ".*$gdb_prompt $" { fail "print value of !(sbig.s\[90\] * 2)" }
251 timeout { fail "(timeout) print value of !(sbig.s\[90\] * 2)" }
255 send_gdb "print sizeof(sbig)\n"
257 -re ".\[0-9\]* = 800.*$gdb_prompt $" {
258 pass "print value of sizeof(sbig)"
260 -re ".*$gdb_prompt $" { fail "print value of sizeof(sbig)" }
261 timeout { fail "(timeout) print value of sizeof(sbig)" }
265 send_gdb "print sizeof(cbig)\n"
267 -re ".\[0-9\]* = 100.*$gdb_prompt $" {
268 pass "print value of sizeof(cbig)"
270 -re ".*$gdb_prompt $" { fail "print value of sizeof(cbig)" }
271 timeout { fail "(timeout) print value of sizeof(cbig)" }
275 send_gdb "print sizeof(lbig)/sizeof(long)\n"
277 -re ".\[0-9\]* = 900.*$gdb_prompt $" {
278 pass "print value of sizeof(lbig)/sizeof(long)"
280 -re ".*$gdb_prompt $" { fail "print value of sizeof(lbig)/sizeof(long)" }
281 timeout { fail "(timeout) print value of sizeof(lbig)/sizeof(long)" }
284 send_gdb "print ibig.i\[100\] << 2\n"
286 -re ".\[0-9\]* = 20.*$gdb_prompt $" {
287 pass "print value of ibig.i\[100\] << 2"
289 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] << 2" }
290 timeout { fail "(timeout) print value of ibig.i\[100\] << 2" }
293 send_gdb "print sbig.s\[90\] >> 4\n"
295 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
296 pass "print value of sbig.s\[90\] >> 4"
298 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] >> 4" }
299 timeout { fail "(timeout) print value of sbig.s\[90\] >> 4" }
302 send_gdb "print lbig.l\[333\] >> 6\n"
304 -re ".\[0-9\]* = 15624999.*$gdb_prompt $" {
305 pass "print value of lbig.l\[333\] >> 6"
307 -re ".*$gdb_prompt $" { fail "print value of lbig.l\[333\] >> 6" }
308 timeout { fail "(timeout) print value of lbig.l\[333\] >> 6" }