0f957a7fb65a784deb49f2932dccfb51bc3ff3eb
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.chill / chexp.exp
1 # Copyright (C) 1992 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., 675 Mass Ave, Cambridge, MA 02139, 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 Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 # Set the current language to chill. This counts as a test. If it
30 # fails, then we skip the other tests.
31
32 proc set_lang_chill {} {
33 global prompt
34
35 send "set language chill\n"
36 expect {
37 -re ".*$prompt $" {}
38 timeout { fail "set language chill (timeout)" ; return 0 }
39 }
40
41 send "show language\n"
42 expect {
43 -re ".* source language is \"chill\".*$prompt $" {
44 pass "set language to \"chill\""
45 return 1
46 }
47 -re ".*$prompt $" {
48 fail "setting language to \"chill\""
49 return 0
50 }
51 timeout {
52 fail "can't show language (timeout)"
53 return 0
54 }
55 }
56 }
57
58 proc test_integer_literals_accepted {} {
59 global prompt
60
61 # Test various decimal values.
62
63 gdb_test "p 123" " = 123"
64 gdb_test "p -123" " = -123"
65 gdb_test "p D'123" " = 123"
66 gdb_test "p d'123" " = 123"
67 gdb_test "p -D'123" " = -123"
68 gdb_test "p -d'123" " = -123"
69 gdb_test "p 123_456" " = 123456"
70 gdb_test "p __1_2_3__" " = 123"
71 gdb_test "p/d 123" " = D'123"
72
73 # Test various binary values.
74
75 gdb_test "p B'111" " = 7"
76 gdb_test "p b'111" " = 7"
77 gdb_test "p -B'111" " = -7"
78 gdb_test "p B'0111" " = 7"
79 gdb_test "p b'0111" " = 7"
80 gdb_test "p -b'0111" " = -7"
81 gdb_test "p B'_0_1_1_1_" " = 7"
82 gdb_test "p b'_0_1_1_1_" " = 7"
83 gdb_test "p -b'_0_1_1_1_" " = -7"
84 gdb_test "p/t B'111" " = B'111"
85
86 # Test various octal values.
87
88 gdb_test "p O'123" " = 83"
89 gdb_test "p o'123" " = 83"
90 gdb_test "p -o'0123" " = -83"
91 gdb_test "p O'0123" " = 83"
92 gdb_test "p o'0123" " = 83"
93 gdb_test "p -o'123" " = -83"
94 gdb_test "p O'_1_2_3_" " = 83"
95 gdb_test "p o'_1_2_3_" " = 83"
96 gdb_test "p -o'_1_2_3_" " = -83"
97 gdb_test "p/o O'123" " = O'123"
98
99 # Test various hexadecimal values.
100
101 gdb_test "p H'123" " = 291"
102 gdb_test "p h'123" " = 291"
103 gdb_test "p -h'123" " = -291"
104 gdb_test "p H'0123" " = 291"
105 gdb_test "p h'0123" " = 291"
106 gdb_test "p -h'0123" " = -291"
107 gdb_test "p H'_1_2_3_" " = 291"
108 gdb_test "p h'_1_2_3_" " = 291"
109 gdb_test "p -h'_1_2_3_" " = -291"
110 gdb_test "p H'ABCDEF" " = 11259375"
111 gdb_test "p H'abcdef" " = 11259375"
112 gdb_test "p H'AbCdEf" " = 11259375"
113 gdb_test "p H'_A_b_C_d_E_f_" " = 11259375"
114 gdb_test "p/x H'123" " = H'123"
115 }
116
117 proc test_character_literals_accepted {} {
118 global prompt
119
120 # Test various decimal values.
121
122 gdb_test "p 'a'" " = 'a'"
123 gdb_test "p/x 'a'" " = H'61"
124 gdb_test "p/d 'a'" " = D'97"
125 gdb_test "p/t 'a'" " = B'1100001"
126 # gdb_test "p '^(97)'" " = 'a'" (not in GNU Chill)
127 gdb_test "p C'61'" " = 'a'"
128 gdb_test "p c'61'" " = 'a'"
129 gdb_test "p/x C'FF'" " = H'ff"
130 # gdb_test "p/x '^(H'FF)'" " = H'ff" (not in GNU Chill)
131 # gdb_test "p/x '^(D'255)'" " = H'ff" (not in GNU Chill)
132 }
133
134 proc test_integer_literals_rejected {} {
135 global prompt
136
137 # These are valid integer literals in Z.200, but not GNU-Chill.
138
139 test_print_reject "p _"
140 test_print_reject "p __"
141
142 test_print_reject "p D'"
143 test_print_reject "p D'_"
144 test_print_reject "p D'__"
145
146 test_print_reject "p B'"
147 test_print_reject "p B'_"
148 test_print_reject "p B'__"
149
150 test_print_reject "p O'"
151 test_print_reject "p O'_"
152 test_print_reject "p O'__"
153
154 test_print_reject "p H'"
155 test_print_reject "p H'_"
156 test_print_reject "p H'__"
157
158 # Test various decimal values.
159
160 test_print_reject "p D'DEADBEEF"
161 test_print_reject "p D'123DEADBEEF"
162
163 # Test various binary values.
164
165 test_print_reject "p B'2"
166 test_print_reject "p B'12"
167
168 # Test various octal values.
169
170 test_print_reject "p O'9"
171 test_print_reject "p O'79"
172
173 # Test various hexadecimal values.
174
175 test_print_reject "p H'G"
176 test_print_reject "p H'AG"
177 }
178
179 proc test_boolean_literals_accepted {} {
180 global prompt
181
182 # Test the only possible values for a boolean, TRUE and FALSE.
183
184 gdb_test "p TRUE" " = TRUE"
185 gdb_test "p FALSE" " = FALSE"
186 }
187
188 proc test_float_literals_accepted {} {
189 global prompt
190
191 # Test various floating point formats
192
193 gdb_test "p .44 < .45" " = 1"
194 gdb_test "p .44 > .45" " = 0"
195 gdb_test "p 0.44 < 0.45" " = 1"
196 gdb_test "p 0.44 > 0.45" " = 0"
197 gdb_test "p 44. < 45." " = 1"
198 gdb_test "p 44. > 45." " = 0"
199 gdb_test "p 44.0 < 45.0" " = 1"
200 gdb_test "p 44.0 > 45.0" " = 0"
201 gdb_test "p 10D20 < 10D21" " = 1"
202 gdb_test "p 10D20 > 10D21" " = 0"
203 gdb_test "p 10d20 < 10d21" " = 1"
204 gdb_test "p 10d20 > 10d21" " = 0"
205 gdb_test "p 10E20 < 10E21" " = 1"
206 gdb_test "p 10E20 > 10E21" " = 0"
207 gdb_test "p 10e20 < 10e21" " = 1"
208 gdb_test "p 10e20 > 10e21" " = 0"
209 gdb_test "p 10.D20 < 10.D21" " = 1"
210 gdb_test "p 10.D20 > 10.D21" " = 0"
211 gdb_test "p 10.d20 < 10.d21" " = 1"
212 gdb_test "p 10.d20 > 10.d21" " = 0"
213 gdb_test "p 10.E20 < 10.E21" " = 1"
214 gdb_test "p 10.E20 > 10.E21" " = 0"
215 gdb_test "p 10.e20 < 10.e21" " = 1"
216 gdb_test "p 10.e20 > 10.e21" " = 0"
217 gdb_test "p 10.0D20 < 10.0D21" " = 1"
218 gdb_test "p 10.0D20 > 10.0D21" " = 0"
219 gdb_test "p 10.0d20 < 10.0d21" " = 1"
220 gdb_test "p 10.0d20 > 10.0d21" " = 0"
221 gdb_test "p 10.0E20 < 10.0E21" " = 1"
222 gdb_test "p 10.0E20 > 10.0E21" " = 0"
223 gdb_test "p 10.0e20 < 10.0e21" " = 1"
224 gdb_test "p 10.0e20 > 10.0e21" " = 0"
225 gdb_test "p 10.0D+20 < 10.0D+21" " = 1"
226 gdb_test "p 10.0D+20 > 10.0D+21" " = 0"
227 gdb_test "p 10.0d+20 < 10.0d+21" " = 1"
228 gdb_test "p 10.0d+20 > 10.0d+21" " = 0"
229 gdb_test "p 10.0E+20 < 10.0E+21" " = 1"
230 gdb_test "p 10.0E+20 > 10.0E+21" " = 0"
231 gdb_test "p 10.0e+20 < 10.0e+21" " = 1"
232 gdb_test "p 10.0e+20 > 10.0e+21" " = 0"
233 gdb_test "p 10.0D-11 < 10.0D-10" " = 1"
234 gdb_test "p 10.0D-11 > 10.0D-10" " = 0"
235 gdb_test "p 10.0d-11 < 10.0d-10" " = 1"
236 gdb_test "p 10.0d-11 > 10.0d-10" " = 0"
237 gdb_test "p 10.0E-11 < 10.0E-10" " = 1"
238 gdb_test "p 10.0E-11 > 10.0E-10" " = 0"
239 gdb_test "p 10.0e-11 < 10.0e-10" " = 1"
240 gdb_test "p 10.0e-11 > 10.0e-10" " = 0"
241 # looks funny, but apparently legal
242 gdb_test "p _.1e+10 < _.1e+11" " = 1"
243 gdb_test "p _.1e+10 > _.1e+11" " = 0"
244 gdb_test "p __.1e-12 < __.1e-11" " = 1"
245 gdb_test "p __.1e-12 > __.1e-11" " = 0"
246 }
247
248 proc test_convenience_variables {} {
249 global prompt
250
251 gdb_test "set \$foo := 101" " := 101" \
252 "Set a new convenience variable"
253
254 gdb_test "print \$foo" " = 101" \
255 "Print contents of new convenience variable"
256
257 gdb_test "set \$foo := 301" " := 301" \
258 "Set convenience variable to a new value"
259
260 gdb_test "print \$foo" " = 301" \
261 "Print new contents of convenience variable"
262
263 gdb_test "set \$_ := 11" " := 11" \
264 "Set convenience variable \$_"
265
266 gdb_test "print \$_" " = 11" \
267 "Print contents of convenience variable \$_"
268
269 gdb_test "print \$foo + 10" " = 311" \
270 "Use convenience variable in arithmetic expression"
271
272 gdb_test "print (\$foo := 32) + 4" " = 36" \
273 "Use convenience variable assignment in arithmetic expression"
274
275 gdb_test "print \$bar" " = void" \
276 "Print contents of uninitialized convenience variable"
277 }
278
279 proc test_value_history {} {
280 global prompt
281
282 gdb_test "print 101" "\\\$1 = 101" \
283 "Set value-history\[1\] using \$1"
284
285 gdb_test "print 102" "\\\$2 = 102" \
286 "Set value-history\[2\] using \$2"
287
288 gdb_test "print 103" "\\\$3 = 103" \
289 "Set value-history\[3\] using \$3"
290
291 gdb_test "print \$\$" "\\\$4 = 102" \
292 "Print value-history\[MAX-1\] using inplicit index \$\$"
293
294 gdb_test "print \$\$" "\\\$5 = 103" \
295 "Print value-history\[MAX-1\] again using implicit index \$\$"
296
297 gdb_test "print \$" "\\\$6 = 103" \
298 "Print value-history\[MAX\] using implicit index \$"
299
300 gdb_test "print \$\$2" "\\\$7 = 102" \
301 "Print value-history\[MAX-2\] using explicit index \$\$2"
302
303 gdb_test "print \$0" "\\\$8 = 102" \
304 "Print value-history\[MAX\] using explicit index \$0"
305
306 gdb_test "print 108" "\\\$9 = 108" ""
307
308 gdb_test "print \$\$0" "\\\$10 = 108" \
309 "Print value-history\[MAX\] using explicit index \$\$0"
310
311 gdb_test "print \$1" "\\\$11 = 101" \
312 "Print value-history\[1\] using explicit index \$1"
313
314 gdb_test "print \$2" "\\\$12 = 102" \
315 "Print value-history\[2\] using explicit index \$2"
316
317 gdb_test "print \$3" "\\\$13 = 103" \
318 "Print value-history\[3\] using explicit index \$3"
319
320 gdb_test "print \$-3" "\\\$14 = 100" \
321 "Print (value-history\[MAX\] - 3) using implicit index \$"
322
323 gdb_test "print \$1 + 3" "\\\$15 = 104" \
324 "Use value-history element in arithmetic expression"
325 }
326
327 proc test_arithmetic_expressions {} {
328 global prompt
329
330 # Test unary minus with various operands
331
332 # gdb_test "p -(TRUE)" " = -1" "unary minus applied to bool"
333 # gdb_test "p -('a')" " = xxx" "unary minus applied to char"
334 gdb_test "p -(1)" " = -1" "unary minus applied to int"
335 gdb_test "p -(1.0)" " = -1" "unary minus applied to real"
336
337 # Test addition with various operands
338
339 gdb_test "p TRUE + 1" " = 2" "bool plus int"
340 gdb_test "p 'a' + 1" " = 98" "char plus int"
341 gdb_test "p 1 + 1" " = 2" "int plus int"
342 gdb_test "p 1.0 + 1" " = 2" "real plus int"
343 gdb_test "p 1.0 + 2.0" " = 3" "real plus real"
344
345 # Test subtraction with various operands
346
347 gdb_test "p TRUE - 1" " = 0" "bool minus int"
348 gdb_test "p 'b' - 1" " = 97" "char minus int"
349 gdb_test "p 3 - 1" " = 2" "int minus int"
350 gdb_test "p 3.0 - 1" " = 2" "real minus int"
351 gdb_test "p 5.0 - 2.0" " = 3" "real minus real"
352
353 # Test multiplication with various operands
354
355 gdb_test "p TRUE * 1" " = 1" "bool times int"
356 gdb_test "p 'a' * 2" " = 194" "char times int"
357 gdb_test "p 2 * 3" " = 6" "int times int"
358 gdb_test "p 2.0 * 3" " = 6" "real times int"
359 gdb_test "p 2.0 * 3.0" " = 6" "real times real"
360
361 # Test division with various operands
362
363 gdb_test "p TRUE / 1" " = 1" "bool divided by int"
364 gdb_test "p 'a' / 2" " = 48" "char divided by int"
365 gdb_test "p 6 / 3" " = 2" "int divided by int"
366 gdb_test "p 6.0 / 3" " = 2" "real divided by int"
367 gdb_test "p 6.0 / 3.0" " = 2" "real divided by real"
368
369 # Test modulo with various operands
370
371 gdb_test "p TRUE MOD 1" " = 0" "bool modulo int"
372 gdb_test "p 'a' MOD 2" " = 1" "char modulo int"
373 gdb_test "p -5 MOD 3" " = 1" "negative int modulo int"
374 gdb_test "p 5 MOD 1" " = 0" "int modulo int"
375 gdb_test "p 5 MOD 2" " = 1" "int modulo int"
376 gdb_test "p 5 MOD 3" " = 2" "int modulo int"
377 gdb_test "p 5 MOD 4" " = 1" "int modulo int"
378 gdb_test "p 5 MOD 5" " = 0" "int modulo int"
379 gdb_test "p 0 MOD 1" " = 0" "int modulo int"
380 gdb_test "p 0 MOD 2" " = 0" "int modulo int"
381 gdb_test "p 0 MOD 3" " = 0" "int modulo int"
382 gdb_test "p 0 MOD 4" " = 0" "int modulo int"
383 gdb_test "p -5 MOD 1" " = 0" "int modulo int"
384 gdb_test "p -5 MOD 2" " = 1" "int modulo int"
385 gdb_test "p -5 MOD 3" " = 1" "int modulo int"
386 gdb_test "p -5 MOD 4" " = 3" "int modulo int"
387 gdb_test "p -5 MOD 5" " = 0" "int modulo int"
388 gdb_test "p -5 MOD 5" " = 0" "int modulo int"
389 test_print_reject "p 6.0 MOD 3" \
390 "Integer-only operation on floating point number.*"
391 test_print_reject "p 6.0 MOD 3.0" \
392 "Integer-only operation on floating point number.*"
393 test_print_reject "p -5 MOD -1" \
394 "Second operand of MOD must be greater than zero.*"
395 test_print_reject "p -5 MOD 0" \
396 "Second operand of MOD must be greater than zero.*"
397
398 # Test remainder with various operands
399
400 gdb_test "p TRUE REM 1" " = 0" "bool remainder int"
401 gdb_test "p 'a' REM 2" " = 1" "char remainder int"
402 gdb_test "p 5 REM 5" " = 0" "int remainder int"
403 gdb_test "p 5 REM 4" " = 1" "int remainder int"
404 gdb_test "p 5 REM 3" " = 2" "int remainder int"
405 gdb_test "p 5 REM 2" " = 1" "int remainder int"
406 gdb_test "p 5 REM 1" " = 0" "int remainder int"
407 gdb_test "p 5 REM -1" " = 0" "int remainder int"
408 gdb_test "p 5 REM -2" " = 1" "int remainder int"
409 gdb_test "p 5 REM -3" " = 2" "int remainder int"
410 gdb_test "p 5 REM -4" " = 1" "int remainder int"
411 gdb_test "p 5 REM -5" " = 0" "int remainder int"
412 gdb_test "p -5 REM 5" " = 0" "int remainder int"
413 gdb_test "p -5 REM 4" " = -1" "int remainder int"
414 gdb_test "p -5 REM 3" " = -2" "int remainder int"
415 gdb_test "p -5 REM 2" " = -1" "int remainder int"
416 gdb_test "p -5 REM 1" " = 0" "int remainder int"
417 gdb_test "p -5 REM -1" " = 0" "int remainder int"
418 gdb_test "p -5 REM -2" " = -1" "int remainder int"
419 gdb_test "p -5 REM -3" " = -2" "int remainder int"
420 gdb_test "p -5 REM -4" " = -1" "int remainder int"
421 gdb_test "p -5 REM -5" " = 0" "int remainder int"
422 gdb_test "p 6 REM 3" " = 0" "int remainder int"
423 test_print_reject "p 6.0 REM 3" \
424 "Integer-only operation on floating point number.*"
425 test_print_reject "p 6.0 REM 3.0" \
426 "Integer-only operation on floating point number.*"
427 }
428
429 # Start with a fresh gdb.
430
431 gdb_exit
432 gdb_start
433 gdb_reinitialize_dir $srcdir/$subdir
434
435 send "set print sevenbit-strings\n" ; expect -re ".*$prompt $"
436
437 if [set_lang_chill] then {
438 test_value_history
439 test_convenience_variables
440 test_integer_literals_accepted
441 test_integer_literals_rejected
442 test_boolean_literals_accepted
443 test_character_literals_accepted
444 test_float_literals_accepted
445 test_arithmetic_expressions
446 } else {
447 warning "$test_name tests suppressed."
448 }
This page took 0.045503 seconds and 3 git commands to generate.