]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/store.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / store.exp
CommitLineData
8da195dd
AC
1# This testcase is part of GDB, the GNU debugger.
2
1d506c26 3# Copyright 2002-2024 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
e229648e
JK
18standard_testfile
19set executable $testfile
27e829d0 20
5b362f04 21if { [prepare_for_testing "failed to prepare" $executable $srcfile] } {
b9c5a23d 22 return -1
27e829d0
AC
23}
24
27e829d0
AC
25#
26# set it up at a breakpoint so we can play with the variable values
27#
28
65a33d75 29if {![runto_main]} {
cdd42066 30 return
27e829d0
AC
31}
32
33#
34
81a58f5b 35proc check_set { t l r new add } {
263a0f8c
JK
36 global gdb_prompt
37
8da195dd 38 set prefix "var ${t} l"
27e829d0 39 gdb_test "tbreak wack_${t}"
263a0f8c
JK
40
41 set test "continue to wack_${t}"
42 gdb_test_multiple "continue" $test {
43 -re "register ${t} l = u, r = v;\r\n$gdb_prompt $" {
44 # See GCC PR debug/53948.
45 send_gdb "next\n"
46 exp_continue
47 }
48 -re "l = add_${t} .l, r.;\r\n$gdb_prompt $" {
49 pass $test
50 }
51 }
52
abf6d805 53 set supported_l 1
25e5c209
TV
54 set test "${prefix}; print old l, expecting ${l}"
55 gdb_test_multiple "print l" "$test" {
abf6d805 56 -re -wrap " = <optimized out>" {
25e5c209 57 unsupported $test
abf6d805 58 set supported_l 0
25e5c209 59 }
abf6d805 60 -re -wrap " = ${l}" {
25e5c209
TV
61 pass $test
62 }
63 }
abf6d805
TV
64
65 set test "${prefix}; print old r, expecting ${r}"
66 gdb_test_multiple "print r" "$test" {
67 -re -wrap " = <optimized out>" {
68 unsupported $test
69 }
70 -re -wrap " = ${r}" {
71 pass $test
72 }
73 }
74
75 if { $supported_l } {
25e5c209
TV
76 gdb_test_no_output "set variable l = 4" \
77 "${prefix}; setting l to 4"
78 gdb_test "print l" " = ${new}" \
79 "${prefix}; print new l, expecting ${new}"
abf6d805
TV
80 }
81 gdb_test "next" "return l \\+ r;" \
82 "${prefix}; next over add call"
83 if { $supported_l } {
25e5c209
TV
84 gdb_test "print l" " = ${add}" \
85 "${prefix}; print incremented l, expecting ${add}"
86 }
27e829d0
AC
87}
88
30b66ecc 89check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
81a58f5b
AC
90check_set "short" "-1" "-2" "4" "2"
91check_set "int" "-1" "-2" "4" "2"
92check_set "long" "-1" "-2" "4" "2"
93check_set "longest" "-1" "-2" "4" "2"
94check_set "float" "-1" "-2" "4" "2"
95check_set "double" "-1" "-2" "4" "2"
96check_set "doublest" "-1" "-2" "4" "2"
27e829d0
AC
97
98#
99
81a58f5b 100proc up_set { t l r new } {
25e5c209
TV
101 global gdb_prompt
102
8da195dd 103 set prefix "upvar ${t} l"
27e829d0 104 gdb_test "tbreak add_${t}"
8da195dd
AC
105 gdb_test "continue" "return u . v;" \
106 "continue to add_${t}"
107 gdb_test "up" "l = add_${t} .l, r.;" \
108 "${prefix}; up"
25e5c209 109
abf6d805 110 set supported_l 1
25e5c209
TV
111 set test "${prefix}; print old l, expecting ${l}"
112 gdb_test_multiple "print l" "$test" {
abf6d805 113 -re -wrap " = <optimized out>" {
25e5c209 114 unsupported $test
abf6d805 115 set supported_l 0
25e5c209 116 }
abf6d805 117 -re -wrap " = ${l}" {
25e5c209
TV
118 pass $test
119 }
120 }
abf6d805
TV
121
122 set test "${prefix}; print old r, expecting ${r}"
123 gdb_test_multiple "print r" "$test" {
124 -re -wrap " = <optimized out>" {
125 unsupported $test
126 }
127 -re -wrap " = ${r}" {
128 pass $test
129 }
130 }
131
132 if { $supported_l } {
25e5c209
TV
133 gdb_test_no_output "set variable l = 4" \
134 "${prefix}; set l to 4"
135 gdb_test "print l" " = ${new}" \
136 "${prefix}; print new l, expecting ${new}"
137 }
27e829d0
AC
138}
139
30b66ecc 140up_set "charest" "-1 .*" "-2 .*" "4 ..004."
81a58f5b
AC
141up_set "short" "-1" "-2" "4"
142up_set "int" "-1" "-2" "4"
143up_set "long" "-1" "-2" "4"
144up_set "longest" "-1" "-2" "4"
145up_set "float" "-1" "-2" "4"
146up_set "double" "-1" "-2" "4"
147up_set "doublest" "-1" "-2" "4"
27e829d0
AC
148
149#
150
151proc check_struct { t old new } {
8da195dd 152 set prefix "var struct ${t} u"
27e829d0
AC
153 gdb_test "tbreak wack_struct_${t}"
154 gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
8da195dd
AC
155 "continue to wack_struct_${t}"
156 gdb_test "next 2" "add_struct_${t} .u.;" \
157 "${prefix}; next to add_struct_${t} call"
158 gdb_test "print u" " = ${old}" \
159 "${prefix}; print old u, expecting ${old}"
27d3a1a2 160 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
161 "${prefix}; set u to s_${t}"
162 gdb_test "print u" " = ${new}" \
163 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
164}
165
7634bb6e
DJ
166check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
167check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
168check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
169check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
170
171proc up_struct { t old new } {
8da195dd 172 set prefix "up struct ${t} u"
27e829d0
AC
173 gdb_test "tbreak add_struct_${t}"
174 gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
8da195dd
AC
175 "continue to add_struct_${t}"
176 gdb_test "up" "u = add_struct_${t} .u.;" \
177 "${prefix}; up"
178 gdb_test "print u" " = ${old}" \
179 "${prefix}; print old u, expecting ${old}"
27d3a1a2 180 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
181 "${prefix}; set u to s_${t}"
182 gdb_test "print u" " = ${new}" \
183 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
184}
185
7634bb6e
DJ
186up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
187up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
188up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
189up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
190
191#
192
193proc check_field { t } {
194 global gdb_prompt
195 gdb_test "tbreak wack_field_${t}"
196 gdb_test "continue" "register struct f_${t} u = f_${t};" \
197 "continue field ${t}"
81a58f5b
AC
198
199 # Match either the return statement, or the line immediatly after
200 # it. The compiler can end up merging the return statement into
201 # the return instruction.
202 gdb_test "next" "(return u;|\})" "next field ${t}"
27e829d0
AC
203
204 gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
27d3a1a2 205 gdb_test_no_output "set variable u = F_${t}"
27e829d0
AC
206 gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
207
27d3a1a2 208 gdb_test_no_output "set variable u = F_${t}, u.i = f_${t}.i"
27e829d0
AC
209 gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
210
27d3a1a2 211 gdb_test_no_output "set variable u = F_${t}, u.j = f_${t}.j"
27e829d0
AC
212 gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
213
27d3a1a2 214 gdb_test_no_output "set variable u = F_${t}, u.k = f_${t}.k"
27e829d0
AC
215 gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
216
27d3a1a2 217 gdb_test_no_output "set variable u = f_${t}, u.i = F_${t}.i"
27e829d0
AC
218 gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
219
27d3a1a2 220 gdb_test_no_output "set variable u = f_${t}, u.j = F_${t}.j"
27e829d0
AC
221 gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
222
27d3a1a2 223 gdb_test_no_output "set variable u = f_${t}, u.k = F_${t}.k"
27e829d0
AC
224 gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
225
226}
227
228check_field 1
229check_field 2
230check_field 3
231check_field 4
232
233#
234
235# WANTED: A fairly portable way of convincing the compiler to split a
236# value across memory and registers.
237