Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / store.exp
blob3ed7621165d5d464b965cb21bb0dcc51e872a919
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2002-2023 Free Software Foundation, Inc.
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
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 standard_testfile
19 set executable $testfile
21 if { [prepare_for_testing "failed to prepare" $executable $srcfile] } {
22     return -1
26 # set it up at a breakpoint so we can play with the variable values
29 if {![runto_main]} {
30     return
35 proc check_set { t l r new add } {
36     global gdb_prompt
38     set prefix "var ${t} l"
39     gdb_test "tbreak wack_${t}"
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     }
53     set supported_l 1
54     set test "${prefix}; print old l, expecting ${l}"
55     gdb_test_multiple "print l" "$test"  {
56         -re -wrap " = <optimized out>" {
57             unsupported $test
58             set supported_l 0
59         }
60         -re -wrap " = ${l}" {
61             pass $test
62         }
63     }
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     }
75     if { $supported_l } {
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}"
80     }
81     gdb_test "next" "return l \\+ r;" \
82         "${prefix}; next over add call"
83     if { $supported_l } {
84         gdb_test "print l" " = ${add}" \
85             "${prefix}; print incremented l, expecting ${add}"
86     }
89 check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
90 check_set "short" "-1" "-2" "4" "2"
91 check_set "int" "-1" "-2" "4" "2"
92 check_set "long" "-1" "-2" "4" "2"
93 check_set "longest" "-1" "-2" "4" "2"
94 check_set "float" "-1" "-2" "4" "2"
95 check_set "double" "-1" "-2" "4" "2"
96 check_set "doublest" "-1" "-2" "4" "2"
100 proc up_set { t l r new } {
101     global gdb_prompt
103     set prefix "upvar ${t} l"
104     gdb_test "tbreak add_${t}"
105     gdb_test "continue" "return u . v;" \
106         "continue to add_${t}"
107     gdb_test "up" "l = add_${t} .l, r.;" \
108         "${prefix}; up"
110     set supported_l 1
111     set test "${prefix}; print old l, expecting ${l}"
112     gdb_test_multiple "print l" "$test"  {
113         -re -wrap " = <optimized out>" {
114             unsupported $test
115             set supported_l 0
116         }
117         -re -wrap " = ${l}" {
118             pass $test
119         }
120     }
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     }
132     if { $supported_l } {
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     }
140 up_set "charest" "-1 .*" "-2 .*" "4 ..004."
141 up_set "short" "-1" "-2" "4"
142 up_set "int" "-1" "-2" "4"
143 up_set "long" "-1" "-2" "4"
144 up_set "longest" "-1" "-2" "4"
145 up_set "float" "-1" "-2" "4"
146 up_set "double" "-1" "-2" "4"
147 up_set "doublest" "-1" "-2" "4"
151 proc check_struct { t old new } {
152     set prefix "var struct ${t} u"
153     gdb_test "tbreak wack_struct_${t}"
154     gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
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}"
160     gdb_test_no_output "set variable u = s_${t}" \
161         "${prefix}; set u to s_${t}"
162     gdb_test "print u" " = ${new}" \
163         "${prefix}; print new u, expecting ${new}"
166 check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
167 check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
168 check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
169 check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
171 proc up_struct { t old new } {
172     set prefix "up struct ${t} u"
173     gdb_test "tbreak add_struct_${t}"
174     gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
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}"
180     gdb_test_no_output "set variable u = s_${t}" \
181         "${prefix}; set u to s_${t}"
182     gdb_test "print u" " = ${new}" \
183         "${prefix}; print new u, expecting ${new}"
186 up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
187 up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
188 up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
189 up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
193 proc 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}"
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}"
204     gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
205     gdb_test_no_output "set variable u = F_${t}"
206     gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
208     gdb_test_no_output "set variable u = F_${t}, u.i = f_${t}.i"
209     gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
211     gdb_test_no_output "set variable u = F_${t}, u.j = f_${t}.j"
212     gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
214     gdb_test_no_output "set variable u = F_${t}, u.k = f_${t}.k"
215     gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
217     gdb_test_no_output "set variable u = f_${t}, u.i = F_${t}.i"
218     gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
220     gdb_test_no_output "set variable u = f_${t}, u.j = F_${t}.j"
221     gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
223     gdb_test_no_output "set variable u = f_${t}, u.k = F_${t}.k"
224     gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
228 check_field 1
229 check_field 2
230 check_field 3
231 check_field 4
235 # WANTED: A fairly portable way of convincing the compiler to split a
236 # value across memory and registers.