1 # Copyright 1998, 1999, 2000, 2007, 2008, 2009 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 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # This test deals with calling functions which have strings as parameters.
19 # it plays around with constant strings.
20 # the corresponding source file is call-strs.c
32 set testfile "call-strs"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
36 # Test depends on printf, which the sparclet stub doesn't support.
37 if { [istarget "sparclet-*-*"] } {
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 untested call-strs.exp
48 # Some targets can't call functions, so don't even bother with this
50 if [target_info exists gdb,cannot_call_functions] {
51 setup_xfail "*-*-*" 2416
52 fail "This target can not call functions"
56 # Set the current language to C. This counts as a test. If it
57 # fails, then we skip the other tests.
62 send_gdb "set language c\n"
64 -re ".*$gdb_prompt $" {}
65 timeout { fail "set language c (timeout)" ; return 0; }
68 send_gdb "show language\n"
70 -re ".* source language is \"c\".*$gdb_prompt $" {
71 pass "set language to \"c\""
74 -re ".*$gdb_prompt $" {
75 fail "setting language to \"c\""
79 fail "can't show language (timeout)"
87 # Start with a fresh gdb.
91 gdb_reinitialize_dir $srcdir/$subdir
93 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
94 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
95 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
99 if ![runto_main] then {
100 perror "couldn't run to breakpoint"
107 -re ".*strcpy\\(buf, \"test string\"\\);.*$gdb_prompt $" {pass "step after assignment to s"}
108 -re ".*$gdb_prompt $" { fail "step after assignment to s" }
109 timeout { fail "step after assignment to s (timeout)" }
116 -re ".*str_func\\(\"abcd\", \"efgh\", \"ijkl\", \"mnop\", \"qrst\", \"uvwx\", \"yz12\"\\);.*$gdb_prompt $" {pass "next over strcpy"}
117 -re ".*$gdb_prompt $" { fail "next over strcpy" }
118 timeout { fail "next over strcpy (timeout)" }
122 send_gdb "print buf\n"
124 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
127 -re ".*$gdb_prompt $" { fail "print buf" }
128 timeout { fail "(timeout) print buf" }
135 -re ".*= \"test string\".*$gdb_prompt $" {
138 -re ".*$gdb_prompt $" { fail "print s" }
139 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
144 if ![gdb_skip_stdio_test "print str_func1(s)"] {
145 send_gdb "print str_func1(s)\n"
147 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
148 pass "print str_func1(s)"
150 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
151 timeout { fail "(timeout) print str_func1(s)" }
156 #print str_func1("test string")
157 if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
158 send_gdb "print str_func1(\"test string\")\n"
160 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
161 pass "print str_func1(\"test string\")"
163 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
164 timeout { fail "(timeout) print str_func1(\"test string\")" }
169 if ![gdb_skip_stdio_test "call str_func1(s)"] {
170 send_gdb "call str_func1(s)\n"
172 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
173 pass "call str_func1(s)"
175 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
176 timeout { fail "(timeout) call str_func1(s)" }
180 #call str_func1("test string")
181 if ![gdb_skip_stdio_test "call str_func1 (...)"] {
182 send_gdb "call str_func1(\"test string\")\n"
184 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
185 pass "call str_func1(\"test string\")"
187 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
188 timeout { fail "(timeout) call str_func1(\"test string\")" }
192 #print str_func1(buf)
193 if ![gdb_skip_stdio_test "print str_func1(buf)"] {
194 send_gdb "print str_func1(buf)\n"
196 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
197 pass "print str_func1(buf)"
199 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
200 timeout { fail "(timeout) print str_func1(buf)" }
205 if ![gdb_skip_stdio_test "call str_func1(buf)"] {
206 send_gdb "call str_func1(buf)\n"
208 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
209 pass "call str_func1(buf)"
211 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
212 timeout { fail "(timeout) call str_func1(buf)" }
216 #print str_func("a","b","c","d","e","f","g")
217 if ![gdb_skip_stdio_test "print str_func(a,b,c,d,e,f,g)"] {
218 send_gdb "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
220 -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 $" {
221 pass "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
223 -re ".*$gdb_prompt $" { fail "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
224 timeout { fail "(timeout) print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
228 #call str_func("a","b","c","d","e","f","g")
229 if ![gdb_skip_stdio_test "call str_func(a,b,c,d,e,f,g)"] {
230 send_gdb "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
232 -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 $" {
233 pass "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
235 -re ".*$gdb_prompt $" { fail "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
236 timeout { fail "(timeout) call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
240 #print str_func(s,s,s,s,s,s,s)
241 if ![gdb_skip_stdio_test "print str_func(s,s,s,s,s,s,s,s)"] {
242 send_gdb "print str_func(s,s,s,s,s,s,s)\n"
244 -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 $" {
245 pass "print str_func(s,s,s,s,s,s,s)"
247 -re ".*$gdb_prompt $" { fail "print str_func(s,s,s,s,s,s,s)" }
248 timeout { fail "(timeout) print str_func(s,s,s,s,s,s,s)" }
252 #call str_func(s,s,s,s,s,s,s)
253 if ![gdb_skip_stdio_test "call str_func(s,s,s,s,s,s,s,s)"] {
254 send_gdb "call str_func(s,s,s,s,s,s,s)\n"
256 -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 $" {
257 pass "call str_func(s,s,s,s,s,s,s)"
259 -re ".*$gdb_prompt $" { fail "call str_func(s,s,s,s,s,s,s)" }
260 timeout { fail "(timeout) call str_func(s,s,s,s,s,s,s)" }