integers.exp revision 1.12 1 1.1 christos # This testcase is part of GDB, the GNU debugger.
2 1.1 christos
3 1.11 christos # Copyright 2012-2024 Free Software Foundation, Inc.
4 1.1 christos #
5 1.1 christos # This program is free software; you can redistribute it and/or modify
6 1.1 christos # it under the terms of the GNU General Public License as published by
7 1.1 christos # the Free Software Foundation; either version 3 of the License, or
8 1.1 christos # (at your option) any later version.
9 1.1 christos #
10 1.1 christos # This program is distributed in the hope that it will be useful,
11 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 1.1 christos # GNU General Public License for more details.
14 1.1 christos #
15 1.1 christos # You should have received a copy of the GNU General Public License
16 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 1.1 christos
18 1.1 christos # Test integer expressions.
19 1.1 christos
20 1.1 christos load_lib "go.exp"
21 1.1 christos
22 1.11 christos require allow_go_tests support_go_compile
23 1.1 christos
24 1.1 christos standard_testfile .go
25 1.1 christos
26 1.7 christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug go}] } {
27 1.1 christos return -1
28 1.1 christos }
29 1.1 christos
30 1.1 christos set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
31 1.1 christos set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
32 1.1 christos
33 1.1 christos if { [go_runto_main] < 0 } {
34 1.1 christos return -1
35 1.1 christos }
36 1.1 christos
37 1.1 christos if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
38 1.1 christos pass "setting breakpoint 1"
39 1.1 christos }
40 1.1 christos
41 1.7 christos gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "going to first breakpoint"
42 1.1 christos
43 1.7 christos gdb_test "print i" ".* = 0" "print i before assigned to 1"
44 1.1 christos
45 1.7 christos gdb_test "next" "i = 1" "next to 'i = 1' line"
46 1.7 christos gdb_test "next" "j = 2" "next to 'j = 2' line"
47 1.1 christos # At that point,
48 1.1 christos # i should be equal to 1
49 1.1 christos gdb_test "print i" " = 1"
50 1.1 christos # but j should still be equal to zero
51 1.7 christos gdb_test "print j" " = 0" "test j value before assignment"
52 1.1 christos
53 1.7 christos gdb_test "next" "k = 3" "next to 'k = 3' line"
54 1.7 christos gdb_test "next" "l = k" "next to 'l = k' line"
55 1.1 christos
56 1.1 christos #j should be equal to 2
57 1.1 christos gdb_test "print j" " = 2"
58 1.1 christos # k should be equal to 3
59 1.1 christos gdb_test "print k" " = 3"
60 1.1 christos # But l should still be zero
61 1.1 christos gdb_test "print l" " = 0"
62 1.1 christos
63 1.1 christos # Test addition
64 1.1 christos gdb_test "print i + j" " = 3"
65 1.1 christos gdb_test "print i + k" " = 4"
66 1.1 christos gdb_test "print j + k" " = 5"
67 1.1 christos gdb_test "print i + j + k" " = 6"
68 1.1 christos
69 1.12 christos # Test subtraction
70 1.1 christos gdb_test "print j - i" " = 1"
71 1.1 christos gdb_test "print i - j" "= -1"
72 1.1 christos gdb_test "print k -i -j" " = 0"
73 1.1 christos gdb_test "print k -(i + j)" " = 0"
74 1.1 christos
75 1.1 christos # Test unany minus
76 1.1 christos gdb_test "print -i" " = -1"
77 1.1 christos gdb_test "print (-i)" " = -1"
78 1.1 christos gdb_test "print -(i)" " = -1"
79 1.1 christos gdb_test "print -(i+j)" " = -3"
80 1.1 christos
81 1.1 christos # Test boolean operators =, <>, <, <=, > and >=
82 1.1 christos gdb_test "print i + 1 == j" " = true"
83 1.1 christos gdb_test "print i + 1 != j" " = false"
84 1.1 christos gdb_test "print i + 1 < j" " = false"
85 1.1 christos gdb_test "print i + 1 <= j" " = true"
86 1.1 christos gdb_test "print i + 1 > j" " = false"
87 1.1 christos gdb_test "print i + 1 >= j" " = true"
88 1.1 christos
89 1.1 christos # Test multiplication
90 1.1 christos gdb_test "print 2 * i" " = 2"
91 1.1 christos gdb_test "print j * k" " = 6"
92 1.1 christos gdb_test "print 3000*i" " = 3000"
93 1.1 christos
94 1.1 christos #Test div and mod operators
95 1.1 christos gdb_test "print 35 / 2" " = 17"
96 1.1 christos gdb_test "print 35 % 2" " = 1"
97 1.1 christos
98 1.1 christos # Test several operators together
99 1.1 christos gdb_test "print i+10*j+100*k" " = 321"
100 1.1 christos gdb_test " print (i + 5) * (j + 7)" " = 54"
101 1.1 christos
102 1.1 christos gdb_test "set var i = 2" " = 2"
103 1.7 christos gdb_test "print i" " = 2" "testing new i value"
104 1.1 christos
105 1.1 christos if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
106 1.1 christos pass "setting breakpoint 2"
107 1.1 christos }
108 1.1 christos
109 1.1 christos gdb_test "cont" \
110 1.1 christos "Breakpoint .*:${bp_location2}.*" \
111 1.1 christos "Going to second breakpoint"
112 1.1 christos gdb_test "print i" \
113 1.1 christos ".* = 5.*" \
114 1.7 christos "value of i after assignment"
115