1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2002-2004, 2007-2012 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/>.
23 # test running programs
27 set srcfile ${testfile}.c
28 set binfile ${objdir}/${subdir}/${testfile}
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 if [get_compiler_info ${binfile}] {
40 gdb_reinitialize_dir $srcdir/$subdir
44 # set it up at a breakpoint so we can play with the variable values
47 if ![runto_main] then {
48 perror "couldn't run to breakpoint"
54 proc check_set { t l r new add } {
55 set prefix "var ${t} l"
56 gdb_test "tbreak wack_${t}"
57 gdb_test "continue" "register ${t} l = u, r = v;" \
58 "continue to wack_${t}"
59 gdb_test "next" "l = add_${t} .l, r.;" \
60 "${prefix}; next ${t}"
61 gdb_test "print l" " = ${l}" \
62 "${prefix}; print old l, expecting ${l}"
63 gdb_test "print r" " = ${r}" \
64 "${prefix}; print old r, expecting ${r}"
65 gdb_test_no_output "set variable l = 4" \
66 "${prefix}; setting l to 4"
67 gdb_test "print l" " = ${new}" \
68 "${prefix}; print new l, expecting ${new}"
69 gdb_test "next" "return l \\+ r;" \
70 "${prefix}; next over add call"
71 gdb_test "print l" " = ${add}" \
72 "${prefix}; print incremented l, expecting ${add}"
75 check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
76 check_set "short" "-1" "-2" "4" "2"
77 check_set "int" "-1" "-2" "4" "2"
78 check_set "long" "-1" "-2" "4" "2"
79 check_set "longest" "-1" "-2" "4" "2"
80 check_set "float" "-1" "-2" "4" "2"
81 check_set "double" "-1" "-2" "4" "2"
82 check_set "doublest" "-1" "-2" "4" "2"
86 proc up_set { t l r new } {
87 set prefix "upvar ${t} l"
88 gdb_test "tbreak add_${t}"
89 gdb_test "continue" "return u . v;" \
90 "continue to add_${t}"
91 gdb_test "up" "l = add_${t} .l, r.;" \
93 gdb_test "print l" " = ${l}" \
94 "${prefix}; print old l, expecting ${l}"
95 gdb_test "print r" " = ${r}" \
96 "${prefix}; print old r, expecting ${r}"
97 gdb_test_no_output "set variable l = 4" \
98 "${prefix}; set l to 4"
99 gdb_test "print l" " = ${new}" \
100 "${prefix}; print new l, expecting ${new}"
103 up_set "charest" "-1 .*" "-2 .*" "4 ..004."
104 up_set "short" "-1" "-2" "4"
105 up_set "int" "-1" "-2" "4"
106 up_set "long" "-1" "-2" "4"
107 up_set "longest" "-1" "-2" "4"
108 up_set "float" "-1" "-2" "4"
109 up_set "double" "-1" "-2" "4"
110 up_set "doublest" "-1" "-2" "4"
114 proc check_struct { t old new } {
115 set prefix "var struct ${t} u"
116 gdb_test "tbreak wack_struct_${t}"
117 gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \
118 "continue to wack_struct_${t}"
119 gdb_test "next 2" "add_struct_${t} .u.;" \
120 "${prefix}; next to add_struct_${t} call"
121 gdb_test "print u" " = ${old}" \
122 "${prefix}; print old u, expecting ${old}"
123 gdb_test_no_output "set variable u = s_${t}" \
124 "${prefix}; set u to s_${t}"
125 gdb_test "print u" " = ${new}" \
126 "${prefix}; print new u, expecting ${new}"
129 check_struct "1" "{s = \\{0}}" "{s = \\{1}}"
130 check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
131 check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
132 check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
134 proc up_struct { t old new } {
135 set prefix "up struct ${t} u"
136 gdb_test "tbreak add_struct_${t}"
137 gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
138 "continue to add_struct_${t}"
139 gdb_test "up" "u = add_struct_${t} .u.;" \
141 gdb_test "print u" " = ${old}" \
142 "${prefix}; print old u, expecting ${old}"
143 gdb_test_no_output "set variable u = s_${t}" \
144 "${prefix}; set u to s_${t}"
145 gdb_test "print u" " = ${new}" \
146 "${prefix}; print new u, expecting ${new}"
149 up_struct "1" "{s = \\{0}}" "{s = \\{1}}"
150 up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
151 up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
152 up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
156 proc check_field { t } {
158 gdb_test "tbreak wack_field_${t}"
159 gdb_test "continue" "register struct f_${t} u = f_${t};" \
160 "continue field ${t}"
162 # Match either the return statement, or the line immediatly after
163 # it. The compiler can end up merging the return statement into
164 # the return instruction.
165 gdb_test "next" "(return u;|\})" "next field ${t}"
167 gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
168 gdb_test_no_output "set variable u = F_${t}"
169 gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
171 gdb_test_no_output "set variable u = F_${t}, u.i = f_${t}.i"
172 gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
174 gdb_test_no_output "set variable u = F_${t}, u.j = f_${t}.j"
175 gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
177 gdb_test_no_output "set variable u = F_${t}, u.k = f_${t}.k"
178 gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
180 gdb_test_no_output "set variable u = f_${t}, u.i = F_${t}.i"
181 gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
183 gdb_test_no_output "set variable u = f_${t}, u.j = F_${t}.j"
184 gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
186 gdb_test_no_output "set variable u = f_${t}, u.k = F_${t}.k"
187 gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
198 # WANTED: A fairly portable way of convincing the compiler to split a
199 # value across memory and registers.