]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/store.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / store.exp
CommitLineData
8da195dd
AC
1# This testcase is part of GDB, the GNU debugger.
2
42a4f53d 3# Copyright 2002-2019 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
8da195dd
AC
58 gdb_test "print l" " = ${l}" \
59 "${prefix}; print old l, expecting ${l}"
60 gdb_test "print r" " = ${r}" \
61 "${prefix}; print old r, expecting ${r}"
27d3a1a2 62 gdb_test_no_output "set variable l = 4" \
8da195dd
AC
63 "${prefix}; setting l to 4"
64 gdb_test "print l" " = ${new}" \
146b9145 65 "${prefix}; print new l, expecting ${new}"
8da195dd
AC
66 gdb_test "next" "return l \\+ r;" \
67 "${prefix}; next over add call"
68 gdb_test "print l" " = ${add}" \
69 "${prefix}; print incremented l, expecting ${add}"
27e829d0
AC
70}
71
30b66ecc 72check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
81a58f5b
AC
73check_set "short" "-1" "-2" "4" "2"
74check_set "int" "-1" "-2" "4" "2"
75check_set "long" "-1" "-2" "4" "2"
76check_set "longest" "-1" "-2" "4" "2"
77check_set "float" "-1" "-2" "4" "2"
78check_set "double" "-1" "-2" "4" "2"
79check_set "doublest" "-1" "-2" "4" "2"
27e829d0
AC
80
81#
82
81a58f5b 83proc up_set { t l r new } {
8da195dd 84 set prefix "upvar ${t} l"
27e829d0 85 gdb_test "tbreak add_${t}"
8da195dd
AC
86 gdb_test "continue" "return u . v;" \
87 "continue to add_${t}"
88 gdb_test "up" "l = add_${t} .l, r.;" \
89 "${prefix}; up"
90 gdb_test "print l" " = ${l}" \
91 "${prefix}; print old l, expecting ${l}"
92 gdb_test "print r" " = ${r}" \
93 "${prefix}; print old r, expecting ${r}"
27d3a1a2 94 gdb_test_no_output "set variable l = 4" \
8da195dd
AC
95 "${prefix}; set l to 4"
96 gdb_test "print l" " = ${new}" \
97 "${prefix}; print new l, expecting ${new}"
27e829d0
AC
98}
99
30b66ecc 100up_set "charest" "-1 .*" "-2 .*" "4 ..004."
81a58f5b
AC
101up_set "short" "-1" "-2" "4"
102up_set "int" "-1" "-2" "4"
103up_set "long" "-1" "-2" "4"
104up_set "longest" "-1" "-2" "4"
105up_set "float" "-1" "-2" "4"
106up_set "double" "-1" "-2" "4"
107up_set "doublest" "-1" "-2" "4"
27e829d0
AC
108
109#
110
111proc check_struct { t old new } {
8da195dd 112 set prefix "var struct ${t} u"
27e829d0
AC
113 gdb_test "tbreak wack_struct_${t}"
114 gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
8da195dd
AC
115 "continue to wack_struct_${t}"
116 gdb_test "next 2" "add_struct_${t} .u.;" \
117 "${prefix}; next to add_struct_${t} call"
118 gdb_test "print u" " = ${old}" \
119 "${prefix}; print old u, expecting ${old}"
27d3a1a2 120 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
121 "${prefix}; set u to s_${t}"
122 gdb_test "print u" " = ${new}" \
123 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
124}
125
7634bb6e
DJ
126check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
127check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
128check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
129check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
130
131proc up_struct { t old new } {
8da195dd 132 set prefix "up struct ${t} u"
27e829d0
AC
133 gdb_test "tbreak add_struct_${t}"
134 gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
8da195dd
AC
135 "continue to add_struct_${t}"
136 gdb_test "up" "u = add_struct_${t} .u.;" \
137 "${prefix}; up"
138 gdb_test "print u" " = ${old}" \
139 "${prefix}; print old u, expecting ${old}"
27d3a1a2 140 gdb_test_no_output "set variable u = s_${t}" \
8da195dd
AC
141 "${prefix}; set u to s_${t}"
142 gdb_test "print u" " = ${new}" \
143 "${prefix}; print new u, expecting ${new}"
27e829d0
AC
144}
145
7634bb6e
DJ
146up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
147up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
148up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
149up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
27e829d0
AC
150
151#
152
153proc check_field { t } {
154 global gdb_prompt
155 gdb_test "tbreak wack_field_${t}"
156 gdb_test "continue" "register struct f_${t} u = f_${t};" \
157 "continue field ${t}"
81a58f5b
AC
158
159 # Match either the return statement, or the line immediatly after
160 # it. The compiler can end up merging the return statement into
161 # the return instruction.
162 gdb_test "next" "(return u;|\})" "next field ${t}"
27e829d0
AC
163
164 gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
27d3a1a2 165 gdb_test_no_output "set variable u = F_${t}"
27e829d0
AC
166 gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
167
27d3a1a2 168 gdb_test_no_output "set variable u = F_${t}, u.i = f_${t}.i"
27e829d0
AC
169 gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
170
27d3a1a2 171 gdb_test_no_output "set variable u = F_${t}, u.j = f_${t}.j"
27e829d0
AC
172 gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
173
27d3a1a2 174 gdb_test_no_output "set variable u = F_${t}, u.k = f_${t}.k"
27e829d0
AC
175 gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
176
27d3a1a2 177 gdb_test_no_output "set variable u = f_${t}, u.i = F_${t}.i"
27e829d0
AC
178 gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
179
27d3a1a2 180 gdb_test_no_output "set variable u = f_${t}, u.j = F_${t}.j"
27e829d0
AC
181 gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
182
27d3a1a2 183 gdb_test_no_output "set variable u = f_${t}, u.k = F_${t}.k"
27e829d0
AC
184 gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
185
186}
187
188check_field 1
189check_field 2
190check_field 3
191check_field 4
192
193#
194
195# WANTED: A fairly portable way of convincing the compiler to split a
196# value across memory and registers.
197