]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/store.exp
gdb/testsuite/
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / store.exp
CommitLineData
8da195dd
AC
1# This testcase is part of GDB, the GNU debugger.
2
0b302171 3# Copyright 2002-2004, 2007-2012 Free Software Foundation, Inc.
27e829d0
AC
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
27e829d0
AC
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
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
27e829d0 17
27e829d0
AC
18#
19# test running programs
20#
27e829d0
AC
21
22set testfile "store"
23set srcfile ${testfile}.c
24set binfile ${objdir}/${subdir}/${testfile}
25if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b9c5a23d
DJ
26 untested store.exp
27 return -1
27e829d0
AC
28}
29
4c93b1db 30if [get_compiler_info] {
27e829d0
AC
31 return -1;
32}
33
34gdb_exit
35gdb_start
36gdb_reinitialize_dir $srcdir/$subdir
37gdb_load ${binfile}
38
39#
40# set it up at a breakpoint so we can play with the variable values
41#
42
43if ![runto_main] then {
44 perror "couldn't run to breakpoint"
45 continue
46}
47
48#
49
81a58f5b 50proc check_set { t l r new add } {
263a0f8c
JK
51 global gdb_prompt
52
8da195dd 53 set prefix "var ${t} l"
27e829d0 54 gdb_test "tbreak wack_${t}"
263a0f8c
JK
55
56 set test "continue to wack_${t}"
57 gdb_test_multiple "continue" $test {
58 -re "register ${t} l = u, r = v;\r\n$gdb_prompt $" {
59 # See GCC PR debug/53948.
60 send_gdb "next\n"
61 exp_continue
62 }
63 -re "l = add_${t} .l, r.;\r\n$gdb_prompt $" {
64 pass $test
65 }
66 }
67
8da195dd
AC
68 gdb_test "print l" " = ${l}" \
69 "${prefix}; print old l, expecting ${l}"
70 gdb_test "print r" " = ${r}" \
71 "${prefix}; print old r, expecting ${r}"
27d3a1a2 72 gdb_test_no_output "set variable l = 4" \
8da195dd
AC
73 "${prefix}; setting l to 4"
74 gdb_test "print l" " = ${new}" \
146b9145 75 "${prefix}; print new l, expecting ${new}"
8da195dd
AC
76 gdb_test "next" "return l \\+ r;" \
77 "${prefix}; next over add call"
78 gdb_test "print l" " = ${add}" \
79 "${prefix}; print incremented l, expecting ${add}"
27e829d0
AC
80}
81
30b66ecc 82check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
81a58f5b
AC
83check_set "short" "-1" "-2" "4" "2"
84check_set "int" "-1" "-2" "4" "2"
85check_set "long" "-1" "-2" "4" "2"
86check_set "longest" "-1" "-2" "4" "2"
87check_set "float" "-1" "-2" "4" "2"
88check_set "double" "-1" "-2" "4" "2"
89check_set "doublest" "-1" "-2" "4" "2"
27e829d0
AC
90
91#
92
81a58f5b 93proc up_set { t l r new } {
8da195dd 94 set prefix "upvar ${t} l"
27e829d0 95 gdb_test "tbreak add_${t}"
8da195dd
AC
96 gdb_test "continue" "return u . v;" \
97 "continue to add_${t}"
98 gdb_test "up" "l = add_${t} .l, r.;" \
99 "${prefix}; up"
100 gdb_test "print l" " = ${l}" \
101 "${prefix}; print old l, expecting ${l}"
102 gdb_test "print r" " = ${r}" \
103 "${prefix}; print old r, expecting ${r}"
27d3a1a2 104 gdb_test_no_output "set variable l = 4" \
8da195dd
AC
105 "${prefix}; set l to 4"
106 gdb_test "print l" " = ${new}" \
107 "${prefix}; print new l, expecting ${new}"
27e829d0
AC
108}
109
30b66ecc 110up_set "charest" "-1 .*" "-2 .*" "4 ..004."
81a58f5b
AC
111up_set "short" "-1" "-2" "4"
112up_set "int" "-1" "-2" "4"
113up_set "long" "-1" "-2" "4"
114up_set "longest" "-1" "-2" "4"
115up_set "float" "-1" "-2" "4"
116up_set "double" "-1" "-2" "4"
117up_set "doublest" "-1" "-2" "4"
27e829d0
AC
118
119#
120
121proc check_struct { t old new } {
8da195dd 122 set prefix "var struct ${t} u"
27e829d0
AC
123 gdb_test "tbreak wack_struct_${t}"
124 gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
8da195dd
AC
125 "continue to wack_struct_${t}"
126 gdb_test "next 2" "add_struct_${t} .u.;" \
127 "${prefix}; next to add_struct_${t} call"
128 gdb_test "print u" " = ${old}" \
129 "${prefix}; print old u, expecting ${old}"
27d3a1a2 130 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
131 "${prefix}; set u to s_${t}"
132 gdb_test "print u" " = ${new}" \
133 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
134}
135
7634bb6e
DJ
136check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
137check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
138check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
139check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
140
141proc up_struct { t old new } {
8da195dd 142 set prefix "up struct ${t} u"
27e829d0
AC
143 gdb_test "tbreak add_struct_${t}"
144 gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
8da195dd
AC
145 "continue to add_struct_${t}"
146 gdb_test "up" "u = add_struct_${t} .u.;" \
147 "${prefix}; up"
148 gdb_test "print u" " = ${old}" \
149 "${prefix}; print old u, expecting ${old}"
27d3a1a2 150 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
151 "${prefix}; set u to s_${t}"
152 gdb_test "print u" " = ${new}" \
153 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
154}
155
7634bb6e
DJ
156up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
157up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
158up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
159up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
160
161#
162
163proc check_field { t } {
164 global gdb_prompt
165 gdb_test "tbreak wack_field_${t}"
166 gdb_test "continue" "register struct f_${t} u = f_${t};" \
167 "continue field ${t}"
81a58f5b
AC
168
169 # Match either the return statement, or the line immediatly after
170 # it. The compiler can end up merging the return statement into
171 # the return instruction.
172 gdb_test "next" "(return u;|\})" "next field ${t}"
27e829d0
AC
173
174 gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
27d3a1a2 175 gdb_test_no_output "set variable u = F_${t}"
27e829d0
AC
176 gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
177
27d3a1a2 178 gdb_test_no_output "set variable u = F_${t}, u.i = f_${t}.i"
27e829d0
AC
179 gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
180
27d3a1a2 181 gdb_test_no_output "set variable u = F_${t}, u.j = f_${t}.j"
27e829d0
AC
182 gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
183
27d3a1a2 184 gdb_test_no_output "set variable u = F_${t}, u.k = f_${t}.k"
27e829d0
AC
185 gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
186
27d3a1a2 187 gdb_test_no_output "set variable u = f_${t}, u.i = F_${t}.i"
27e829d0
AC
188 gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
189
27d3a1a2 190 gdb_test_no_output "set variable u = f_${t}, u.j = F_${t}.j"
27e829d0
AC
191 gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
192
27d3a1a2 193 gdb_test_no_output "set variable u = f_${t}, u.k = F_${t}.k"
27e829d0
AC
194 gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
195
196}
197
198check_field 1
199check_field 2
200check_field 3
201check_field 4
202
203#
204
205# WANTED: A fairly portable way of convincing the compiler to split a
206# value across memory and registers.
207