aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.chill/chexp.exp
blob: 516582c9da4102083471465767f53d67bb39246a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# Copyright (C) 1992 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# This file was written by Fred Fish. (fnf@cygnus.com)

if $tracelevel then {
	strace $tracelevel
}

set prms_id 0
set bug_id 0

# Set the current language to chill.  This counts as a test.  If it
# fails, then we skip the other tests.

proc set_lang_chill {} {
    global prompt

    send "set language chill\n"
    expect {
	-re ".*$prompt $" {}
	timeout { fail "set language chill (timeout)" ; return 0 }
    }

    send "show language\n"
    expect {
	-re ".* source language is \"chill\".*$prompt $" {
	    pass "set language to \"chill\""
	    return 1
	}
	-re ".*$prompt $" {
	    fail "setting language to \"chill\""
	    return 0
	}
	timeout {
	    fail "can't show language (timeout)"
	    return 0
	}
    }
}

# Testing printing of a specific value.  Increment passcount for
# success or issue fail message for failure.  In both cases, return
# a 1 to indicate that more tests can proceed.  However a timeout
# is a serious error, generates a special fail message, and causes
# a 0 to be returned to indicate that more tests are likely to fail
# as well.
#
# Args are:
#
#	First one is string to send to gdb
#	Second one is string to match gdb result to
#	Third one is an optional message to be printed

proc test_print_accept { args } {
    global prompt
    global passcount
    global verbose

    if [llength $args]==3 then {
	set message [lindex $args 2]
    } else {
	set message [lindex $args 0]
    }
    set sendthis [lindex $args 0]
    set expectthis [lindex $args 1]
    if $verbose>2 then {
	send_user "Sending \"$sendthis\" to gdb\n"
	send_user "Looking to match \"$expectthis\"\n"
	send_user "Message is \"$message\"\n"
    }
    send "$sendthis\n"
    expect {
	-re ".* = $expectthis\r\n$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$prompt $" {
	    if ![string match "" $message] then {
		fail "$sendthis ($message)"
	    } else {
		fail "$sendthis"
	    }
	    return 1
	}
	timeout {
	    fail "$sendthis (timeout)"
	    return 0
	}
    }
}

proc test_integer_literals_accepted {} {
    global prompt
    global passcount

    set passcount 0

    # Test various decimal values.

    test_print_accept "p 123" "123"
    test_print_accept "p -123" "-123"
    test_print_accept "p D'123" "123"
    test_print_accept "p d'123" "123"
    test_print_accept "p -D'123" "-123"
    test_print_accept "p -d'123" "-123"
    test_print_accept "p 123_456" "123456"
    test_print_accept "p __1_2_3__" "123"
    test_print_accept "p/d 123" "D'123"

    # Test various binary values.

    test_print_accept "p B'111" "7"
    test_print_accept "p b'111" "7"
    test_print_accept "p -B'111" "-7"
    test_print_accept "p B'0111" "7"
    test_print_accept "p b'0111" "7"
    test_print_accept "p -b'0111" "-7"
    test_print_accept "p B'_0_1_1_1_" "7"
    test_print_accept "p b'_0_1_1_1_" "7"
    test_print_accept "p -b'_0_1_1_1_" "-7"
    test_print_accept "p/t B'111" "B'111"

    # Test various octal values.

    test_print_accept "p O'123" "83"
    test_print_accept "p o'123" "83"
    test_print_accept "p -o'0123" "-83"
    test_print_accept "p O'0123" "83"
    test_print_accept "p o'0123" "83"
    test_print_accept "p -o'123" "-83"
    test_print_accept "p O'_1_2_3_" "83"
    test_print_accept "p o'_1_2_3_" "83"
    test_print_accept "p -o'_1_2_3_" "-83"
    test_print_accept "p/o O'123" "O'123"

    # Test various hexadecimal values.

    test_print_accept "p H'123" "291"
    test_print_accept "p h'123" "291"
    test_print_accept "p -h'123" "-291"
    test_print_accept "p H'0123" "291"
    test_print_accept "p h'0123" "291"
    test_print_accept "p -h'0123" "-291"
    test_print_accept "p H'_1_2_3_" "291"
    test_print_accept "p h'_1_2_3_" "291"
    test_print_accept "p -h'_1_2_3_" "-291"
    test_print_accept "p H'ABCDEF" "11259375"
    test_print_accept "p H'abcdef" "11259375"
    test_print_accept "p H'AbCdEf" "11259375"
    test_print_accept "p H'_A_b_C_d_E_f_" "11259375"
    test_print_accept "p/x H'123" "H'123"

    if $passcount then {
	pass "$passcount correct integer literals printed"
    }
}

