1 # Copyright 1998, 1999, 2000 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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 # Some targets can't call functions, so don't even bother with this
53 if [target_info exists gdb,cannot_call_functions] {
54 setup_xfail "*-*-*" 2416
55 fail "This target can not call functions"
59 # Set the current language to C. This counts as a test. If it
60 # fails, then we skip the other tests.
65 send_gdb "set language c\n"
67 -re ".*$gdb_prompt $" {}
68 timeout { fail "set language c (timeout)" ; return 0; }
71 send_gdb "show language\n"
73 -re ".* source language is \"c\".*$gdb_prompt $" {
74 pass "set language to \"c\""
77 -re ".*$gdb_prompt $" {
78 fail "setting language to \"c\""
82 fail "can't show language (timeout)"
90 # Start with a fresh gdb.
94 gdb_reinitialize_dir $srcdir/$subdir
96 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
97 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
98 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
102 if ![runto_main] then {
103 perror "couldn't run to breakpoint"
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)" }
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)" }
125 send_gdb "print buf\n"
127 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
130 -re ".*$gdb_prompt $" { fail "print buf" }
131 timeout { fail "(timeout) print buf" }
138 -re ".*= \"test string\".*$gdb_prompt $" {
141 -re ".*$gdb_prompt $" { fail "print s" }
142 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
147 if ![gdb_skip_stdio_test "print str_func1(s)"] {
148 send_gdb "print str_func1(s)\n"
150 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
151 pass "print str_func1(s)"
153 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
154 timeout { fail "(timeout) print str_func1(s)" }
159 #print str_func1("test string")
160 if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
161 send_gdb "print str_func1(\"test string\")\n"
163 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
164 pass "print str_func1(\"test string\")"
166 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
167 timeout { fail "(timeout) print str_func1(\"test string\")" }
172 if ![gdb_skip_stdio_test "call str_func1(s)"] {
173 send_gdb "call str_func1(s)\n"
175 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
176 pass "call str_func1(s)"
178 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
179 timeout { fail "(timeout) call str_func1(s)" }
183 #call str_func1("test string")
184 if ![gdb_skip_stdio_test "call str_func1 (...)"] {
185 send_gdb "call str_func1(\"test string\")\n"
187 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
188 pass "call str_func1(\"test string\")"
190 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
191 timeout { fail "(timeout) call str_func1(\"test string\")" }
195 #print str_func1(buf)
196 if ![gdb_skip_stdio_test "print str_func1(buf)"] {
197 send_gdb "print str_func1(buf)\n"
199 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
200 pass "print str_func1(buf)"
202 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
203 timeout { fail "(timeout) print str_func1(buf)" }
208 if ![gdb_skip_stdio_test "call str_func1(buf)"] {
209 send_gdb "call str_func1(buf)\n"
211 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
212 pass "call str_func1(buf)"
214 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
215 timeout { fail "(timeout) call str_func1(buf)" }
219 #print str_func("a","b","c","d","e","f","g")
220 if ![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"
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\")"
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\")" }
231 #call str_func("a","b","c","d","e","f","g")
232 if ![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"
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\")"
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\")" }
243 #print str_func(s,s,s,s,s,s,s)
244 if ![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"
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)"
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)" }
255 #call str_func(s,s,s,s,s,s,s)
256 if ![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"
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)"
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)" }