]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/call-strs.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / call-strs.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2000, 2007 Free Software Foundation, Inc.
c906108c
SS
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
1960c400
MS
40# Test depends on printf, which the sparclet stub doesn't support.
41if { [istarget "sparclet-*-*"] } {
42 return 0;
43}
44
c906108c 45if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
46 untested call-strs.exp
47 return -1
c906108c
SS
48}
49
50
51
9fbfe2dc
AC
52# Some targets can't call functions, so don't even bother with this
53# test.
c906108c
SS
54if [target_info exists gdb,cannot_call_functions] {
55 setup_xfail "*-*-*" 2416
56 fail "This target can not call functions"
57 continue
58}
59
60# Set the current language to C. This counts as a test. If it
61# fails, then we skip the other tests.
62
63proc set_lang_c {} {
64 global gdb_prompt
65
66 send_gdb "set language c\n"
67 gdb_expect {
68 -re ".*$gdb_prompt $" {}
69 timeout { fail "set language c (timeout)" ; return 0; }
70 }
71
72 send_gdb "show language\n"
73 gdb_expect {
74 -re ".* source language is \"c\".*$gdb_prompt $" {
75 pass "set language to \"c\""
76 return 1
77 }
78 -re ".*$gdb_prompt $" {
79 fail "setting language to \"c\""
80 return 0
81 }
82 timeout {
83 fail "can't show language (timeout)"
84 return 0
85 }
86 }
87}
88
89
90
91# Start with a fresh gdb.
92
93gdb_exit
94gdb_start
95gdb_reinitialize_dir $srcdir/$subdir
96gdb_load ${binfile}
97send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
98send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
99send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
100
1960c400 101set timeout 120
c906108c
SS
102
103if ![runto_main] then {
104 perror "couldn't run to breakpoint"
105 continue
106}
107
108#step
109send_gdb "step\n"
110gdb_expect {
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)" }
114 }
115
116
37f8da45 117#next
7a292a7a 118send_gdb "next\n"
c906108c 119gdb_expect {
7a292a7a
SS
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)" }
c906108c
SS
123 }
124
125#print buf
126send_gdb "print buf\n"
127gdb_expect {
128 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
129 pass "print buf"
130 }
131 -re ".*$gdb_prompt $" { fail "print buf" }
132 timeout { fail "(timeout) print buf" }
133 }
134
135
136#print s
137send_gdb "print s\n"
138gdb_expect {
139 -re ".*= \"test string\".*$gdb_prompt $" {
140 pass "print s"
141 }
142 -re ".*$gdb_prompt $" { fail "print s" }
143 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
144 }
145
146
147#print str_func1(s)
13a5e3b8
MS
148if ![gdb_skip_stdio_test "print str_func1(s)"] {
149 send_gdb "print str_func1(s)\n"
150 gdb_expect {
151 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
152 pass "print str_func1(s)"
153 }
154 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
155 timeout { fail "(timeout) print str_func1(s)" }
156 }
157}
c906108c
SS
158
159
160#print str_func1("test string")
13a5e3b8
MS
161if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
162 send_gdb "print str_func1(\"test string\")\n"
163 gdb_expect {
164 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
165 pass "print str_func1(\"test string\")"
166 }
167 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
168 timeout { fail "(timeout) print str_func1(\"test string\")" }
169 }
170}
c906108c
SS
171
172#call str_func1(s)
13a5e3b8
MS
173if ![gdb_skip_stdio_test "call str_func1(s)"] {
174 send_gdb "call str_func1(s)\n"
175 gdb_expect {
176 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
177 pass "call str_func1(s)"
178 }
179 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
180 timeout { fail "(timeout) call str_func1(s)" }
181 }
182}
c906108c
SS
183
184#call str_func1("test string")
13a5e3b8
MS
185if ![gdb_skip_stdio_test "call str_func1 (...)"] {
186 send_gdb "call str_func1(\"test string\")\n"
187 gdb_expect {
188 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
189 pass "call str_func1(\"test string\")"
190 }
191 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
192 timeout { fail "(timeout) call str_func1(\"test string\")" }
193 }
194}
c906108c
SS
195
196#print str_func1(buf)
13a5e3b8
MS
197if ![gdb_skip_stdio_test "print str_func1(buf)"] {
198 send_gdb "print str_func1(buf)\n"
199 gdb_expect {
200 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
201 pass "print str_func1(buf)"
202 }
203 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
204 timeout { fail "(timeout) print str_func1(buf)" }
205 }
206}
c906108c
SS
207
208#call str_func1(buf)
13a5e3b8
MS
209if ![gdb_skip_stdio_test "call str_func1(buf)"] {
210 send_gdb "call str_func1(buf)\n"
211 gdb_expect {
212 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
213 pass "call str_func1(buf)"
214 }
215 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
216 timeout { fail "(timeout) call str_func1(buf)" }
217 }
218}
c906108c
SS
219
220#print str_func("a","b","c","d","e","f","g")
13a5e3b8
MS
221if ![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"
223 gdb_expect {
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\")"
226 }
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\")" }
229 }
230}
c906108c
SS
231
232#call str_func("a","b","c","d","e","f","g")
13a5e3b8
MS
233if ![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"
235 gdb_expect {
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\")"
238 }
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\")" }
241 }
242}
c906108c 243
085dd6e6 244#print str_func(s,s,s,s,s,s,s)
13a5e3b8
MS
245if ![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"
247 gdb_expect {
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)"
250 }
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)" }
253 }
254}
c906108c 255
085dd6e6 256#call str_func(s,s,s,s,s,s,s)
13a5e3b8
MS
257if ![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"
259 gdb_expect {
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)"
262 }
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)" }
265 }
266}
c906108c
SS
267
268gdb_exit
269return 0