1 # Copyright 1998, 1999, 2000, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
19 # This test deals with calling functions which have strings as parameters.
20 # it plays around with constant strings.
21 # the corresponding source file is call-strs.c
33 set testfile "call-strs"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 # Test depends on printf, which the sparclet stub doesn't support.
38 if { [istarget "sparclet-*-*"] } {
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
43 untested call-strs.exp
49 # Some targets can't call functions, so don't even bother with this
51 if [target_info exists gdb,cannot_call_functions] {
52 setup_xfail "*-*-*" 2416
53 fail "This target can not call functions"
57 # Set the current language to C. This counts as a test. If it
58 # fails, then we skip the other tests.
63 send_gdb "set language c\n"
65 -re ".*$gdb_prompt $" {}
66 timeout { fail "set language c (timeout)" ; return 0; }
69 send_gdb "show language\n"
71 -re ".* source language is \"c\".*$gdb_prompt $" {
72 pass "set language to \"c\""
75 -re ".*$gdb_prompt $" {
76 fail "setting language to \"c\""
80 fail "can't show language (timeout)"
88 # Start with a fresh gdb.
92 gdb_reinitialize_dir $srcdir/$subdir
94 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
95 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
96 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
100 if ![runto_main] then {
101 perror "couldn't run to breakpoint"
108 -re ".*strcpy\\(buf, \"test string\"\\);.*$gdb_prompt $" {pass "step after assignment to s"}
109 -re ".*$gdb_prompt $" { fail "step after assignment to s" }
110 timeout { fail "step after assignment to s (timeout)" }
117 -re ".*str_func\\(\"abcd\", \"efgh\", \"ijkl\", \"mnop\", \"qrst\", \"uvwx\", \"yz12\"\\);.*$gdb_prompt $" {pass "next over strcpy"}
118 -re ".*$gdb_prompt $" { fail "next over strcpy" }
119 timeout { fail "next over strcpy (timeout)" }
123 send_gdb "print buf\n"
125 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
128 -re ".*$gdb_prompt $" { fail "print buf" }
129 timeout { fail "(timeout) print buf" }
136 -re ".*= \"test string\".*$gdb_prompt $" {
139 -re ".*$gdb_prompt $" { fail "print s" }
140 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
145 if ![gdb_skip_stdio_test "print str_func1(s)"] {
146 send_gdb "print str_func1(s)\n"
148 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
149 pass "print str_func1(s)"
151 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
152 timeout { fail "(timeout) print str_func1(s)" }
157 #print str_func1("test string")
158 if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
159 send_gdb "print str_func1(\"test string\")\n"
161 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
162 pass "print str_func1(\"test string\")"
164 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
165 timeout { fail "(timeout) print str_func1(\"test string\")" }
170 if ![gdb_skip_stdio_test "call str_func1(s)"] {
171 send_gdb "call str_func1(s)\n"
173 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
174 pass "call str_func1(s)"
176 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
177 timeout { fail "(timeout) call str_func1(s)" }
181 #call str_func1("test string")
182 if ![gdb_skip_stdio_test "call str_func1 (...)"] {
183 send_gdb "call str_func1(\"test string\")\n"
185 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
186 pass "call str_func1(\"test string\")"
188 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
189 timeout { fail "(timeout) call str_func1(\"test string\")" }
193 #print str_func1(buf)
194 if ![gdb_skip_stdio_test "print str_func1(buf)"] {
195 send_gdb "print str_func1(buf)\n"
197 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
198 pass "print str_func1(buf)"
200 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
201 timeout { fail "(timeout) print str_func1(buf)" }
206 if ![gdb_skip_stdio_test "call str_func1(buf)"] {
207 send_gdb "call str_func1(buf)\n"
209 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
210 pass "call str_func1(buf)"
212 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
213 timeout { fail "(timeout) call str_func1(buf)" }
217 #print str_func("a","b","c","d","e","f","g")
218 if ![gdb_skip_stdio_test "print str_func(a,b,c,d,e,f,g)"] {
219 send_gdb "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
221 -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 $" {
222 pass "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
224 -re ".*$gdb_prompt $" { fail "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
225 timeout { fail "(timeout) print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
229 #call str_func("a","b","c","d","e","f","g")
230 if ![gdb_skip_stdio_test "call str_func(a,b,c,d,e,f,g)"] {
231 send_gdb "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
233 -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 $" {
234 pass "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
236 -re ".*$gdb_prompt $" { fail "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
237 timeout { fail "(timeout) call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
241 #print str_func(s,s,s,s,s,s,s)
242 if ![gdb_skip_stdio_test "print str_func(s,s,s,s,s,s,s,s)"] {
243 send_gdb "print str_func(s,s,s,s,s,s,s)\n"
245 -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 $" {
246 pass "print str_func(s,s,s,s,s,s,s)"
248 -re ".*$gdb_prompt $" { fail "print str_func(s,s,s,s,s,s,s)" }
249 timeout { fail "(timeout) print str_func(s,s,s,s,s,s,s)" }
253 #call str_func(s,s,s,s,s,s,s)
254 if ![gdb_skip_stdio_test "call str_func(s,s,s,s,s,s,s,s)"] {
255 send_gdb "call str_func(s,s,s,s,s,s,s)\n"
257 -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 $" {
258 pass "call str_func(s,s,s,s,s,s,s)"
260 -re ".*$gdb_prompt $" { fail "call str_func(s,s,s,s,s,s,s)" }
261 timeout { fail "(timeout) call str_func(s,s,s,s,s,s,s)" }