]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/call-strs.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / call-strs.exp
1 # Copyright 1998, 1999, 2000, 2007 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 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
29 if $tracelevel then {
30 strace $tracelevel
31 }
32
33 set prms_id 0
34 set bug_id 0
35
36 set testfile "call-strs"
37 set srcfile ${testfile}.c
38 set binfile ${objdir}/${subdir}/${testfile}
39
40 # Test depends on printf, which the sparclet stub doesn't support.
41 if { [istarget "sparclet-*-*"] } {
42 return 0;
43 }
44
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
46 untested call-strs.exp
47 return -1
48 }
49
50
51
52 # Some targets can't call functions, so don't even bother with this
53 # test.
54 if [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
63 proc 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
93 gdb_exit
94 gdb_start
95 gdb_reinitialize_dir $srcdir/$subdir
96 gdb_load ${binfile}
97 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
98 send_gdb "set print address off\n" ; gdb_expect -re "$gdb_prompt $"
99 send_gdb "set width 0\n" ; gdb_expect -re "$gdb_prompt $"
100
101 set timeout 120
102
103 if ![runto_main] then {
104 perror "couldn't run to breakpoint"
105 continue
106 }
107
108 #step
109 send_gdb "step\n"
110 gdb_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
117 #next
118 send_gdb "next\n"
119 gdb_expect {
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)" }
123 }
124
125 #print buf
126 send_gdb "print buf\n"
127 gdb_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
137 send_gdb "print s\n"
138 gdb_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)
148 if ![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 }
158
159
160 #print str_func1("test string")
161 if ![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 }
171
172 #call str_func1(s)
173 if ![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 }
183
184 #call str_func1("test string")
185 if ![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 }
195
196 #print str_func1(buf)
197 if ![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 }
207
208 #call str_func1(buf)
209 if ![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 }
219
220 #print str_func("a","b","c","d","e","f","g")
221 if ![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 }
231
232 #call str_func("a","b","c","d","e","f","g")
233 if ![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 }
243
244 #print str_func(s,s,s,s,s,s,s)
245 if ![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 }
255
256 #call str_func(s,s,s,s,s,s,s)
257 if ![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 }
267
268 gdb_exit
269 return 0