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