1# Copyright 1998, 1999, 2000 Free Software Foundation, Inc. 2 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 2 of the License, or 6# (at your option) any later version. 7# 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. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# Please email any bugs, comments, and/or additions to this file to: 18# bug-gdb@prep.ai.mit.edu 19 20 21# This file is part of the gdb testsuite 22# file written by Elena Zannoni (ezannoni@cygnus.com) 23 24# 25# tests for expressions with struct/array elements and mixed operator types 26# with elementary types 27# 28 29if $tracelevel then { 30 strace $tracelevel 31 } 32 33# By default, the datastructures are allocated on the stack. For targets 34# with very small stack, that will not work. In that case, just set 35# storage to `-DSTORAGE=static' which changes the datastructures to be 36# allocated in data segment. 37set storage "-DSTORAGE=" 38if [target_info exists gdb,small_stack_section] { 39 set storage "-DSTORAGE=static" 40} 41 42set additional_flags "additional_flags=-w ${storage}" 43 44# 45# test running programs 46# 47set prms_id 0 48set bug_id 0 49 50set testfile "miscexprs" 51set srcfile ${testfile}.c 52set binfile ${objdir}/${subdir}/${testfile} 53 54if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags}]] != "" } { 55 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 56} 57 58if [get_compiler_info ${binfile}] { 59 return -1; 60} 61 62gdb_exit 63gdb_start 64gdb_reinitialize_dir $srcdir/$subdir 65gdb_load ${binfile} 66 67 68# 69# set it up at a breakpoint so we can play with the variable values 70# 71if ![runto_main] then { 72 perror "couldn't run to breakpoint" 73 continue 74} 75 76send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" 77 78 send_gdb "cont\n" 79 gdb_expect { 80 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" { 81 send_gdb "up\n" 82 gdb_expect { 83 -re ".*main.*$gdb_prompt $" { 84 pass "up from marker1" 85 } 86 -re ".*$gdb_prompt $" { 87 fail "up from marker1" 88 } 89 timeout { fail "up from marker1 (timeout)" } 90 } 91 } 92 -re "$gdb_prompt $" { fail "continue to marker1" } 93 timeout { fail "(timeout) continue to marker1" } 94 } 95 96global hex 97 98send_gdb "print &ibig.i\[0\]\n" 99gdb_expect { 100 -re ".\[0-9\]* = \\(int \\*\\) $hex.*$gdb_prompt $" { 101 pass "print value of &ibig.i\[0\]" 102 } 103 -re ".*$gdb_prompt $" { fail "print value of &ibig.i\[0\]" } 104 timeout { fail "(timeout) print value of &ibig.i\[0\]" } 105 } 106 107send_gdb "print &cbig.c\[0\]\n" 108gdb_expect { 109 -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" { 110 pass "print value of &cbig.c\[0\]" 111 } 112 -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" { 113 pass "print value of &cbig.c\[0\]" 114 } 115 -re ".*$gdb_prompt $" { fail "print value of &cbig.c\[0\]" } 116 timeout { fail "(timeout) print value of &cbig.c\[0\]" } 117 } 118 119send_gdb "print &fbig.f\[0\]\n" 120gdb_expect { 121 -re ".\[0-9\]* = \\(float \\*\\) $hex.*$gdb_prompt $" { 122 pass "print value of &fbig.f\[0\]" 123 } 124 -re ".*$gdb_prompt $" { fail "print value of &fbig.f\[0\]" } 125 timeout { fail "(timeout) print value of &fbig.f\[0\]" } 126 } 127 128send_gdb "print &dbig.d\[0\]\n" 129gdb_expect { 130 -re ".\[0-9\]* = \\(double \\*\\) $hex.*$gdb_prompt $" { 131 pass "print value of &dbig.d\[0\]" 132 } 133 -re ".*$gdb_prompt $" { fail "print value of &dbig.d\[0\]" } 134 timeout { fail "(timeout) print value of &dbig.d\[0\]" } 135 } 136 137send_gdb "print &sbig.s\[0\]\n" 138gdb_expect { 139 -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" { 140 pass "print value of &sbig.s\[0\]" 141 } 142 -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" { 143 pass "print value of &sbig.s\[0\]" 144 } 145 -re ".*$gdb_prompt $" { fail "print value of &sbig.s\[0\]" } 146 timeout { fail "(timeout) print value of &sbig.s\[0\]" } 147 } 148 149send_gdb "print &lbig.l\[0\]\n" 150gdb_expect { 151 -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" { 152 pass "print value of &lbig.l\[0\]" 153 } 154 -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" { 155 pass "print value of &lbig.l\[0\]" 156 } 157 -re ".*$gdb_prompt $" { fail "print value of &lbig.l\[0\]" } 158 timeout { fail "(timeout) print value of &lbig.l\[0\]" } 159 } 160 161 162send_gdb "print ibig.i\[100\] | 1\n" 163gdb_expect { 164 -re ".\[0-9\]* = 5.*$gdb_prompt $" { 165 pass "print value of ibig.i\[100\] | 1" 166 } 167 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] | 1" } 168 timeout { fail "(timeout) print value of ibig.i\[100\] | 1" } 169 } 170 171 172send_gdb "print sbig.s\[90\] & 127\n" 173gdb_expect { 174 -re ".\[0-9\]* = 127.*$gdb_prompt $" { 175 pass "print value of sbig.s\[90\] & 127" 176 } 177 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] & 127" } 178 timeout { fail "(timeout) print value of sbig.s\[90\] & 127" } 179 } 180 181send_gdb "print !ibig.i\[100\]\n" 182gdb_expect { 183 -re ".\[0-9\]* = $false.*$gdb_prompt $" { 184 pass "print value of !ibig.i\[100\]" 185 } 186 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" } 187 timeout { fail "(timeout) print value of !ibig.i\[100\]" } 188 } 189 190send_gdb "print !sbig.s\[90\]\n" 191gdb_expect { 192 -re ".\[0-9\]* = $false.*$gdb_prompt $" { 193 pass "print value of !sbig.s\[90\]" 194 } 195 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\]" } 196 timeout { fail "(timeout) print value of !sbig.s\[90\]" } 197 } 198 199 200send_gdb "print !fbig.f\[100\]\n" 201gdb_expect { 202 -re ".\[0-9\]* = $false.*$gdb_prompt $" { 203 pass "print value of !ibig.i\[100\]" 204 } 205 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" } 206 timeout { fail "(timeout) print value of !ibig.i\[100\]" } 207 } 208 209send_gdb "print !dbig.d\[202\]\n" 210gdb_expect { 211 -re ".\[0-9\]* = $false.*$gdb_prompt $" { 212 pass "print value of !ibig.i\[100\]" 213 } 214 -re ".*$gdb_prompt $" { fail "print value of !ibig.i\[100\]" } 215 timeout { fail "(timeout) print value of !ibig.i\[100\]" } 216 } 217 218 219 220send_gdb "print sbig.s\[90\] * 10\n" 221gdb_expect { 222 -re ".\[0-9\]* = 2550.*$gdb_prompt $" { 223 pass "print value of !sbig.s\[90\] * 10" 224 } 225 -re ".*$gdb_prompt $" { fail "print value of !sbig.s\[90\] * 10" } 226 timeout { fail "(timeout) print value of !sbig.s\[90\] * 10" } 227 } 228 229send_gdb "print ibig.i\[100\] * sbig.s\[90\]\n" 230gdb_expect { 231 -re ".\[0-9\]* = 1275.*$gdb_prompt $" { 232 pass "print value of ibig.i\[100\] * sbig.s\[90\]" 233 } 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\]" } 236 } 237 238send_gdb "print fbig.f\[100\] * dbig.d\[202\]\n" 239gdb_expect { 240 -re ".\[0-9\]* = 119.99\[0-9\]*.*$gdb_prompt $" { 241 pass "print value of fbig.f\[100\] * dbig.d\[202\]" 242 } 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\]" } 245 } 246 247send_gdb "print !(sbig.s\[90\] * 2)\n" 248gdb_expect { 249 -re ".\[0-9\]* = $false.*$gdb_prompt $" { 250 pass "print value of !(sbig.s\[90\] * 2)" 251 } 252 -re ".*$gdb_prompt $" { fail "print value of !(sbig.s\[90\] * 2)" } 253 timeout { fail "(timeout) print value of !(sbig.s\[90\] * 2)" } 254 } 255 256 257send_gdb "print sizeof(sbig)\n" 258gdb_expect { 259 -re ".\[0-9\]* = 800.*$gdb_prompt $" { 260 pass "print value of sizeof(sbig)" 261 } 262 -re ".*$gdb_prompt $" { fail "print value of sizeof(sbig)" } 263 timeout { fail "(timeout) print value of sizeof(sbig)" } 264 } 265 266 267send_gdb "print sizeof(cbig)\n" 268gdb_expect { 269 -re ".\[0-9\]* = 100.*$gdb_prompt $" { 270 pass "print value of sizeof(cbig)" 271 } 272 -re ".*$gdb_prompt $" { fail "print value of sizeof(cbig)" } 273 timeout { fail "(timeout) print value of sizeof(cbig)" } 274 } 275 276 277send_gdb "print sizeof(lbig)/sizeof(long)\n" 278gdb_expect { 279 -re ".\[0-9\]* = 900.*$gdb_prompt $" { 280 pass "print value of sizeof(lbig)/sizeof(long)" 281 } 282 -re ".*$gdb_prompt $" { fail "print value of sizeof(lbig)/sizeof(long)" } 283 timeout { fail "(timeout) print value of sizeof(lbig)/sizeof(long)" } 284 } 285 286send_gdb "print ibig.i\[100\] << 2\n" 287gdb_expect { 288 -re ".\[0-9\]* = 20.*$gdb_prompt $" { 289 pass "print value of ibig.i\[100\] << 2" 290 } 291 -re ".*$gdb_prompt $" { fail "print value of ibig.i\[100\] << 2" } 292 timeout { fail "(timeout) print value of ibig.i\[100\] << 2" } 293 } 294 295send_gdb "print sbig.s\[90\] >> 4\n" 296gdb_expect { 297 -re ".\[0-9\]* = 15.*$gdb_prompt $" { 298 pass "print value of sbig.s\[90\] >> 4" 299 } 300 -re ".*$gdb_prompt $" { fail "print value of sbig.s\[90\] >> 4" } 301 timeout { fail "(timeout) print value of sbig.s\[90\] >> 4" } 302 } 303 304send_gdb "print lbig.l\[333\] >> 6\n" 305gdb_expect { 306 -re ".\[0-9\]* = 15624999.*$gdb_prompt $" { 307 pass "print value of lbig.l\[333\] >> 6" 308 } 309 -re ".*$gdb_prompt $" { fail "print value of lbig.l\[333\] >> 6" } 310 timeout { fail "(timeout) print value of lbig.l\[333\] >> 6" } 311 } 312