proc test_character_literals_accepted {} {
    global prompt
    global passcount

    set passcount 0

    # Test various decimal values.

    test_print_accept "p 'a'" "'a'"
    test_print_accept "p/x 'a'" "H'61"
    test_print_accept "p/d 'a'" "D'97"
    test_print_accept "p/t 'a'" "B'1100001"
    # test_print_accept "p '^(97)'" "'a'"	(not in GNU Chill)
    test_print_accept "p C'61'" "'a'"
    test_print_accept "p c'61'" "'a'"
    test_print_accept "p/x C'FF'" "H'ff"
    # test_print_accept "p/x '^(H'FF)'" "H'ff"	(not in GNU Chill)
    # test_print_accept "p/x '^(D'255)'" "H'ff"	(not in GNU Chill)

    if $passcount then {
	pass "$passcount correct character literals printed"
    }
}

# Testing printing of a specific value.  Increment passcount for
# success or issue fail message for failure.  In both cases, return
# a 1 to indicate that more tests can proceed.  However a timeout
# is a serious error, generates a special fail message, and causes
# a 0 to be returned to indicate that more tests are likely to fail
# as well.

proc test_print_reject { args } {
    global prompt
    global passcount
    global verbose

    if [llength $args]==2 then {
	set expectthis [lindex $args 1]
    } else {
	set expectthis "should never match this bogus string"
    }
    set sendthis [lindex $args 0]
    if $verbose>2 then {
	send_user "Sending \"$sendthis\" to gdb\n"
	send_user "Looking to match \"$expectthis\"\n"
    }
    send "$sendthis\n"
    expect {
	-re ".*Invalid syntax in expression.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*Junk after end of expression.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*No symbol table is loaded.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$expectthis.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$prompt $" {
	    fail "$sendthis not properly rejected"
	    return 1
	}
	timeout {
	    fail "$sendthis (timeout)"
	    return 0
	}
    }
}

proc test_integer_literals_rejected {} {
    global prompt
    global passcount

    set passcount 0

    # These are valid integer literals in Z.200, but not GNU-Chill.

    test_print_reject "p _"
    test_print_reject "p __"

    test_print_reject "p D'" 
    test_print_reject "p D'_" 
    test_print_reject "p D'__" 

    test_print_reject "p B'" 
    test_print_reject "p B'_" 
    test_print_reject "p B'__" 

    test_print_reject "p O'" 
    test_print_reject "p O'_" 
    test_print_reject "p O'__" 

    test_print_reject "p H'" 
    test_print_reject "p H'_" 
    test_print_reject "p H'__" 

    # Test various decimal values.

    test_print_reject "p D'DEADBEEF"
    test_print_reject "p D'123DEADBEEF"

    # Test various binary values.

    test_print_reject "p B'2" 
    test_print_reject "p B'12" 

    # Test various octal values.

    test_print_reject "p O'9" 
    test_print_reject "p O'79" 

    # Test various hexadecimal values.

    test_print_reject "p H'G" 
    test_print_reject "p H'AG" 

    if $passcount then {
	pass "$passcount incorrect integer literals rejected"
    }
}

proc test_boolean_literals_accepted {} {
    global prompt
    global passcount

    set passcount 0

    # Test the only possible values for a boolean, TRUE and FALSE.

    test_print_accept "p TRUE" "TRUE"
    test_print_accept "p FALSE" "FALSE"

    if $passcount then {
	pass "$passcount correct boolean literals printed"
    }
}

