]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/logical.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / logical.exp
1 # Copyright (C) 1998 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 file is part of the gdb testsuite
23
24 #
25 # tests for correctenss of logical operators, associativity and precedence
26 # with integer type variables
27 #
28
29 if $tracelevel then {
30 strace $tracelevel
31 }
32
33 #
34 # test running programs
35 #
36 set prms_id 0
37 set bug_id 0
38
39 set testfile "int-type"
40 set srcfile ${testfile}.c
41 set binfile ${objdir}/${subdir}/${testfile}
42
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
44 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 }
46
47
48
49 gdb_exit
50 gdb_start
51 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_load ${binfile}
53
54
55 #
56 # set it up at a breakpoint so we can play with the variable values
57 #
58
59 if ![runto_main] then {
60 perror "couldn't run to breakpoint"
61 continue
62 }
63
64 #
65 # test expressions with "int" types
66 #
67
68 gdb_test "set variable x=0" "" "set variable x=0"
69 gdb_test "set variable y=0" "" "set variable y=0"
70 gdb_test "set variable z=0" "" "set variable z=0"
71
72 send_gdb "print x\n"
73 gdb_expect {
74 -re ".*0.*$gdb_prompt $" {
75 pass "print value of x"
76 }
77 -re ".*$gdb_prompt $" { fail "print value of x" }
78 timeout { fail "(timeout) print value of x" }
79 }
80
81
82 send_gdb "print y\n"
83 gdb_expect {
84 -re ".*0.*$gdb_prompt $" {
85 pass "print value of y"
86 }
87 -re ".*$gdb_prompt $" { fail "print value of y" }
88 timeout { fail "(timeout) print value of y" }
89 }
90
91 send_gdb "print z\n"
92 gdb_expect {
93 -re ".*0.*$gdb_prompt $" {
94 pass "print value of z"
95 }
96 -re ".*$gdb_prompt $" { fail "print value of z" }
97 timeout { fail "(timeout) print value of z" }
98 }
99
100
101 # truth tables for && , || , !
102
103 send_gdb "print x && y\n"
104 gdb_expect {
105 -re ".*0.*$gdb_prompt $" {
106 pass "print value of x<y"
107 }
108 -re ".*$gdb_prompt $" { fail "print value of x<y" }
109 timeout { fail "(timeout) print value of x<y" }
110 }
111
112
113
114 send_gdb "print x || y\n"
115 gdb_expect {
116 -re ".*0.*$gdb_prompt $" {
117 pass "print value of x<=y"
118 }
119 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
120 timeout { fail "(timeout) print value of x<=y" }
121 }
122
123 send_gdb "print !x\n"
124 gdb_expect {
125 -re ".*1.*$gdb_prompt $" {
126 pass "print value of x>y"
127 }
128 -re ".*$gdb_prompt $" { fail "print value of x>y" }
129 timeout { fail "(timeout) print value of x>y" }
130 }
131
132 gdb_test "set variable y=1" "" "set variable y=1"
133
134 send_gdb "print x && y\n"
135 gdb_expect {
136 -re ".*0.*$gdb_prompt $" {
137 pass "print value of x<y"
138 }
139 -re ".*$gdb_prompt $" { fail "print value of x<y" }
140 timeout { fail "(timeout) print value of x<y" }
141 }
142
143
144
145 send_gdb "print x || y\n"
146 gdb_expect {
147 -re ".*1.*$gdb_prompt $" {
148 pass "print value of x<=y"
149 }
150 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
151 timeout { fail "(timeout) print value of x<=y" }
152 }
153
154 gdb_test "set variable x=1" "" "set variable x=1"
155
156 send_gdb "print x && y\n"
157 gdb_expect {
158 -re ".*1.*$gdb_prompt $" {
159 pass "print value of x<y"
160 }
161 -re ".*$gdb_prompt $" { fail "print value of x<y" }
162 timeout { fail "(timeout) print value of x<y" }
163 }
164
165
166
167 send_gdb "print x || y\n"
168 gdb_expect {
169 -re ".*1.*$gdb_prompt $" {
170 pass "print value of x<=y"
171 }
172 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
173 timeout { fail "(timeout) print value of x<=y" }
174 }
175
176 send_gdb "print !x\n"
177 gdb_expect {
178 -re ".*0.*$gdb_prompt $" {
179 pass "print value of x>y"
180 }
181 -re ".*$gdb_prompt $" { fail "print value of x>y" }
182 timeout { fail "(timeout) print value of x>y" }
183 }
184
185 gdb_test "set variable y=0" "" "set variable y=0"
186
187 send_gdb "print x && y\n"
188 gdb_expect {
189 -re ".*0.*$gdb_prompt $" {
190 pass "print value of x<y"
191 }
192 -re ".*$gdb_prompt $" { fail "print value of x<y" }
193 timeout { fail "(timeout) print value of x<y" }
194 }
195
196
197
198 send_gdb "print x || y\n"
199 gdb_expect {
200 -re ".*1.*$gdb_prompt $" {
201 pass "print value of x<=y"
202 }
203 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
204 timeout { fail "(timeout) print value of x<=y" }
205 }
206
207
208 # end truth tables for &&, ||, !
209
210
211 # test associativity of && , || , !
212
213 gdb_test "set variable x=0" "" "set variable x=0"
214 gdb_test "set variable y=0" "" "set variable y=0"
215 gdb_test "set variable z=0" "" "set variable z=0"
216
217 send_gdb "print x && y && z\n"
218 gdb_expect {
219 -re ".*0.*$gdb_prompt $" {
220 pass "print value of x && y && z (000)"
221 }
222 -re ".*$gdb_prompt $" { fail "print value of x && y && z (000) " }
223 timeout { fail "(timeout) print value of x && y && z (000) " }
224 }
225
226 send_gdb "print x || y || z\n"
227 gdb_expect {
228 -re ".*0.*$gdb_prompt $" {
229 pass "print value of x || y || z (000)"
230 }
231 -re ".*$gdb_prompt $" { fail "print value of x || y || z (000)" }
232 timeout { fail "(timeout) print value of x || y || z (000) " }
233 }
234
235 send_gdb "print !!x\n"
236 gdb_expect {
237 -re ".*0.*$gdb_prompt $" {
238 pass "print value of !!x (0)"
239 }
240 -re ".*$gdb_prompt $" { fail "print value of !!x (0)" }
241 timeout { fail "(timeout) print value of !!x (0) " }
242 }
243
244
245 gdb_test "set variable y=1" "" "set variable y=1"
246
247 send_gdb "print x && y && z\n"
248 gdb_expect {
249 -re ".*0.*$gdb_prompt $" {
250 pass "print value of x && y && z (010)"
251 }
252 -re ".*$gdb_prompt $" { fail "print value of x && y && z (010) " }
253 timeout { fail "(timeout) print value of x && y && z (010) " }
254 }
255
256 send_gdb "print x || y || z\n"
257 gdb_expect {
258 -re ".*1.*$gdb_prompt $" {
259 pass "print value of x || y || z (010)"
260 }
261 -re ".*$gdb_prompt $" { fail "print value of x || y || z (010)" }
262 timeout { fail "(timeout) print value of x || y || z (010) " }
263 }
264
265
266 gdb_test "set variable z=1" "" "set variable z=1"
267
268 send_gdb "print x && y && z\n"
269 gdb_expect {
270 -re ".*0.*$gdb_prompt $" {
271 pass "print value of x && y && z (011)"
272 }
273 -re ".*$gdb_prompt $" { fail "print value of x && y && z (011) " }
274 timeout { fail "(timeout) print value of x && y && z (011) " }
275 }
276
277 send_gdb "print x || y || z\n"
278 gdb_expect {
279 -re ".*1.*$gdb_prompt $" {
280 pass "print value of x || y || z (011)"
281 }
282 -re ".*$gdb_prompt $" { fail "print value of x || y || z (011)" }
283 timeout { fail "(timeout) print value of x || y || z (011) " }
284 }
285
286
287 gdb_test "set variable x=1" "" "set variable x=1"
288
289 send_gdb "print x && y && z\n"
290 gdb_expect {
291 -re ".*1.*$gdb_prompt $" {
292 pass "print value of x && y && z (111)"
293 }
294 -re ".*$gdb_prompt $" { fail "print value of x && y && z (111) " }
295 timeout { fail "(timeout) print value of x && y && z (111) " }
296 }
297
298 send_gdb "print x || y || z\n"
299 gdb_expect {
300 -re ".*1.*$gdb_prompt $" {
301 pass "print value of x || y || z (111)"
302 }
303 -re ".*$gdb_prompt $" { fail "print value of x || y || z (111)" }
304 timeout { fail "(timeout) print value of x || y || z (111) " }
305 }
306
307 send_gdb "print !!x\n"
308 gdb_expect {
309 -re ".*1.*$gdb_prompt $" {
310 pass "print value of !!x (1)"
311 }
312 -re ".*$gdb_prompt $" { fail "print value of !!x (1)" }
313 timeout { fail "(timeout) print value of !!x (1) " }
314 }
315
316
317 gdb_test "set variable z=0" "" "set variable z=0"
318
319 send_gdb "print x && y && z\n"
320 gdb_expect {
321 -re ".*0.*$gdb_prompt $" {
322 pass "print value of x && y && z (110)"
323 }
324 -re ".*$gdb_prompt $" { fail "print value of x && y && z (110) " }
325 timeout { fail "(timeout) print value of x && y && z (110) " }
326 }
327
328 send_gdb "print x || y || z\n"
329 gdb_expect {
330 -re ".*1.*$gdb_prompt $" {
331 pass "print value of x || y || z (110)"
332 }
333 -re ".*$gdb_prompt $" { fail "print value of x || y || z (110)" }
334 timeout { fail "(timeout) print value of x || y || z (110) " }
335 }
336
337
338
339
340 gdb_test "set variable y=0" "" "set variable y=0"
341
342 send_gdb "print x && y && z\n"
343 gdb_expect {
344 -re ".*0.*$gdb_prompt $" {
345 pass "print value of x && y && z (100)"
346 }
347 -re ".*$gdb_prompt $" { fail "print value of x && y && z (100) " }
348 timeout { fail "(timeout) print value of x && y && z (100) " }
349 }
350
351 send_gdb "print x || y || z\n"
352 gdb_expect {
353 -re ".*1.*$gdb_prompt $" {
354 pass "print value of x || y || z (100)"
355 }
356 -re ".*$gdb_prompt $" { fail "print value of x || y || z (100)" }
357 timeout { fail "(timeout) print value of x || y || z (100) " }
358 }
359
360
361
362
363 gdb_test "set variable z=1" "" "set variable z=1"
364
365 send_gdb "print x && y && z\n"
366 gdb_expect {
367 -re ".*0.*$gdb_prompt $" {
368 pass "print value of x && y && z (101)"
369 }
370 -re ".*$gdb_prompt $" { fail "print value of x && y && z (101) " }
371 timeout { fail "(timeout) print value of x && y && z (101) " }
372 }
373
374 send_gdb "print x || y || z\n"
375 gdb_expect {
376 -re ".*1.*$gdb_prompt $" {
377 pass "print value of x || y || z (101)"
378 }
379 -re ".*$gdb_prompt $" { fail "print value of x || y || z (101)" }
380 timeout { fail "(timeout) print value of x || y || z (101) " }
381 }
382
383
384 gdb_test "set variable x=0" "" "set variable x=0"
385
386 send_gdb "print x && y && z\n"
387 gdb_expect {
388 -re ".*0.*$gdb_prompt $" {
389 pass "print value of x && y && z (001)"
390 }
391 -re ".*$gdb_prompt $" { fail "print value of x && y && z (001) " }
392 timeout { fail "(timeout) print value of x && y && z (001) " }
393 }
394
395 send_gdb "print x || y || z\n"
396 gdb_expect {
397 -re ".*1.*$gdb_prompt $" {
398 pass "print value of x || y || z (001)"
399 }
400 -re ".*$gdb_prompt $" { fail "print value of x || y || z (001)" }
401 timeout { fail "(timeout) print value of x || y || z (001) " }
402 }
403
404
405
406
407 # test precedence of &&, || ,!
408
409
410 send_gdb "print !x && y\n"
411 gdb_expect {
412 -re ".*0.*$gdb_prompt $" {
413 pass "print value of !x && y (00)"
414 }
415 -re ".*$gdb_prompt $" { fail "print value of !x && y (00)" }
416 timeout { fail "(timeout) print value of !x && y (00) " }
417 }
418
419
420 gdb_test "set variable x=1" "" "set variable x=1"
421
422
423 send_gdb "print !x && y\n"
424 gdb_expect {
425 -re ".*0.*$gdb_prompt $" {
426 pass "print value of !x && y (10)"
427 }
428 -re ".*$gdb_prompt $" { fail "print value of !x && y (10)" }
429 timeout { fail "(timeout) print value of !x && y (10) " }
430 }
431
432
433
434
435 gdb_test "set variable y=1" "" "set variable y=1"
436
437 send_gdb "print !x || y\n"
438 gdb_expect {
439 -re ".*1.*$gdb_prompt $" {
440 pass "print value of !x || y (11)"
441 }
442 -re ".*$gdb_prompt $" { fail "print value of !x || y (11)" }
443 timeout { fail "(timeout) print value of !x || y (11) " }
444 }
445
446
447 gdb_test "set variable x=0" "" "set variable x=0"
448
449
450 send_gdb "print !x || y\n"
451 gdb_expect {
452 -re ".*1.*$gdb_prompt $" {
453 pass "print value of !x || y (01)"
454 }
455 -re ".*$gdb_prompt $" { fail "print value of !x || y (01)" }
456 timeout { fail "(timeout) print value of !x || y (01) " }
457 }
458
459
460
461 gdb_test "set variable x=1" "" "set variable x=1"
462 gdb_test "set variable z=0" "" "set variable z=0"
463
464 send_gdb "print x || y && z\n"
465 gdb_expect {
466 -re ".*1.*$gdb_prompt $" {
467 pass "print value of x || y && z (110)"
468 }
469 -re ".*$gdb_prompt $" { fail "print value of x || y && z (110)" }
470 timeout { fail "(timeout) print value of x || y && z (110) " }
471 }
472
473
474 gdb_test "set variable y=0" "" "set variable y=0"
475
476
477 send_gdb "print x || y && z\n"
478 gdb_expect {
479 -re ".*1.*$gdb_prompt $" {
480 pass "print value of x || y && z (100)"
481 }
482 -re ".*$gdb_prompt $" { fail "print value of x || y && z (100)" }
483 timeout { fail "(timeout) print value of x || y && z (100) " }
484 }
485
486
487
488 gdb_test "set variable x=0" "" "set variable x=0"
489
490 send_gdb "print x || !y && z\n"
491 gdb_expect {
492 -re ".*0.*$gdb_prompt $" {
493
494 gdb_test "set variable x=1" "" "set variable x=1"
495 send_gdb "print x || !y && z\n"
496 gdb_expect {
497 -re ".*1.*$gdb_prompt $" {
498 pass "print value of x || !y && z "
499 }
500 -re ".*$gdb_prompt $" { fail "print value of x || !y && z" }
501 timeout { fail "(timeout) print value of x || !y && z " }
502 }
503 }
504 -re ".*$gdb_prompt $" { fail "print value of x || y && z " }
505 timeout { fail "(timeout) print value of x || y && z " }
506 }
507
508
509
510
511
512 gdb_test "set variable x=1" "" "set variable x=1"
513 gdb_test "set variable y=2" "" "set variable y=2"
514 gdb_test "set variable w=3" "" "set variable w=3"
515 gdb_test "set variable z=3" "" "set variable z=3"
516
517
518 send_gdb "print x > y || w == z\n"
519 gdb_expect {
520 -re ".*1.*$gdb_prompt $" {
521 pass "print value of x > y || w == z"
522 }
523 -re ".*$gdb_prompt $" { fail "print value of x > y || w == z" }
524 timeout { fail "(timeout) print value of x > y || w == z " }
525 }
526
527
528 gdb_test "set variable x=1" "" "set variable x=1"
529 gdb_test "set variable y=2" "" "set variable y=2"
530 gdb_test "set variable w=1" "" "set variable w=1"
531 gdb_test "set variable z=3" "" "set variable z=3"
532
533
534 send_gdb "print x >= y && w != z\n"
535 gdb_expect {
536 -re ".*0.*$gdb_prompt $" {
537 pass "print value of x >= y || w != z"
538 }
539 -re ".*$gdb_prompt $" { fail "print value of x >= y || w != z" }
540 timeout { fail "(timeout) print value of x >= y || w != z " }
541 }
542
543
544
545 gdb_test "set variable x=2" "" "set variable x=2"
546 gdb_test "set variable y=2" "" "set variable y=2"
547 gdb_test "set variable w=2" "" "set variable w=2"
548 gdb_test "set variable z=3" "" "set variable z=3"
549
550
551 send_gdb "print ! x > y || w + z\n"
552 gdb_expect {
553 -re ".*1.*$gdb_prompt $" {
554 pass "print value of x > y || w != z"
555 }
556 -re ".*$gdb_prompt $" { fail "print value of x > y || w != z" }
557 timeout { fail "(timeout) print value of x > y || w != z " }
558 }
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575