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