proc test_float_literals_accepted {} {
    global prompt
    global passcount

    set passcount 0

    # Test various floating point formats

    test_print_accept "p .44 < .45" "1"
    test_print_accept "p .44 > .45" "0"
    test_print_accept "p 0.44 < 0.45" "1"
    test_print_accept "p 0.44 > 0.45" "0"
    test_print_accept "p 44. < 45." "1"
    test_print_accept "p 44. > 45." "0"
    test_print_accept "p 44.0 < 45.0" "1"
    test_print_accept "p 44.0 > 45.0" "0"
    test_print_accept "p 10D20 < 10D21" "1"
    test_print_accept "p 10D20 > 10D21" "0"
    test_print_accept "p 10d20 < 10d21" "1"
    test_print_accept "p 10d20 > 10d21" "0"
    test_print_accept "p 10E20 < 10E21" "1"
    test_print_accept "p 10E20 > 10E21" "0"
    test_print_accept "p 10e20 < 10e21" "1"
    test_print_accept "p 10e20 > 10e21" "0"
    test_print_accept "p 10.D20 < 10.D21" "1"
    test_print_accept "p 10.D20 > 10.D21" "0"
    test_print_accept "p 10.d20 < 10.d21" "1"
    test_print_accept "p 10.d20 > 10.d21" "0"
    test_print_accept "p 10.E20 < 10.E21" "1"
    test_print_accept "p 10.E20 > 10.E21" "0"
    test_print_accept "p 10.e20 < 10.e21" "1"
    test_print_accept "p 10.e20 > 10.e21" "0"
    test_print_accept "p 10.0D20 < 10.0D21" "1"
    test_print_accept "p 10.0D20 > 10.0D21" "0"
    test_print_accept "p 10.0d20 < 10.0d21" "1"
    test_print_accept "p 10.0d20 > 10.0d21" "0"
    test_print_accept "p 10.0E20 < 10.0E21" "1"
    test_print_accept "p 10.0E20 > 10.0E21" "0"
    test_print_accept "p 10.0e20 < 10.0e21" "1"
    test_print_accept "p 10.0e20 > 10.0e21" "0"
    test_print_accept "p 10.0D+20 < 10.0D+21" "1"
    test_print_accept "p 10.0D+20 > 10.0D+21" "0"
    test_print_accept "p 10.0d+20 < 10.0d+21" "1"
    test_print_accept "p 10.0d+20 > 10.0d+21" "0"
    test_print_accept "p 10.0E+20 < 10.0E+21" "1"
    test_print_accept "p 10.0E+20 > 10.0E+21" "0"
    test_print_accept "p 10.0e+20 < 10.0e+21" "1"
    test_print_accept "p 10.0e+20 > 10.0e+21" "0"
    test_print_accept "p 10.0D-11 < 10.0D-10" "1"
    test_print_accept "p 10.0D-11 > 10.0D-10" "0"
    test_print_accept "p 10.0d-11 < 10.0d-10" "1"
    test_print_accept "p 10.0d-11 > 10.0d-10" "0"
    test_print_accept "p 10.0E-11 < 10.0E-10" "1"
    test_print_accept "p 10.0E-11 > 10.0E-10" "0"
    test_print_accept "p 10.0e-11 < 10.0e-10" "1"
    test_print_accept "p 10.0e-11 > 10.0e-10" "0"
    # looks funny, but apparently legal
    test_print_accept "p _.1e+10 < _.1e+11" "1"
    test_print_accept "p _.1e+10 > _.1e+11" "0"
    test_print_accept "p __.1e-12 < __.1e-11" "1"
    test_print_accept "p __.1e-12 > __.1e-11" "0"

    if $passcount then {
	pass "$passcount correct float literal comparisons"
    }
}

proc test_convenience_variables {} {
    global prompt

    gdb_test "set \\\$foo := 101"	" := 101" \
	"Set a new convenience variable"

    gdb_test "print \\\$foo"		" = 101" \
	"Print contents of new convenience variable"

    gdb_test "set \\\$foo := 301"	" := 301" \
	"Set convenience variable to a new value"

    gdb_test "print \\\$foo"		" = 301" \
	"Print new contents of convenience variable"

    gdb_test "set \\\$_ := 11"		" := 11" \
	"Set convenience variable \$_"

    gdb_test "print \\\$_"		" = 11" \
	"Print contents of convenience variable \$_"

    gdb_test "print \\\$foo + 10"	" = 311" \
	"Use convenience variable in arithmetic expression"

    gdb_test "print (\\\$foo := 32) + 4"	" = 36" \
	"Use convenience variable assignment in arithmetic expression"

    gdb_test "print \\\$bar"		" = void" \
	"Print contents of uninitialized convenience variable"
}

