* gdb.base/gdb1090.exp: Change breakpoint location to read the
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
CommitLineData
7b6bb8da 1# Copyright 1998, 1999, 2001, 2007, 2008, 2009, 2010, 2011
4c38e0a4 2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# This file was written by Elena Zannoni (ezannoni@cygnus.com)
b4127474 18# Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
c906108c
SS
19
20# This file is part of the gdb testsuite
21#
22# tests for correctness of arithmetic operators, associativity and precedence
23# with integer type variables
24#
25
26if $tracelevel then {
27 strace $tracelevel
28 }
29
30#
31# test running programs
32#
c906108c
SS
33
34set testfile "int-type"
35set srcfile ${testfile}.c
36set binfile ${objdir}/${subdir}/${testfile}
37
fc91c6c2 38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
39 untested arithmet.exp
40 return -1
c906108c
SS
41 }
42
43gdb_exit
44gdb_start
45gdb_reinitialize_dir $srcdir/$subdir
46gdb_load ${binfile}
47
48
49#
50# set it up at a breakpoint so we can play with the variable values
51#
52
53if ![runto_main] then {
54 perror "couldn't run to breakpoint"
55 continue
56}
57
58#
59# test expressions with "int" types
60#
61
27d3a1a2
MS
62gdb_test_no_output "set variable x=14"
63gdb_test_no_output "set variable y=2"
64gdb_test_no_output "set variable z=2"
65gdb_test_no_output "set variable w=3"
b4127474
MC
66
67gdb_test "print x" "14"
68gdb_test "print y" "2"
69gdb_test "print z" "2"
70gdb_test "print w" "3"
71
72gdb_test "print x+y" "16"
73gdb_test "print x-y" "12"
74gdb_test "print x*y" "28"
75gdb_test "print x/y" "7"
76gdb_test "print x%y" "0"
77
78# x y z w
79# 14 2 2 3
c906108c
SS
80
81# Test associativity of +, -, *, % ,/
82
b4127474
MC
83gdb_test "print x+y+z" "18"
84gdb_test "print x-y-z" "10"
85gdb_test "print x*y*z" "56"
86gdb_test "print x/y/z" "3"
87gdb_test "print x%y%z" "0"
c906108c
SS
88
89# test precedence rules on pairs of arithmetic operators
90
27d3a1a2
MS
91gdb_test_no_output "set variable x=10"
92gdb_test_no_output "set variable y=4"
c906108c 93
b4127474
MC
94# x y z w
95# 10 4 2 3
c906108c 96
b4127474
MC
97gdb_test "print x+y-z" "12"
98gdb_test "print x+y*z" "18"
112f9ab5
MC
99gdb_test "print x+y%w" "11"
100gdb_test "print x+y/w" "11"
b4127474
MC
101gdb_test "print x-y*z" "2"
102gdb_test "print x-y%z" "10"
103gdb_test "print x-y/z" "8"
104gdb_test "print x*y/z" "20"
112f9ab5
MC
105gdb_test "print x*y%w" "1"
106gdb_test "print x/y%w" "2"
c906108c 107
b4127474 108# test use of parentheses to enforce different order of evaluation
c906108c 109
112f9ab5
MC
110gdb_test "print x-(y+w)" "3"
111gdb_test "print x/(y*w)" "0"
112gdb_test "print x-(y/w)" "9"
113gdb_test "print (x+y)*w" "42"
This page took 1.041447 seconds and 4 git commands to generate.