Update copyright year in most headers.
[external/binutils.git] / gdb / testsuite / gdb.base / miscexprs.exp
1 # Copyright 1998, 1999, 2000, 2007, 2008, 2009, 2010
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
18 # This file is part of the gdb testsuite
19 # file written by Elena Zannoni (ezannoni@cygnus.com)
20
21 #
22 # tests for expressions with struct/array elements and mixed operator types
23 # with elementary types
24
25
26 if $tracelevel then {
27         strace $tracelevel
28         }
29
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"
37 }
38
39 set additional_flags "additional_flags=${storage}"
40
41 #
42 # test running programs
43 #
44 set prms_id 0
45 set bug_id 0
46
47 set testfile "miscexprs"
48 set srcfile ${testfile}.c
49 set binfile ${objdir}/${subdir}/${testfile}
50
51 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
52     untested miscexprs.exp
53     return -1
54 }
55
56 if [get_compiler_info ${binfile}] {
57     return -1;
58 }
59
60 gdb_exit
61 gdb_start
62 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_load ${binfile}
64
65
66 #
67 # set it up at a breakpoint so we can play with the variable values
68 #
69 if ![runto_main] then {
70     perror "couldn't run to breakpoint"
71     continue
72 }
73
74 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
75
76     send_gdb "cont\n"
77     gdb_expect {
78         -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
79             send_gdb "up\n"
80             gdb_expect {
81                 -re ".*main.*$gdb_prompt $" {
82                     pass "up from marker1"
83                 }
84                 -re ".*$gdb_prompt $" {
85                     fail "up from marker1"
86                 }
87                 timeout { fail "up from marker1 (timeout)" }
88             }
89         }
90         -re "$gdb_prompt $" { fail "continue to marker1"  }
91         timeout { fail "(timeout) continue to marker1"  }
92     }
93
94 global hex
95
96 send_gdb "print &ibig.i\[0\]\n"
97 gdb_expect {
98     -re ".\[0-9\]* = \\(int \\*\\) $hex.*$gdb_prompt $" {
99         pass "print value of &ibig.i\[0\]"
100       }
101     -re ".*$gdb_prompt $" { fail "print value of &ibig.i\[0\]" }
102     timeout           { fail "(timeout) print value of &ibig.i\[0\]" }
103   }
104
105 send_gdb "print &cbig.c\[0\]\n"
106 gdb_expect {
107     -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
108         pass "print value of &cbig.c\[0\]"
109       }
110     -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
111         pass "print value of &cbig.c\[0\]"
112       }
113     -re ".*$gdb_prompt $" { fail "print value of &cbig.c\[0\]" }
114     timeout           { fail "(timeout) print value of &cbig.c\[0\]" }
115   }
116
117 send_gdb "print &fbig.f\[0\]\n"
118 gdb_expect {
119     -re ".\[0-9\]* = \\(float \\*\\) $hex.*$gdb_prompt $" {
120         pass "print value of &fbig.f\[0\]"
121       }
122     -re ".*$gdb_prompt $" { fail "print value of &fbig.f\[0\]" }
123     timeout           { fail "(timeout) print value of &fbig.f\[0\]" }
124   }
125
126 send_gdb "print &dbig.d\[0\]\n"
127 gdb_expect {
128     -re ".\[0-9\]* = \\(double \\*\\) $hex.*$gdb_prompt $" {
129         pass "print value of &dbig.d\[0\]"
130       }
131     -re ".*$gdb_prompt $" { fail "print value of &dbig.d\[0\]" }
132     timeout           { fail "(timeout) print value of &dbig.d\[0\]" }
133   }
134
135 send_gdb "print &sbig.s\[0\]\n"
136 gdb_expect {
137     -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
138         pass "print value of &sbig.s\[0\]"
139     }
140     -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
141         pass "print value of &sbig.s\[0\]"
142     }
143     -re ".*$gdb_prompt $" { fail "print value of &sbig.s\[0\]" }
144     timeout           { fail "(timeout) print value of &sbig.s\[0\]" }
145   }
146
147 send_gdb "print &lbig.l\[0\]\n"
148 gdb_expect {
149     -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
150         pass "print value of &lbig.l\[0\]"
151     }
152     -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
153         pass "print value of &lbig.l\[0\]"
154     }
155     -re ".*$gdb_prompt $" { fail "print value of &lbig.l\[0\]" }
156     timeout           { fail "(timeout) print value of &lbig.l\[0\]" }
157   }
158
159
160 send_gdb "print ibig.i\[100\] | 1\n"
161 gdb_expect {
162     -re ".\[0-9\]* = 5.*$gdb_prompt $" {
163         pass "print value of ibig.i\[100\] | 1"
164       }
165     -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] | 1" }
166     timeout           { fail "(timeout) print value of ibig.i\[100\] | 1" }
167   }
168
169
170 send_gdb "print sbig.s\[90\] & 127\n"
171 gdb_expect {
172     -re ".\[0-9\]* = 127.*$gdb_prompt $" {
173         pass "print value of sbig.s\[90\] & 127"
174       }
175     -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] & 127" }
176     timeout           { fail "(timeout) print value of sbig.s\[90\] & 127" }
177   }
178
179 send_gdb "print !ibig.i\[100\]\n"
180 gdb_expect {
181     -re ".\[0-9\]* = $false.*$gdb_prompt $" {
182         pass "print value of !ibig.i\[100\]"
183       }
184     -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
185     timeout           { fail "(timeout) print value of !ibig.i\[100\]" }
186   }
187
188 send_gdb "print !sbig.s\[90\]\n"
189 gdb_expect {
190     -re ".\[0-9\]* = $false.*$gdb_prompt $" {
191         pass "print value of !sbig.s\[90\]"
192       }
193     -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\]" }
194     timeout           { fail "(timeout) print value of !sbig.s\[90\]" }
195   }
196
197
198 send_gdb "print !fbig.f\[100\]\n"
199 gdb_expect {
200     -re ".\[0-9\]* = $false.*$gdb_prompt $" {
201         pass "print value of !ibig.i\[100\]"
202       }
203     -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
204     timeout           { fail "(timeout) print value of !ibig.i\[100\]" }
205   }
206
207 send_gdb "print !dbig.d\[202\]\n"
208 gdb_expect {
209     -re ".\[0-9\]* = $false.*$gdb_prompt $" {
210         pass "print value of !ibig.i\[100\]"
211       }
212     -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" }
213     timeout           { fail "(timeout) print value of !ibig.i\[100\]" }
214   }
215
216
217
218 send_gdb "print sbig.s\[90\] * 10\n"
219 gdb_expect {
220     -re ".\[0-9\]* = 2550.*$gdb_prompt $" {
221         pass "print value of !sbig.s\[90\] * 10"
222       }
223     -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\] * 10" }
224     timeout           { fail "(timeout) print value of !sbig.s\[90\] * 10" }
225   }
226
227 send_gdb "print ibig.i\[100\] * sbig.s\[90\]\n"
228 gdb_expect {
229     -re ".\[0-9\]* = 1275.*$gdb_prompt $" {
230         pass "print value of ibig.i\[100\] * sbig.s\[90\]"
231       }
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\]" }
234   }
235
236 send_gdb "print fbig.f\[100\] * dbig.d\[202\]\n"
237 gdb_expect {
238     -re ".\[0-9\]* = 119.99\[0-9\]*.*$gdb_prompt $" {
239         pass "print value of fbig.f\[100\] * dbig.d\[202\]"
240       }
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\]" }
243   }
244
245 send_gdb "print !(sbig.s\[90\] * 2)\n"
246 gdb_expect {
247     -re ".\[0-9\]* = $false.*$gdb_prompt $" {
248         pass "print value of !(sbig.s\[90\] * 2)"
249       }
250     -re ".*$gdb_prompt $" { fail "print value of !(sbig.s\[90\] * 2)" }
251     timeout           { fail "(timeout) print value of !(sbig.s\[90\] * 2)" }
252   }
253
254
255 send_gdb "print sizeof(sbig)\n"
256 gdb_expect {
257     -re ".\[0-9\]* = 800.*$gdb_prompt $" {
258         pass "print value of sizeof(sbig)"
259       }
260     -re ".*$gdb_prompt $" { fail "print value of sizeof(sbig)" }
261     timeout           { fail "(timeout) print value of sizeof(sbig)" }
262   }
263
264
265 send_gdb "print sizeof(cbig)\n"
266 gdb_expect {
267     -re ".\[0-9\]* = 100.*$gdb_prompt $" {
268         pass "print value of sizeof(cbig)"
269       }
270     -re ".*$gdb_prompt $" { fail "print value of sizeof(cbig)" }
271     timeout           { fail "(timeout) print value of sizeof(cbig)" }
272   }
273
274
275 send_gdb "print sizeof(lbig)/sizeof(long)\n"
276 gdb_expect {
277     -re ".\[0-9\]* = 900.*$gdb_prompt $" {
278         pass "print value of sizeof(lbig)/sizeof(long)"
279       }
280     -re ".*$gdb_prompt $" { fail "print value of sizeof(lbig)/sizeof(long)" }
281     timeout     { fail "(timeout) print value of sizeof(lbig)/sizeof(long)" }
282   }
283
284 send_gdb "print ibig.i\[100\] << 2\n"
285 gdb_expect {
286     -re ".\[0-9\]* = 20.*$gdb_prompt $" {
287         pass "print value of ibig.i\[100\] << 2"
288       }
289     -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] << 2" }
290     timeout           { fail "(timeout) print value of ibig.i\[100\] << 2" }
291   }
292
293 send_gdb "print sbig.s\[90\] >> 4\n"
294 gdb_expect {
295     -re ".\[0-9\]* = 15.*$gdb_prompt $" {
296         pass "print value of sbig.s\[90\] >> 4"
297       }
298     -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] >> 4" }
299     timeout           { fail "(timeout) print value of sbig.s\[90\] >> 4" }
300   }
301
302 send_gdb "print lbig.l\[333\] >> 6\n"
303 gdb_expect {
304     -re ".\[0-9\]* = 15624999.*$gdb_prompt $" {
305         pass "print value of lbig.l\[333\] >> 6"
306       }
307     -re ".*$gdb_prompt $" { fail "print value of lbig.l\[333\] >> 6" }
308     timeout           { fail "(timeout) print value of lbig.l\[333\] >> 6" }
309   }