Do not run for targets which do not support shared objects.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / store.exp
CommitLineData
7634bb6e 1# Copyright 2002, 2003 Free Software Foundation, Inc.
27e829d0
AC
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@gnu.org
19
20if $tracelevel {
21 strace $tracelevel
22}
23
24#
25# test running programs
26#
27set prms_id 0
28set bug_id 0
29
30set testfile "store"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
35}
36
37if [get_compiler_info ${binfile}] {
38 return -1;
39}
40
41gdb_exit
42gdb_start
43gdb_reinitialize_dir $srcdir/$subdir
44gdb_load ${binfile}
45
46#
47# set it up at a breakpoint so we can play with the variable values
48#
49
50if ![runto_main] then {
51 perror "couldn't run to breakpoint"
52 continue
53}
54
55#
56
81a58f5b 57proc check_set { t l r new add } {
27e829d0
AC
58 global gdb_prompt
59 gdb_test "tbreak wack_${t}"
81a58f5b
AC
60 gdb_test "continue" "register ${t} l = u, r = v;" "continue to wack_${t}"
61 gdb_test "next" "l = add_${t} .l, r.;" "next ${t}"
62 gdb_test "print l" " = ${l}" "print old l - ${t}"
63 gdb_test "print r" " = ${r}" "print old r - ${t}"
27e829d0 64 gdb_test "set variable l = 4"
81a58f5b 65 gdb_test "print l" " = ${new}" "print new l - ${t}"
3a871b37 66 gdb_test "next" "return l \\+ r;"
81a58f5b 67 gdb_test "print l" " = ${add}" "print add - ${t}"
27e829d0
AC
68}
69
3a871b37 70check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
81a58f5b
AC
71check_set "short" "-1" "-2" "4" "2"
72check_set "int" "-1" "-2" "4" "2"
73check_set "long" "-1" "-2" "4" "2"
74check_set "longest" "-1" "-2" "4" "2"
75check_set "float" "-1" "-2" "4" "2"
76check_set "double" "-1" "-2" "4" "2"
77check_set "doublest" "-1" "-2" "4" "2"
27e829d0
AC
78
79#
80
81a58f5b 81proc up_set { t l r new } {
27e829d0
AC
82 global gdb_prompt
83 gdb_test "tbreak add_${t}"
81a58f5b
AC
84 gdb_test "continue" "return u . v;" "continue to add_${t}"
85 gdb_test "up" "l = add_${t} .l, r.;" "up ${t}"
86 gdb_test "print l" " = ${l}" "up print old l - ${t}"
87 gdb_test "print r" " = ${r}" "up print old r - ${t}"
27e829d0 88 gdb_test "set variable l = 4"
81a58f5b 89 gdb_test "print l" " = ${new}" "up print new l - ${t}"
27e829d0
AC
90}
91
3a871b37 92up_set "charest" "-1 .*" "-2 .*" "4 ..004."
81a58f5b
AC
93up_set "short" "-1" "-2" "4"
94up_set "int" "-1" "-2" "4"
95up_set "long" "-1" "-2" "4"
96up_set "longest" "-1" "-2" "4"
97up_set "float" "-1" "-2" "4"
98up_set "double" "-1" "-2" "4"
99up_set "doublest" "-1" "-2" "4"
27e829d0
AC
100
101#
102
103proc check_struct { t old new } {
104 global gdb_prompt
105 gdb_test "tbreak wack_struct_${t}"
106 gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
107 "continue set struct ${t}"
108 gdb_test "next 2" "add_struct_${t} .u.;"
109 gdb_test "print u" " = ${old}" "old check struct ${t}"
110 gdb_test "set variable u = s_${t}"
111 gdb_test "print u" " = ${new}" "new check struct ${t}"
112}
113
7634bb6e
DJ
114check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
115check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
116check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
117check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
118
119proc up_struct { t old new } {
120 global gdb_prompt
121 gdb_test "tbreak add_struct_${t}"
122 gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
123 "continue up struct ${t}"
124 gdb_test "up" "u = add_struct_${t} .u.;" "up struct ${t}"
125 gdb_test "print u" " = ${old}" "old up struct ${t}"
126 gdb_test "set variable u = s_${t}"
127 gdb_test "print u" " = ${new}" "new up struct ${t}"
128}
129
7634bb6e
DJ
130up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
131up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
132up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
133up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
134
135#
136
137proc check_field { t } {
138 global gdb_prompt
139 gdb_test "tbreak wack_field_${t}"
140 gdb_test "continue" "register struct f_${t} u = f_${t};" \
141 "continue field ${t}"
81a58f5b
AC
142
143 # Match either the return statement, or the line immediatly after
144 # it. The compiler can end up merging the return statement into
145 # the return instruction.
146 gdb_test "next" "(return u;|\})" "next field ${t}"
27e829d0
AC
147
148 gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
149 gdb_test "set variable u = F_${t}"
150 gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
151
152 gdb_test "set variable u = F_${t}, u.i = f_${t}.i"
153 gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
154
155 gdb_test "set variable u = F_${t}, u.j = f_${t}.j"
156 gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
157
158 gdb_test "set variable u = F_${t}, u.k = f_${t}.k"
159 gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
160
161 gdb_test "set variable u = f_${t}, u.i = F_${t}.i"
162 gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
163
164 gdb_test "set variable u = f_${t}, u.j = F_${t}.j"
165 gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
166
167 gdb_test "set variable u = f_${t}, u.k = F_${t}.k"
168 gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
169
170}
171
172check_field 1
173check_field 2
174check_field 3
175check_field 4
176
177#
178
179# WANTED: A fairly portable way of convincing the compiler to split a
180# value across memory and registers.
181
This page took 0.150143 seconds and 4 git commands to generate.