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