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/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
20 # This file is part of the gdb testsuite
21 # file written by Elena Zannoni (ezannoni@cygnus.com)
24 # tests for expressions with struct/array elements and mixed operator types
25 # with elementary types
32 # By default, the datastructures are allocated on the stack. For targets
33 # with very small stack, that will not work. In that case, just set
34 # storage to `-DSTORAGE=static' which changes the datastructures to be
35 # allocated in data segment.
36 set storage "-DSTORAGE="
37 if [target_info exists gdb,small_stack_section] {
38 set storage "-DSTORAGE=static"
41 set additional_flags "additional_flags=${storage}"
44 # test running programs
49 set testfile "miscexprs"
50 set srcfile ${testfile}.c
51 set binfile ${objdir}/${subdir}/${testfile}
53 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
54 untested miscexprs.exp
58 if [get_compiler_info ${binfile}] {
64 gdb_reinitialize_dir $srcdir/$subdir
69 # set it up at a breakpoint so we can play with the variable values
71 if ![runto_main] then {
72 perror "couldn't run to breakpoint"
76 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
80 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
83 -re ".*main.*$gdb_prompt $" {
84 pass "up from marker1"
86 -re ".*$gdb_prompt $" {
87 fail "up from marker1"
89 timeout { fail "up from marker1 (timeout)" }
92 -re "$gdb_prompt $" { fail "continue to marker1" }
93 timeout { fail "(timeout) continue to marker1" }
98 send_gdb "print &ibig.i\[0\]\n"
100 -re ".\[0-9\]* = \\(int \\*\\) $hex.*$gdb_prompt $" {
101 pass "print value of &ibig.i\[0\]"
103 -re ".*$gdb_prompt $" { fail "print value of &ibig.i\[0\]" }
104 timeout { fail "(timeout) print value of &ibig.i\[0\]" }
107 send_gdb "print &cbig.c\[0\]\n"
109 -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
110 pass "print value of &cbig.c\[0\]"
112 -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
113 pass "print value of &cbig.c\[0\]"
115 -re ".*$gdb_prompt $" { fail "print value of &cbig.c\[0\]" }
116 timeout { fail "(timeout) print value of &cbig.c\[0\]" }
119 send_gdb "print &fbig.f\[0\]\n"
121 -re ".\[0-9\]* = \\(float \\*\\) $hex.*$gdb_prompt $" {
122 pass "print value of &fbig.f\[0\]"
124 -re ".*$gdb_prompt $" { fail "print value of &fbig.f\[0\]" }
125 timeout { fail "(timeout) print value of &fbig.f\[0\]" }
128 send_gdb "print &dbig.d\[0\]\n"
130 -re ".\[0-9\]* = \\(double \\*\\) $hex.*$gdb_prompt $" {
131 pass "print value of &dbig.d\[0\]"
133 -re ".*$gdb_prompt $" { fail "print value of &dbig.d\[0\]" }
134 timeout { fail "(timeout) print value of &dbig.d\[0\]" }
137 send_gdb "print &sbig.s\[0\]\n"
139 -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
140 pass "print value of &sbig.s\[0\]"
142 -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
143 pass "print value of &sbig.s\[0\]"
145 -re ".*$gdb_prompt $" { fail "print value of &sbig.s\[0\]" }
146 timeout { fail "(timeout) print value of &sbig.s\[0\]" }
149 send_gdb "print &lbig.l\[0\]\n"
151 -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
152 pass "print value of &lbig.l\[0\]"
154 -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
155 pass "print value of &lbig.l\[0\]"
157 -re ".*$gdb_prompt $" { fail "print value of &lbig.l\[0\]" }
158 timeout { fail "(timeout) print value of &lbig.l\[0\]" }
162 send_gdb "print ibig.i\[100\] | 1\n"
164 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
165 pass "print value of ibig.i\[100\] | 1"
167 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] | 1" }
168 timeout { fail "(timeout) print value of ibig.i\[100\] | 1" }
172 send_gdb "print sbig.s\[90\] & 127\n"
174 -re ".\[0-9\]* = 127.*$gdb_prompt $" {
175 pass "print value of sbig.s\[90\] & 127"
177 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] & 127" }
178 timeout { fail "(timeout) print value of sbig.s\[90\] & 127" }
181 send_gdb "print !ibig.i\[100\]\n"
183 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
184 pass "print value of !ibig.i\[100\]"
186 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
187 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
190 send_gdb "print !sbig.s\[90\]\n"
192 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
193 pass "print value of !sbig.s\[90\]"
195 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\]" }
196 timeout { fail "(timeout) print value of !sbig.s\[90\]" }
200 send_gdb "print !fbig.f\[100\]\n"
202 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
203 pass "print value of !ibig.i\[100\]"
205 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
206 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
209 send_gdb "print !dbig.d\[202\]\n"
211 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
212 pass "print value of !ibig.i\[100\]"
214 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
215 timeout { fail "(timeout) print value of !ibig.i\[100\]" }
220 send_gdb "print sbig.s\[90\] * 10\n"
222 -re ".\[0-9\]* = 2550.*$gdb_prompt $" {
223 pass "print value of !sbig.s\[90\] * 10"
225 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\] * 10" }
226 timeout { fail "(timeout) print value of !sbig.s\[90\] * 10" }
229 send_gdb "print ibig.i\[100\] * sbig.s\[90\]\n"
231 -re ".\[0-9\]* = 1275.*$gdb_prompt $" {
232 pass "print value of ibig.i\[100\] * sbig.s\[90\]"
234 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] * sbig.s\[90\]" }
235 timeout { fail "(timeout) print value of ibig.i\[100\] * sbig.s\[90\]" }
238 send_gdb "print fbig.f\[100\] * dbig.d\[202\]\n"
240 -re ".\[0-9\]* = 119.99\[0-9\]*.*$gdb_prompt $" {
241 pass "print value of fbig.f\[100\] * dbig.d\[202\]"
243 -re ".*$gdb_prompt $" { fail "print value of fbig.f\[100\] * dbig.d\[202\]" }
244 timeout { fail "(timeout) print value of fbig.f\[100\] * dbig.d\[202\]" }
247 send_gdb "print !(sbig.s\[90\] * 2)\n"
249 -re ".\[0-9\]* = $false.*$gdb_prompt $" {
250 pass "print value of !(sbig.s\[90\] * 2)"
252 -re ".*$gdb_prompt $" { fail "print value of !(sbig.s\[90\] * 2)" }
253 timeout { fail "(timeout) print value of !(sbig.s\[90\] * 2)" }
257 send_gdb "print sizeof(sbig)\n"
259 -re ".\[0-9\]* = 800.*$gdb_prompt $" {
260 pass "print value of sizeof(sbig)"
262 -re ".*$gdb_prompt $" { fail "print value of sizeof(sbig)" }
263 timeout { fail "(timeout) print value of sizeof(sbig)" }
267 send_gdb "print sizeof(cbig)\n"
269 -re ".\[0-9\]* = 100.*$gdb_prompt $" {
270 pass "print value of sizeof(cbig)"
272 -re ".*$gdb_prompt $" { fail "print value of sizeof(cbig)" }
273 timeout { fail "(timeout) print value of sizeof(cbig)" }
277 send_gdb "print sizeof(lbig)/sizeof(long)\n"
279 -re ".\[0-9\]* = 900.*$gdb_prompt $" {
280 pass "print value of sizeof(lbig)/sizeof(long)"
282 -re ".*$gdb_prompt $" { fail "print value of sizeof(lbig)/sizeof(long)" }
283 timeout { fail "(timeout) print value of sizeof(lbig)/sizeof(long)" }
286 send_gdb "print ibig.i\[100\] << 2\n"
288 -re ".\[0-9\]* = 20.*$gdb_prompt $" {
289 pass "print value of ibig.i\[100\] << 2"
291 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] << 2" }
292 timeout { fail "(timeout) print value of ibig.i\[100\] << 2" }
295 send_gdb "print sbig.s\[90\] >> 4\n"
297 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
298 pass "print value of sbig.s\[90\] >> 4"
300 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] >> 4" }
301 timeout { fail "(timeout) print value of sbig.s\[90\] >> 4" }
304 send_gdb "print lbig.l\[333\] >> 6\n"
306 -re ".\[0-9\]* = 15624999.*$gdb_prompt $" {
307 pass "print value of lbig.l\[333\] >> 6"
309 -re ".*$gdb_prompt $" { fail "print value of lbig.l\[333\] >> 6" }
310 timeout { fail "(timeout) print value of lbig.l\[333\] >> 6" }