]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/call-strs.exp
Updated copyright notices for most files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / call-strs.exp
1 # Copyright 1998, 1999, 2000, 2007, 2008, 2009 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
15
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
25 if $tracelevel then {
26 strace $tracelevel
27 }
28
29 set prms_id 0
30 set bug_id 0
31
32 set testfile "call-strs"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 # Test depends on printf, which the sparclet stub doesn't support.
37 if { [istarget "sparclet-*-*"] } {
38 return 0;
39 }
40
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 untested call-strs.exp
43 return -1
44 }
45
46
47
48 # Some targets can't call functions, so don't even bother with this
49 # test.
50 if [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
59 proc 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
89 gdb_exit
90 gdb_start
91 gdb_reinitialize_dir $srcdir/$subdir
92 gdb_load ${binfile}
93 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
94 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
95 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
96
97 set timeout 120
98
99 if ![runto_main] then {
100 perror "couldn't run to breakpoint"
101 continue
102 }
103
104 #step
105 send_gdb "step\n"
106 gdb_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
113 #next
114 send_gdb "next\n"
115 gdb_expect {
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)" }
119 }
120
121 #print buf
122 send_gdb "print buf\n"
123 gdb_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
133 send_gdb "print s\n"
134 gdb_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)
144 if ![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 }
154
155
156 #print str_func1("test string")
157 if ![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 }
167
168 #call str_func1(s)
169 if ![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 }
179
180 #call str_func1("test string")
181 if ![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 }
191
192 #print str_func1(buf)
193 if ![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 }
203
204 #call str_func1(buf)
205 if ![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 }
215
216 #print str_func("a","b","c","d","e","f","g")
217 if ![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 }
227
228 #call str_func("a","b","c","d","e","f","g")
229 if ![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 }
239
240 #print str_func(s,s,s,s,s,s,s)
241 if ![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 }
251
252 #call str_func(s,s,s,s,s,s,s)
253 if ![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 }
263
264 gdb_exit
265 return 0