proc test_value_history {} {
    global prompt

    gdb_test "print 101"	"\\\$1 = 101" \
	"Set value-history\[1\] using \$1"

    gdb_test "print 102" 	"\\\$2 = 102" \
	"Set value-history\[2\] using \$2"

    gdb_test "print 103"	"\\\$3 = 103" \
	"Set value-history\[3\] using \$3"

    gdb_test "print \\\$\\\$"	"\\\$4 = 102" \
	"Print value-history\[MAX-1\] using inplicit index \$\$"

    gdb_test "print \\\$\\\$"	"\\\$5 = 103" \
	"Print value-history\[MAX-1\] again using implicit index \$\$"

    gdb_test "print \\\$"	"\\\$6 = 103" \
	"Print value-history\[MAX\] using implicit index \$"

    gdb_test "print \\\$\\\$2"	"\\\$7 = 102" \
	"Print value-history\[MAX-2\] using explicit index \$\$2"

    gdb_test "print \\\$0"	"\\\$8 = 102" \
	"Print value-history\[MAX\] using explicit index \$0"

    gdb_test "print 108"	"\\\$9 = 108" ""

    gdb_test "print \\\$\\\$0"	"\\\$10 = 108" \
	"Print value-history\[MAX\] using explicit index \$\$0"

    gdb_test "print \\\$1"	"\\\$11 = 101" \
	"Print value-history\[1\] using explicit index \$1"

    gdb_test "print \\\$2"	"\\\$12 = 102" \
	"Print value-history\[2\] using explicit index \$2"

    gdb_test "print \\\$3"	"\\\$13 = 103" \
	"Print value-history\[3\] using explicit index \$3"

    gdb_test "print \\\$-3"	"\\\$14 = 100" \
	"Print (value-history\[MAX\] - 3) using implicit index \$"

    gdb_test "print \\\$1 + 3"	"\\\$15 = 104" \
	"Use value-history element in arithmetic expression"
}

