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