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