proc test_arithmetic_expressions {} {
    global prompt
    global passcount

    set passcount 0

    # Test unary minus with various operands

#    test_print_accept "p -(TRUE)"	"-1"	"unary minus applied to bool"
#    test_print_accept "p -('a')"	"xxx"	"unary minus applied to char"
    test_print_accept "p -(1)"		"-1"	"unary minus applied to int"
    test_print_accept "p -(1.0)"	"-1"	"unary minus applied to real"

    # Test addition with various operands

    test_print_accept "p TRUE + 1"	"2"	"bool plus int"
    test_print_accept "p 'a' + 1"	"98"	"char plus int"
    test_print_accept "p 1 + 1"		"2"	"int plus int"
    test_print_accept "p 1.0 + 1"	"2"	"real plus int"
    test_print_accept "p 1.0 + 2.0"	"3"	"real plus real"

    # Test subtraction with various operands

    test_print_accept "p TRUE - 1"	"0"	"bool minus int"
    test_print_accept "p 'b' - 1"	"97"	"char minus int"
    test_print_accept "p 3 - 1"		"2"	"int minus int"
    test_print_accept "p 3.0 - 1"	"2"	"real minus int"
    test_print_accept "p 5.0 - 2.0"	"3"	"real minus real"

    # Test multiplication with various operands

    test_print_accept "p TRUE * 1"	"1"	"bool times int"
    test_print_accept "p 'a' * 2"	"194"	"char times int"
    test_print_accept "p 2 * 3"		"6"	"int times int"
    test_print_accept "p 2.0 * 3"	"6"	"real times int"
    test_print_accept "p 2.0 * 3.0"	"6"	"real times real"

    # Test division with various operands

    test_print_accept "p TRUE / 1"	"1"	"bool divided by int"
    test_print_accept "p 'a' / 2"	"48"	"char divided by int"
    test_print_accept "p 6 / 3"		"2"	"int divided by int"
    test_print_accept "p 6.0 / 3"	"2"	"real divided by int"
    test_print_accept "p 6.0 / 3.0"	"2"	"real divided by real"

    # Test modulo with various operands

    test_print_accept "p TRUE MOD 1"	"0"	"bool modulo int"
    test_print_accept "p 'a' MOD 2"	"1"	"char modulo int"
    test_print_accept "p -5 MOD 3"	"1"	"negative int modulo int"
    test_print_accept "p 5 MOD 1"	"0"	"int modulo int"
    test_print_accept "p 5 MOD 2"	"1"	"int modulo int"
    test_print_accept "p 5 MOD 3"	"2"	"int modulo int"
    test_print_accept "p 5 MOD 4"	"1"	"int modulo int"
    test_print_accept "p 5 MOD 5"	"0"	"int modulo int"
    test_print_accept "p 0 MOD 1"	"0"	"int modulo int"
    test_print_accept "p 0 MOD 2"	"0"	"int modulo int"
    test_print_accept "p 0 MOD 3"	"0"	"int modulo int"
    test_print_accept "p 0 MOD 4"	"0"	"int modulo int"
    test_print_accept "p -5 MOD 1"	"0"	"int modulo int"
    test_print_accept "p -5 MOD 2"	"1"	"int modulo int"
    test_print_accept "p -5 MOD 3"	"1"	"int modulo int"
    test_print_accept "p -5 MOD 4"	"3"	"int modulo int"
    test_print_accept "p -5 MOD 5"	"0"	"int modulo int"
    test_print_accept "p -5 MOD 5"	"0"	"int modulo int"
    test_print_reject "p 6.0 MOD 3" \
	"Integer-only operation on floating point number.*"
    test_print_reject "p 6.0 MOD 3.0" \
	"Integer-only operation on floating point number.*"
    test_print_reject "p -5 MOD -1" \
	"Second operand of MOD must be greater than zero.*"
    test_print_reject "p -5 MOD 0" \
	"Second operand of MOD must be greater than zero.*"

    # Test remainder with various operands

    test_print_accept "p TRUE REM 1"	"0"	"bool remainder int"
    test_print_accept "p 'a' REM 2"	"1"	"char remainder int"
    test_print_accept "p 5 REM 5"	"0"	"int remainder int"
    test_print_accept "p 5 REM 4"	"1"	"int remainder int"
    test_print_accept "p 5 REM 3"	"2"	"int remainder int"
    test_print_accept "p 5 REM 2"	"1"	"int remainder int"
    test_print_accept "p 5 REM 1"	"0"	"int remainder int"
    test_print_accept "p 5 REM -1"	"0"	"int remainder int"
    test_print_accept "p 5 REM -2"	"1"	"int remainder int"
    test_print_accept "p 5 REM -3"	"2"	"int remainder int"
    test_print_accept "p 5 REM -4"	"1"	"int remainder int"
    test_print_accept "p 5 REM -5"	"0"	"int remainder int"
    test_print_accept "p -5 REM 5"	"0"	"int remainder int"
    test_print_accept "p -5 REM 4"	"-1"	"int remainder int"
    test_print_accept "p -5 REM 3"	"-2"	"int remainder int"
    test_print_accept "p -5 REM 2"	"-1"	"int remainder int"
    test_print_accept "p -5 REM 1"	"0"	"int remainder int"
    test_print_accept "p -5 REM -1"	"0"	"int remainder int"
    test_print_accept "p -5 REM -2"	"-1"	"int remainder int"
    test_print_accept "p -5 REM -3"	"-2"	"int remainder int"
    test_print_accept "p -5 REM -4"	"-1"	"int remainder int"
    test_print_accept "p -5 REM -5"	"0"	"int remainder int"
    test_print_accept "p 6 REM 3"	"0"	"int remainder int"
    test_print_reject "p 6.0 REM 3" \
	"Integer-only operation on floating point number.*"
    test_print_reject "p 6.0 REM 3.0" \
	"Integer-only operation on floating point number.*"

    if $passcount then {
	pass "$passcount correct arithmetic expressions"
    }
}

# Start with a fresh gdb.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

send "set print sevenbit-strings\n" ; expect -re ".*$prompt $"

if [set_lang_chill] then {
    test_value_history
    test_convenience_variables
    test_integer_literals_accepted
    test_integer_literals_rejected
    test_boolean_literals_accepted
    test_character_literals_accepted
    test_float_literals_accepted
    test_arithmetic_expressions
} else {
    warning "$test_name tests suppressed."
}