* config/tc-arm.c (arm_cpus): Add entry for ARM Cortex-M0.
[binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
blobb1f8c59e7d809a6371dafa59ae38e55df3c2b8b8
1 # Copyright 1998, 1999, 2001, 2007, 2008, 2009 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17 # Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
19 # This file is part of the gdb testsuite
21 # tests for correctness of arithmetic operators, associativity and precedence
22 # with integer type variables
23
25 if $tracelevel then {
26         strace $tracelevel
27         }
30 # test running programs
32 set prms_id 0
33 set bug_id 0
35 set testfile "int-type"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
40      untested arithmet.exp
41      return -1
42     }
44 gdb_exit
45 gdb_start
46 gdb_reinitialize_dir $srcdir/$subdir
47 gdb_load ${binfile}
51 # set it up at a breakpoint so we can play with the variable values
54 if ![runto_main] then {
55     perror "couldn't run to breakpoint"
56     continue
60 # test expressions with "int" types
63 gdb_test "set variable x=14" ""
64 gdb_test "set variable y=2"  ""
65 gdb_test "set variable z=2"  ""
66 gdb_test "set variable w=3"  ""
68 gdb_test "print x" "14"
69 gdb_test "print y"  "2"
70 gdb_test "print z"  "2"
71 gdb_test "print w"  "3"
73 gdb_test "print x+y" "16"
74 gdb_test "print x-y" "12"
75 gdb_test "print x*y" "28"
76 gdb_test "print x/y"  "7"
77 gdb_test "print x%y"  "0"
79 #  x  y  z  w
80 # 14  2  2  3
82 # Test associativity of +, -, *, % ,/
84 gdb_test "print x+y+z" "18"
85 gdb_test "print x-y-z" "10"
86 gdb_test "print x*y*z" "56"
87 gdb_test "print x/y/z"  "3"
88 gdb_test "print x%y%z"  "0"
90 # test precedence rules on pairs of arithmetic operators
92 gdb_test "set variable x=10" ""
93 gdb_test "set variable y=4"  ""
95 #  x  y  z  w
96 # 10  4  2  3
98 gdb_test "print x+y-z" "12"
99 gdb_test "print x+y*z" "18"
100 gdb_test "print x+y%w" "11"
101 gdb_test "print x+y/w" "11"
102 gdb_test "print x-y*z"  "2"
103 gdb_test "print x-y%z" "10"
104 gdb_test "print x-y/z"  "8"
105 gdb_test "print x*y/z" "20"
106 gdb_test "print x*y%w"  "1"
107 gdb_test "print x/y%w"  "2"
109 # test use of parentheses to enforce different order of evaluation
111 gdb_test "print x-(y+w)"  "3"
112 gdb_test "print x/(y*w)"  "0"
113 gdb_test "print x-(y/w)"  "9"
114 gdb_test "print (x+y)*w" "42"