gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / call-strs.exp
CommitLineData
9b254dd1 1# Copyright 1998, 1999, 2000, 2007, 2008 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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
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
21#
22
23#debug strarg
24
25if $tracelevel then {
26 strace $tracelevel
27}
28
29set prms_id 0
30set bug_id 0
31
32set testfile "call-strs"
33set srcfile ${testfile}.c
34set binfile ${objdir}/${subdir}/${testfile}
35
1960c400
MS
36# Test depends on printf, which the sparclet stub doesn't support.
37if { [istarget "sparclet-*-*"] } {
38 return 0;
39}
40
c906108c 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
42 untested call-strs.exp
43 return -1
c906108c
SS
44}
45
46
47
9fbfe2dc
AC
48# Some targets can't call functions, so don't even bother with this
49# test.
c906108c
SS
50if [target_info exists gdb,cannot_call_functions] {
51 setup_xfail "*-*-*" 2416
52 fail "This target can not call functions"
53 continue
54}
55
56# Set the current language to C. This counts as a test. If it
57# fails, then we skip the other tests.
58
59proc set_lang_c {} {
60 global gdb_prompt
61
62 send_gdb "set language c\n"
63 gdb_expect {
64 -re ".*$gdb_prompt $" {}
65 timeout { fail "set language c (timeout)" ; return 0; }
66 }
67
68 send_gdb "show language\n"
69 gdb_expect {
70 -re ".* source language is \"c\".*$gdb_prompt $" {
71 pass "set language to \"c\""
72 return 1
73 }
74 -re ".*$gdb_prompt $" {
75 fail "setting language to \"c\""
76 return 0
77 }
78 timeout {
79 fail "can't show language (timeout)"
80 return 0
81 }
82 }
83}
84
85
86
87# Start with a fresh gdb.
88
89gdb_exit
90gdb_start
91gdb_reinitialize_dir $srcdir/$subdir
92gdb_load ${binfile}
93send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
94send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
95send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
96
1960c400 97set timeout 120
c906108c
SS
98
99if ![runto_main] then {
100 perror "couldn't run to breakpoint"
101 continue
102}
103
104#step
105send_gdb "step\n"
106gdb_expect {
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)" }
110 }
111
112
37f8da45 113#next
7a292a7a 114send_gdb "next\n"
c906108c 115gdb_expect {
7a292a7a
SS
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)" }
c906108c
SS
119 }
120
121#print buf
122send_gdb "print buf\n"
123gdb_expect {
124 -re ".*\"test string\",.*repeats 88 times.*$gdb_prompt $" {
125 pass "print buf"
126 }
127 -re ".*$gdb_prompt $" { fail "print buf" }
128 timeout { fail "(timeout) print buf" }
129 }
130
131
132#print s
133send_gdb "print s\n"
134gdb_expect {
135 -re ".*= \"test string\".*$gdb_prompt $" {
136 pass "print s"
137 }
138 -re ".*$gdb_prompt $" { fail "print s" }
139 timeout { fail "(timeout) print sum_array_print(10, *list1, *list2, *list3, *list4)" }
140 }
141
142
143#print str_func1(s)
13a5e3b8
MS
144if ![gdb_skip_stdio_test "print str_func1(s)"] {
145 send_gdb "print str_func1(s)\n"
146 gdb_expect {
147 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
148 pass "print str_func1(s)"
149 }
150 -re ".*$gdb_prompt $" { fail "print str_func1(s)" }
151 timeout { fail "(timeout) print str_func1(s)" }
152 }
153}
c906108c
SS
154
155
156#print str_func1("test string")
13a5e3b8
MS
157if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
158 send_gdb "print str_func1(\"test string\")\n"
159 gdb_expect {
160 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
161 pass "print str_func1(\"test string\")"
162 }
163 -re ".*$gdb_prompt $" { fail "print str_func1(\"test string\")" }
164 timeout { fail "(timeout) print str_func1(\"test string\")" }
165 }
166}
c906108c
SS
167
168#call str_func1(s)
13a5e3b8
MS
169if ![gdb_skip_stdio_test "call str_func1(s)"] {
170 send_gdb "call str_func1(s)\n"
171 gdb_expect {
172 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
173 pass "call str_func1(s)"
174 }
175 -re ".*$gdb_prompt $" { fail "call str_func1(s)" }
176 timeout { fail "(timeout) call str_func1(s)" }
177 }
178}
c906108c
SS
179
180#call str_func1("test string")
13a5e3b8
MS
181if ![gdb_skip_stdio_test "call str_func1 (...)"] {
182 send_gdb "call str_func1(\"test string\")\n"
183 gdb_expect {
184 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
185 pass "call str_func1(\"test string\")"
186 }
187 -re ".*$gdb_prompt $" { fail "call str_func1(\"test string\")" }
188 timeout { fail "(timeout) call str_func1(\"test string\")" }
189 }
190}
c906108c
SS
191
192#print str_func1(buf)
13a5e3b8
MS
193if ![gdb_skip_stdio_test "print str_func1(buf)"] {
194 send_gdb "print str_func1(buf)\n"
195 gdb_expect {
196 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
197 pass "print str_func1(buf)"
198 }
199 -re ".*$gdb_prompt $" { fail "print str_func1(buf)" }
200 timeout { fail "(timeout) print str_func1(buf)" }
201 }
202}
c906108c
SS
203
204#call str_func1(buf)
13a5e3b8
MS
205if ![gdb_skip_stdio_test "call str_func1(buf)"] {
206 send_gdb "call str_func1(buf)\n"
207 gdb_expect {
208 -re "first string arg is: test string.*\"test string\".*$gdb_prompt $" {
209 pass "call str_func1(buf)"
210 }
211 -re ".*$gdb_prompt $" { fail "call str_func1(buf)" }
212 timeout { fail "(timeout) call str_func1(buf)" }
213 }
214}
c906108c
SS
215
216#print str_func("a","b","c","d","e","f","g")
13a5e3b8
MS
217if ![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"
219 gdb_expect {
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\")"
222 }
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\")" }
225 }
226}
c906108c
SS
227
228#call str_func("a","b","c","d","e","f","g")
13a5e3b8
MS
229if ![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"
231 gdb_expect {
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\")"
234 }
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\")" }
237 }
238}
c906108c 239
085dd6e6 240#print str_func(s,s,s,s,s,s,s)
13a5e3b8
MS
241if ![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"
243 gdb_expect {
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)"
246 }
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)" }
249 }
250}
c906108c 251
085dd6e6 252#call str_func(s,s,s,s,s,s,s)
13a5e3b8
MS
253if ![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"
255 gdb_expect {
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)"
258 }
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)" }
261 }
262}
c906108c
SS
263
264gdb_exit
265return 0
This page took 0.807841 seconds and 4 git commands to generate.