1 # This testcase is part of GDB
, the GNU debugger.
3 # Copyright
2002, 2003, 2004 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
2 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
, write to the Free Software
17 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
24 # test running programs
30 set srcfile $
{testfile
}.c
31 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
32 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
36 if [get_compiler_info $
{binfile
}] {
42 gdb_reinitialize_dir $srcdir
/$subdir
46 #
set it up at a breakpoint so we can play with the
variable values
49 if ![runto_main
] then {
50 perror
"couldn't run to breakpoint"
56 proc check_set
{ t l r new add
} {
57 set prefix
"var ${t} l"
58 gdb_test
"tbreak wack_${t}"
59 gdb_test
"continue" "register ${t} l = u, r = v;" \
60 "continue to wack_${t}"
61 gdb_test
"next" "l = add_${t} .l, r.;" \
62 "${prefix}; next ${t}"
63 gdb_test
"print l" " = ${l}" \
64 "${prefix}; print old l, expecting ${l}"
65 gdb_test
"print r" " = ${r}" \
66 "${prefix}; print old r, expecting ${r}"
67 gdb_test
"set variable l = 4" "" \
68 "${prefix}; setting l to 4"
69 gdb_test
"print l" " = ${new}" \
70 "${prefix}; print new l, expecting ${l}"
71 gdb_test
"next" "return l \\+ r;" \
72 "${prefix}; next over add call"
73 gdb_test
"print l" " = ${add}" \
74 "${prefix}; print incremented l, expecting ${add}"
77 check_set
"charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002."
78 check_set
"short" "-1" "-2" "4" "2"
79 check_set
"int" "-1" "-2" "4" "2"
80 check_set
"long" "-1" "-2" "4" "2"
81 check_set
"longest" "-1" "-2" "4" "2"
82 check_set
"float" "-1" "-2" "4" "2"
83 check_set
"double" "-1" "-2" "4" "2"
84 check_set
"doublest" "-1" "-2" "4" "2"
88 proc up_set
{ t l r new
} {
89 set prefix
"upvar ${t} l"
90 gdb_test
"tbreak add_${t}"
91 gdb_test
"continue" "return u . v;" \
92 "continue to add_${t}"
93 gdb_test
"up" "l = add_${t} .l, r.;" \
95 gdb_test
"print l" " = ${l}" \
96 "${prefix}; print old l, expecting ${l}"
97 gdb_test
"print r" " = ${r}" \
98 "${prefix}; print old r, expecting ${r}"
99 gdb_test
"set variable l = 4" "" \
100 "${prefix}; set l to 4"
101 gdb_test
"print l" " = ${new}" \
102 "${prefix}; print new l, expecting ${new}"
105 up_set
"charest" "-1 .*" "-2 .*" "4 ..004."
106 up_set
"short" "-1" "-2" "4"
107 up_set
"int" "-1" "-2" "4"
108 up_set
"long" "-1" "-2" "4"
109 up_set
"longest" "-1" "-2" "4"
110 up_set
"float" "-1" "-2" "4"
111 up_set
"double" "-1" "-2" "4"
112 up_set
"doublest" "-1" "-2" "4"
116 proc check_struct
{ t old new
} {
117 set prefix
"var struct ${t} u"
118 gdb_test
"tbreak wack_struct_${t}"
119 gdb_test
"continue" "int i; register struct s_${t} u = z_${t};" \
120 "continue to wack_struct_${t}"
121 gdb_test
"next 2" "add_struct_${t} .u.;" \
122 "${prefix}; next to add_struct_${t} call"
123 gdb_test
"print u" " = ${old}" \
124 "${prefix}; print old u, expecting ${old}"
125 gdb_test
"set variable u = s_${t}" "" \
126 "${prefix}; set u to s_${t}"
127 gdb_test
"print u" " = ${new}" \
128 "${prefix}; print new u, expecting ${new}"
131 check_struct
"1" "{s = \\{0}}" "{s = \\{1}}"
132 check_struct
"2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
133 check_struct
"3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
134 check_struct
"4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
136 proc up_struct
{ t old new
} {
137 set prefix
"up struct ${t} u"
138 gdb_test
"tbreak add_struct_${t}"
139 gdb_test
"continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \
140 "continue to add_struct_${t}"
141 gdb_test
"up" "u = add_struct_${t} .u.;" \
143 gdb_test
"print u" " = ${old}" \
144 "${prefix}; print old u, expecting ${old}"
145 gdb_test
"set variable u = s_${t}" "" \
146 "${prefix}; set u to s_${t}"
147 gdb_test
"print u" " = ${new}" \
148 "${prefix}; print new u, expecting ${new}"
151 up_struct
"1" "{s = \\{0}}" "{s = \\{1}}"
152 up_struct
"2" "{s = \\{0, 0}}" "{s = \\{1, 2}}"
153 up_struct
"3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}"
154 up_struct
"4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}"
158 proc check_field
{ t
} {
160 gdb_test
"tbreak wack_field_${t}"
161 gdb_test
"continue" "register struct f_${t} u = f_${t};" \
162 "continue field ${t}"
164 # Match either the
return statement
, or the line immediatly after
165 # it. The compiler can end up merging the
return statement into
166 # the
return instruction.
167 gdb_test
"next" "(return u;|\})" "next field ${t}"
169 gdb_test
"print u" " = {i = 1, j = 1, k = 1}" "old field ${t}"
170 gdb_test
"set variable u = F_${t}"
171 gdb_test
"print u" " = {i = 0, j = 0, k = 0}" "new field ${t}"
173 gdb_test
"set variable u = F_${t}, u.i = f_${t}.i"
174 gdb_test
"print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i"
176 gdb_test
"set variable u = F_${t}, u.j = f_${t}.j"
177 gdb_test
"print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j"
179 gdb_test
"set variable u = F_${t}, u.k = f_${t}.k"
180 gdb_test
"print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k"
182 gdb_test
"set variable u = f_${t}, u.i = F_${t}.i"
183 gdb_test
"print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i"
185 gdb_test
"set variable u = f_${t}, u.j = F_${t}.j"
186 gdb_test
"print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j"
188 gdb_test
"set variable u = f_${t}, u.k = F_${t}.k"
189 gdb_test
"print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k"
200 # WANTED
: A fairly portable way of convincing the compiler to split a
201 # value across memory and registers.