1 # Copyright 1998, 1999, 2000, 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
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
36 set testfile "call-strs"
37 set srcfile ${testfile}.c
38 set binfile ${objdir}/${subdir}/${testfile}
40 # Test depends on printf, which the sparclet stub doesn't support.
41 if { [istarget "sparclet-*-*"] } {
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
46 untested call-strs.exp
52 # Some targets can't call functions, so don't even bother with this
54 if [target_info exists gdb,cannot_call_functions] {
55 setup_xfail "*-*-*" 2416
56 fail "This target can not call functions"
60 # Set the current language to C. This counts as a test. If it
61 # fails, then we skip the other tests.
66 send_gdb "set language c\n"
68 -re ".*$gdb_prompt $" {}
69 timeout { fail "set language c (timeout)" ; return 0; }
72 send_gdb "show language\n"
74 -re ".* source language is \"c\".*$gdb_prompt $" {
75 pass "set language to \"c\""
78 -re ".*$gdb_prompt $" {
79 fail "setting language to \"c\""
83 fail "can't show language (timeout)"
91 # Start with a fresh gdb.
95 gdb_reinitialize_dir $srcdir/$subdir
97 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
98 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
99 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
103 if ![runto_main] then {
104 perror "couldn't run to breakpoint"
111 -re ".*strcpy\\(buf, \"test string\"\\);.*$gdb_prompt $" {pass "step after assignment to s"}
112 -re ".*$gdb_prompt $" { fail "step after assignment to s" }
113 timeout { fail "step after assignment to s (timeout)" }
120 -re ".*str_func\\(\"abcd\", \"efgh\", \"ijkl\", \"mnop\", \"qrst\", \"uvwx\", \"yz12\"\\);.*$gdb_prompt $" {pass "next over strcpy"}
121 -re ".*$gdb_prompt $" { fail "next over strcpy" }
122 timeout { fail "next over strcpy (timeout)" }
126 send_gdb "print buf\n"
128 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
131 -re ".*$gdb_prompt $" { fail "print buf" }
132 timeout { fail "(timeout) print buf" }
139 -re ".*= \"test string\".*$gdb_prompt $" {
142 -re ".*$gdb_prompt $" { fail "print s" }
143 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
148 if ![gdb_skip_stdio_test "print str_func1(s)"] {
149 send_gdb "print str_func1(s)\n"
151 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
152 pass "print str_func1(s)"
154 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
155 timeout { fail "(timeout) print str_func1(s)" }
160 #print str_func1("test string")
161 if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
162 send_gdb "print str_func1(\"test string\")\n"
164 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
165 pass "print str_func1(\"test string\")"
167 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
168 timeout { fail "(timeout) print str_func1(\"test string\")" }
173 if ![gdb_skip_stdio_test "call str_func1(s)"] {
174 send_gdb "call str_func1(s)\n"
176 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
177 pass "call str_func1(s)"
179 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
180 timeout { fail "(timeout) call str_func1(s)" }
184 #call str_func1("test string")
185 if ![gdb_skip_stdio_test "call str_func1 (...)"] {
186 send_gdb "call str_func1(\"test string\")\n"
188 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
189 pass "call str_func1(\"test string\")"
191 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
192 timeout { fail "(timeout) call str_func1(\"test string\")" }
196 #print str_func1(buf)
197 if ![gdb_skip_stdio_test "print str_func1(buf)"] {
198 send_gdb "print str_func1(buf)\n"
200 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
201 pass "print str_func1(buf)"
203 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
204 timeout { fail "(timeout) print str_func1(buf)" }
209 if ![gdb_skip_stdio_test "call str_func1(buf)"] {
210 send_gdb "call str_func1(buf)\n"
212 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
213 pass "call str_func1(buf)"
215 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
216 timeout { fail "(timeout) call str_func1(buf)" }
220 #print str_func("a","b","c","d","e","f","g")
221 if ![gdb_skip_stdio_test "print str_func(a,b,c,d,e,f,g)"] {
222 send_gdb "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
224 -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 $" {
225 pass "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
227 -re ".*$gdb_prompt $" { fail "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
228 timeout { fail "(timeout) print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
232 #call str_func("a","b","c","d","e","f","g")
233 if ![gdb_skip_stdio_test "call str_func(a,b,c,d,e,f,g)"] {
234 send_gdb "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")\n"
236 -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 $" {
237 pass "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")"
239 -re ".*$gdb_prompt $" { fail "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
240 timeout { fail "(timeout) call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" }
244 #print str_func(s,s,s,s,s,s,s)
245 if ![gdb_skip_stdio_test "print str_func(s,s,s,s,s,s,s,s)"] {
246 send_gdb "print str_func(s,s,s,s,s,s,s)\n"
248 -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 $" {
249 pass "print str_func(s,s,s,s,s,s,s)"
251 -re ".*$gdb_prompt $" { fail "print str_func(s,s,s,s,s,s,s)" }
252 timeout { fail "(timeout) print str_func(s,s,s,s,s,s,s)" }
256 #call str_func(s,s,s,s,s,s,s)
257 if ![gdb_skip_stdio_test "call str_func(s,s,s,s,s,s,s,s)"] {
258 send_gdb "call str_func(s,s,s,s,s,s,s)\n"
260 -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 $" {
261 pass "call str_func(s,s,s,s,s,s,s)"
263 -re ".*$gdb_prompt $" { fail "call str_func(s,s,s,s,s,s,s)" }
264 timeout { fail "(timeout) call str_func(s,s,s,s,s,s,s)" }