1 # Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # written by Elena Zannoni (elz@apollo.hp.com)
23 # This file is part of the gdb testsuite
25 # tests for const variables
26 # const pointers to vars
27 # pointers to const variables
28 # const pointers to const vars
36 # test running programs
41 set testfile "constvars"
42 set srcfile ${testfile}.c
43 set binfile ${objdir}/${subdir}/${testfile}
45 # Create and source the file that provides information about the compiler
46 # used to compile the test case.
47 if [get_compiler_info ${binfile}] {
51 if {$hp_aCC_compiler || $hp_cc_compiler} {
57 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [concat debug $lang]] != "" } {
58 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
61 # Create and source the file that provides information about the compiler
62 # used to compile the test case.
64 if [get_compiler_info ${binfile}] {
70 gdb_reinitialize_dir $srcdir/$subdir
75 # set it up at a breakpoint so we can play with the variable values
77 if ![runto_main] then {
78 perror "couldn't run to breakpoint"
84 proc local_compiler_xfail_check { } {
85 if { [test_compiler_info gcc-2-*] } then {
86 if { ![test_debug_format "HP"] \
87 && ![test_debug_format "DWARF 2"] } then {
93 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
97 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
100 -re ".*main.*$gdb_prompt $" {
101 pass "up from marker1"
103 -re ".*$gdb_prompt $" {
104 fail "up from marker1"
106 timeout { fail "up from marker1 (timeout)" }
109 -re "Break.* marker1__.* \\(\\) at .*:$decimal.*$gdb_prompt $" {
110 fail "continue to marker1 (demangling)"
113 -re ".*main.*$gdb_prompt $" {
114 pass "up from marker1"
116 -re ".*$gdb_prompt $" {
117 fail "up from marker1"
119 timeout { fail "up from marker1 (timeout)" }
122 -re "$gdb_prompt $" { fail "continue to marker1" }
123 timeout { fail "(timeout) continue to marker1" }
126 # test function parameters
128 local_compiler_xfail_check
129 if { [test_compiler_info gcc-3-*] && [test_debug_format "stabs"] } then {
130 # With stabs, even GCC 3 does not get the const char arguments correct.
133 send_gdb "ptype qux1\n"
135 -re "type = int \\(const char, const char, const char \\*, char \\* const\\).*$gdb_prompt $" {
138 -re ".*$gdb_prompt $" { fail "ptype qux1" }
139 timeout { fail "(timeout) ptype qux1" }
142 # test vars and pointers
144 proc do_constvar_tests {} {
145 gdb_test "print lave" " = 66 'B'"
146 gdb_test "ptype lave" "type = char"
147 gdb_test "print lavish" " = 10 '\\\\n'"
148 gdb_test "ptype lavish" "type = unsigned char"
149 gdb_test "print lax" " = 20"
150 gdb_test "ptype lax" "type = short.*"
151 gdb_test "print lecherous" " = 30"
152 gdb_test "ptype lecherous" "type = (unsigned short|short unsigned)( int)?"
153 gdb_test "print lechery" " = 40"
154 gdb_test "ptype lechery" "type = long.*"
155 gdb_test "print lectern" " = 50"
156 gdb_test "ptype lectern" "type = (unsigned long|long unsigned)( int)?"
157 gdb_test "print leeway" " = 60"
158 gdb_test "ptype leeway" "type = float"
159 gdb_test "print legacy" " = 70"
160 gdb_test "ptype legacy" "type = double"
161 gdb_test "print laconic" " = 65 'A'"
162 local_compiler_xfail_check
163 gdb_test "ptype laconic" "type = const char"
164 gdb_test "print laggard" " = 1 '.001'"
165 local_compiler_xfail_check
166 gdb_test "ptype laggard" "type = const unsigned char"
167 gdb_test "print lagoon" " = 2"
168 local_compiler_xfail_check
169 gdb_test "ptype lagoon" "type = const short( int)?"
170 gdb_test "print laity" " = 3"
171 local_compiler_xfail_check
172 gdb_test "ptype laity" "type = const (unsigned short|short unsigned)( int)?"
173 gdb_test "print lambent" " = 4"
174 local_compiler_xfail_check
175 gdb_test "ptype lambent" "type = const long( int)?"
176 gdb_test "print laminated" " = 5"
177 local_compiler_xfail_check
178 gdb_test "ptype laminated" "type = const (unsigned long|long unsigned)( int)?"
179 gdb_test "print lampoon" " = 6"
180 local_compiler_xfail_check
181 gdb_test "ptype lampoon" "type = const float"
182 gdb_test "print languid" " = 7"
183 local_compiler_xfail_check
184 gdb_test "ptype languid" "type = const double"
185 gdb_test "print *legend" " = 66 'B'"
186 local_compiler_xfail_check
187 gdb_test "ptype legend" "type = const char \\*"
188 gdb_test "print *legerdemain" " = 10 '\\\\n'"
189 local_compiler_xfail_check
190 gdb_test "ptype legerdemain" "type = const unsigned char \\*"
191 gdb_test "print *leniency" " = 20"
192 local_compiler_xfail_check
193 gdb_test "ptype leniency" "type = const short( int)? \\*"
194 gdb_test "print *leonine" " = 30"
195 local_compiler_xfail_check
196 gdb_test "ptype leonine" "type = const (unsigned short|short unsigned)( int)? \\*"
197 gdb_test "print *lesion" " = 40"
198 local_compiler_xfail_check
199 gdb_test "ptype lesion" "type = const long( int)? \\*"
200 gdb_test "print *lethal" " = 50"
201 local_compiler_xfail_check
202 gdb_test "ptype lethal" "type = const (unsigned long|long unsigned)( int)? \\*"
203 gdb_test "print *lethargic" " = 60"
204 local_compiler_xfail_check
205 gdb_test "ptype lethargic" "type = const float \\*"
206 gdb_test "print *levity" " = 70"
207 local_compiler_xfail_check
208 gdb_test "ptype levity" "type = const double \\*"
209 gdb_test "print *lewd" " = 65 'A'"
210 local_compiler_xfail_check
211 gdb_test "ptype lewd" "type = const char \\* const"
212 gdb_test "print *lexicographer" " = 1 '.001'"
213 local_compiler_xfail_check
214 gdb_test "ptype lexicographer" "type = const unsigned char \\* const"
215 gdb_test "print *lexicon" " = 2"
216 local_compiler_xfail_check
217 gdb_test "ptype lexicon" "type = const short( int)? \\* const"
218 gdb_test "print *liaison" " = 3"
219 local_compiler_xfail_check
220 gdb_test "ptype liaison" "type = const (unsigned short|short unsigned)( int)? \\* const"
221 gdb_test "print *libation" " = 4"
222 local_compiler_xfail_check
223 gdb_test "ptype libation" "type = const long( int)? \\* const"
224 gdb_test "print *libelous" " = 5"
225 local_compiler_xfail_check
226 gdb_test "ptype libelous" "type = const (unsigned long|long unsigned)( int)? \\* const"
227 gdb_test "print *libertine" " = 6"
228 local_compiler_xfail_check
229 gdb_test "ptype libertine" "type = const float \\* const"
230 gdb_test "print *libidinous" " = 7"
231 local_compiler_xfail_check
232 gdb_test "ptype libidinous" "type = const double \\* const"
233 gdb_test "print *languish" " = 65 'A'"
234 local_compiler_xfail_check
235 gdb_test "ptype languish" "type = const char \\*"
236 gdb_test "print *languor" " = 1 '.001'"
237 local_compiler_xfail_check
238 gdb_test "ptype languor" "type = const unsigned char \\*"
239 gdb_test "print *lank" " = 2"
240 local_compiler_xfail_check
241 gdb_test "ptype lank" "type = const short( int)? \\*"
242 gdb_test "print *lapidary" " = 3"
243 local_compiler_xfail_check
244 gdb_test "ptype lapidary" "type = const (unsigned short|short unsigned)( int)? \\*"
245 gdb_test "print *larceny" " = 4"
246 local_compiler_xfail_check
247 gdb_test "ptype larceny" "type = const long( int)? \\*"
248 gdb_test "print *largess" " = 5"
249 local_compiler_xfail_check
250 gdb_test "ptype largess" "type = const (unsigned long|long unsigned)( int)? \\*"
251 gdb_test "print *lascivious" " = 6"
252 local_compiler_xfail_check
254 gdb_test "ptype lascivious" "type = const float \\*"
255 gdb_test "print *lassitude" " = 7"
256 local_compiler_xfail_check
257 gdb_test "ptype lassitude" "type = const double \\*"
258 gdb_test "print *lamprey" " = 66 'B'"
259 local_compiler_xfail_check
260 gdb_test "ptype lamprey" "type = char \\* const"
261 gdb_test "print *lariat" " = 10 '\\\\n'"
262 local_compiler_xfail_check
263 gdb_test "ptype lariat" "type = unsigned char \\* const"
264 gdb_test "print *laudanum" " = 20"
265 local_compiler_xfail_check
266 gdb_test "ptype laudanum" "type = short( int)? \\* const"
267 gdb_test "print *lecithin" " = 30"
268 local_compiler_xfail_check
269 gdb_test "ptype lecithin" "type = (unsigned short|short unsigned)( int)? \\* const"
270 gdb_test "print *leviathan" " = 40"
271 local_compiler_xfail_check
272 gdb_test "ptype leviathan" "type = long( int)? \\* const"
273 gdb_test "print *libretto" " = 50"
274 local_compiler_xfail_check
275 gdb_test "ptype libretto" "type = (unsigned long|long unsigned)( int)? \\* const"
276 gdb_test "print *lissome" " = 60"
277 local_compiler_xfail_check
278 gdb_test "ptype lissome" "type = float \\* const"
279 gdb_test "print *locust" " = 70"
280 local_compiler_xfail_check
281 gdb_test "ptype locust" "type = double \\* const"
283 local_compiler_xfail_check
284 if { [test_compiler_info gcc-3-*] && [test_debug_format "stabs"] } then {
285 # With stabs, even GCC 3 does not get the constant structure member
289 gdb_test "ptype crass" "type = struct crass \{\[\r\n\]+\[\ \t\]+char \\* const ptr;\[\r\n\]+\}"
290 local_compiler_xfail_check
291 gdb_test "ptype crisp" "type = struct crisp \{\[\r\n\]+\[\ \t\]+char \\* const \\*ptr;\[\r\n\]+\}"