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# This file was written by Elena Zannoni (ezannoni@cygnus.com) 21 22# This test deals with calling functions which have strings as parameters. 23# it plays around with constant strings. 24# the corresponding source file is call-strs.c 25# 26 27#debug strarg 28 29if $tracelevel then { 30 strace $tracelevel 31} 32 33set prms_id 0 34set bug_id 0 35 36set testfile "call-strs" 37set srcfile ${testfile}.c 38set binfile ${objdir}/${subdir}/${testfile} 39 40# Test depends on printf, which the sparclet stub doesn't support. 41if { [istarget "sparclet-*-*"] } { 42 return 0; 43} 44 45if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 47} 48 49 50 51# Some targets can't call functions, so don't even bother with this 52# test. 53if [target_info exists gdb,cannot_call_functions] { 54 setup_xfail "*-*-*" 2416 55 fail "This target can not call functions" 56 continue 57} 58 59# Set the current language to C. This counts as a test. If it 60# fails, then we skip the other tests. 61 62proc set_lang_c {} { 63 global gdb_prompt 64 65 send_gdb "set language c\n" 66 gdb_expect { 67 -re ".*$gdb_prompt $" {} 68 timeout { fail "set language c (timeout)" ; return 0; } 69 } 70 71 send_gdb "show language\n" 72 gdb_expect { 73 -re ".* source language is \"c\".*$gdb_prompt $" { 74 pass "set language to \"c\"" 75 return 1 76 } 77 -re ".*$gdb_prompt $" { 78 fail "setting language to \"c\"" 79 return 0 80 } 81 timeout { 82 fail "can't show language (timeout)" 83 return 0 84 } 85 } 86} 87 88 89 90# Start with a fresh gdb. 91 92gdb_exit 93gdb_start 94gdb_reinitialize_dir $srcdir/$subdir 95gdb_load ${binfile} 96send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $" 97send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $" 98send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $" 99 100set timeout 120 101 102if ![runto_main] then { 103 perror "couldn't run to breakpoint" 104 continue 105} 106 107#step 108send_gdb "step\n" 109gdb_expect { 110 -re ".*strcpy\\(buf, \"test string\"\\);.*$gdb_prompt $" {pass "step after assignment to s"} 111 -re ".*$gdb_prompt $" { fail "step after assignment to s" } 112 timeout { fail "step after assignment to s (timeout)" } 113 } 114 115 116#next 117send_gdb "next\n" 118gdb_expect { 119 -re ".*str_func\\(\"abcd\", \"efgh\", \"ijkl\", \"mnop\", \"qrst\", \"uvwx\", \"yz12\"\\);.*$gdb_prompt $" {pass "next over strcpy"} 120 -re ".*$gdb_prompt $" { fail "next over strcpy" } 121 timeout { fail "next over strcpy (timeout)" } 122 } 123 124#print buf 125send_gdb "print buf\n" 126gdb_expect { 127 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" { 128 pass "print buf" 129 } 130 -re ".*$gdb_prompt $" { fail "print buf" } 131 timeout { fail "(timeout) print buf" } 132 } 133 134 135#print s 136send_gdb "print s\n" 137gdb_expect { 138 -re ".*= \"test string\".*$gdb_prompt $" { 139 pass "print s" 140 } 141 -re ".*$gdb_prompt $" { fail "print s" } 142 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" } 143 } 144 145 146#print str_func1(s) 147if ![gdb_skip_stdio_test "print str_func1(s)"] { 148 send_gdb "print str_func1(s)\n" 149 gdb_expect { 150 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 151 pass "print str_func1(s)" 152 } 153 -re ".*$gdb_prompt $" { fail "print str_func1(s)" } 154 timeout { fail "(timeout) print str_func1(s)" } 155 } 156} 157 158 159#print str_func1("test string") 160if ![gdb_skip_stdio_test "print str_func1(teststring)"] { 161 send_gdb "print str_func1(\"test string\")\n" 162 gdb_expect { 163 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 164 pass "print str_func1(\"test string\")" 165 } 166 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" } 167 timeout { fail "(timeout) print str_func1(\"test string\")" } 168 } 169} 170 171#call str_func1(s) 172if ![gdb_skip_stdio_test "call str_func1(s)"] { 173 send_gdb "call str_func1(s)\n" 174 gdb_expect { 175 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 176 pass "call str_func1(s)" 177 } 178 -re ".*$gdb_prompt $" { fail "call str_func1(s)" } 179 timeout { fail "(timeout) call str_func1(s)" } 180 } 181} 182 183#call str_func1("test string") 184if ![gdb_skip_stdio_test "call str_func1 (...)"] { 185 send_gdb "call str_func1(\"test string\")\n" 186 gdb_expect { 187 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 188 pass "call str_func1(\"test string\")" 189 } 190 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" } 191 timeout { fail "(timeout) call str_func1(\"test string\")" } 192 } 193} 194 195#print str_func1(buf) 196if ![gdb_skip_stdio_test "print str_func1(buf)"] { 197 send_gdb "print str_func1(buf)\n" 198 gdb_expect { 199 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 200 pass "print str_func1(buf)" 201 } 202 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" } 203 timeout { fail "(timeout) print str_func1(buf)" } 204 } 205} 206 207#call str_func1(buf) 208if ![gdb_skip_stdio_test "call str_func1(buf)"] { 209 send_gdb "call str_func1(buf)\n" 210 gdb_expect { 211 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" { 212 pass "call str_func1(buf)" 213 } 214 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" } 215 timeout { fail "(timeout) call str_func1(buf)" } 216 } 217} 218 219#print str_func("a","b","c","d","e","f","g") 220if ![gdb_skip_stdio_test "print str_func(a,b,c,d,e,f,g)"] { 221 send_gdb "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n" 222 gdb_expect { 223 -re "first string arg is: a\[ \t\r\n\]+second string arg is: b\[ \t\r\n\]+third string arg is: c\[ \t\r\n\]+fourth string arg is: d\[ \t\r\n\]+fifth string arg is: e\[ \t\r\n\]+sixth string arg is: f\[ \t\r\n\]+seventh string arg is: g\[ \t\r\n\]+.*= \"abcdefg\".*$gdb_prompt $" { 224 pass "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" 225 } 226 -re ".*$gdb_prompt $" { fail "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" } 227 timeout { fail "(timeout) print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" } 228 } 229} 230 231#call str_func("a","b","c","d","e","f","g") 232if ![gdb_skip_stdio_test "call str_func(a,b,c,d,e,f,g)"] { 233 send_gdb "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n" 234 gdb_expect { 235 -re "first string arg is: a\[ \t\r\n\]+second string arg is: b\[ \t\r\n\]+third string arg is: c\[ \t\r\n\]+fourth string arg is: d\[ \t\r\n\]+fifth string arg is: e\[ \t\r\n\]+sixth string arg is: f\[ \t\r\n\]+seventh string arg is: g\[ \t\r\n\]+.*= \"abcdefg\".*$gdb_prompt $" { 236 pass "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" 237 } 238 -re ".*$gdb_prompt $" { fail "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" } 239 timeout { fail "(timeout) call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" } 240 } 241} 242 243#print str_func(s,s,s,s,s,s,s) 244if ![gdb_skip_stdio_test "print str_func(s,s,s,s,s,s,s,s)"] { 245 send_gdb "print str_func(s,s,s,s,s,s,s)\n" 246 gdb_expect { 247 -re "first string arg is: test string\[ \t\r\n\]+second string arg is: test string\[ \t\r\n\]+third string arg is: test string\[ \t\r\n\]+fourth string arg is: test string\[ \t\r\n\]+fifth string arg is: test string\[ \t\r\n\]+sixth string arg is: test string\[ \t\r\n\]+seventh string arg is: test string\[ \t\r\n\]+.*\"test stringtest stringtest stringtest stringtest stringtest stringtest string\".*$gdb_prompt $" { 248 pass "print str_func(s,s,s,s,s,s,s)" 249 } 250 -re ".*$gdb_prompt $" { fail "print str_func(s,s,s,s,s,s,s)" } 251 timeout { fail "(timeout) print str_func(s,s,s,s,s,s,s)" } 252 } 253} 254 255#call str_func(s,s,s,s,s,s,s) 256if ![gdb_skip_stdio_test "call str_func(s,s,s,s,s,s,s,s)"] { 257 send_gdb "call str_func(s,s,s,s,s,s,s)\n" 258 gdb_expect { 259 -re "first string arg is: test string\[ \t\r\n\]+second string arg is: test string\[ \t\r\n\]+third string arg is: test string\[ \t\r\n\]+fourth string arg is: test string\[ \t\r\n\]+fifth string arg is: test string\[ \t\r\n\]+sixth string arg is: test string\[ \t\r\n\]+seventh string arg is: test string\[ \t\r\n\]+.*\"test stringtest stringtest stringtest stringtest stringtest stringtest string\".*$gdb_prompt $" { 260 pass "call str_func(s,s,s,s,s,s,s)" 261 } 262 -re ".*$gdb_prompt $" { fail "call str_func(s,s,s,s,s,s,s)" } 263 timeout { fail "(timeout) call str_func(s,s,s,s,s,s,s)" } 264 } 265} 266 267gdb_exit 268return 0 269