Commit | Line | Data |
---|---|---|
7634bb6e | 1 | # Copyright 2002, 2003 Free Software Foundation, Inc. |
27e829d0 AC |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@gnu.org | |
19 | ||
20 | if $tracelevel { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
24 | # | |
25 | # test running programs | |
26 | # | |
27 | set prms_id 0 | |
28 | set bug_id 0 | |
29 | ||
30 | set testfile "store" | |
31 | set srcfile ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
34 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
35 | } | |
36 | ||
37 | if [get_compiler_info ${binfile}] { | |
38 | return -1; | |
39 | } | |
40 | ||
41 | gdb_exit | |
42 | gdb_start | |
43 | gdb_reinitialize_dir $srcdir/$subdir | |
44 | gdb_load ${binfile} | |
45 | ||
46 | # | |
47 | # set it up at a breakpoint so we can play with the variable values | |
48 | # | |
49 | ||
50 | if ![runto_main] then { | |
51 | perror "couldn't run to breakpoint" | |
52 | continue | |
53 | } | |
54 | ||
55 | # | |
56 | ||
81a58f5b | 57 | proc check_set { t l r new add } { |
27e829d0 AC |
58 | global gdb_prompt |
59 | gdb_test "tbreak wack_${t}" | |
81a58f5b AC |
60 | gdb_test "continue" "register ${t} l = u, r = v;" "continue to wack_${t}" |
61 | gdb_test "next" "l = add_${t} .l, r.;" "next ${t}" | |
62 | gdb_test "print l" " = ${l}" "print old l - ${t}" | |
63 | gdb_test "print r" " = ${r}" "print old r - ${t}" | |
27e829d0 | 64 | gdb_test "set variable l = 4" |
81a58f5b | 65 | gdb_test "print l" " = ${new}" "print new l - ${t}" |
3a871b37 | 66 | gdb_test "next" "return l \\+ r;" |
81a58f5b | 67 | gdb_test "print l" " = ${add}" "print add - ${t}" |
27e829d0 AC |
68 | } |
69 | ||
3a871b37 | 70 | check_set "charest" "-1 .*" "-2 .*" "4 ..004." "2 ..002." |
81a58f5b AC |
71 | check_set "short" "-1" "-2" "4" "2" |
72 | check_set "int" "-1" "-2" "4" "2" | |
73 | check_set "long" "-1" "-2" "4" "2" | |
74 | check_set "longest" "-1" "-2" "4" "2" | |
75 | check_set "float" "-1" "-2" "4" "2" | |
76 | check_set "double" "-1" "-2" "4" "2" | |
77 | check_set "doublest" "-1" "-2" "4" "2" | |
27e829d0 AC |
78 | |
79 | # | |
80 | ||
81a58f5b | 81 | proc up_set { t l r new } { |
27e829d0 AC |
82 | global gdb_prompt |
83 | gdb_test "tbreak add_${t}" | |
81a58f5b AC |
84 | gdb_test "continue" "return u . v;" "continue to add_${t}" |
85 | gdb_test "up" "l = add_${t} .l, r.;" "up ${t}" | |
86 | gdb_test "print l" " = ${l}" "up print old l - ${t}" | |
87 | gdb_test "print r" " = ${r}" "up print old r - ${t}" | |
27e829d0 | 88 | gdb_test "set variable l = 4" |
81a58f5b | 89 | gdb_test "print l" " = ${new}" "up print new l - ${t}" |
27e829d0 AC |
90 | } |
91 | ||
3a871b37 | 92 | up_set "charest" "-1 .*" "-2 .*" "4 ..004." |
81a58f5b AC |
93 | up_set "short" "-1" "-2" "4" |
94 | up_set "int" "-1" "-2" "4" | |
95 | up_set "long" "-1" "-2" "4" | |
96 | up_set "longest" "-1" "-2" "4" | |
97 | up_set "float" "-1" "-2" "4" | |
98 | up_set "double" "-1" "-2" "4" | |
99 | up_set "doublest" "-1" "-2" "4" | |
27e829d0 AC |
100 | |
101 | # | |
102 | ||
103 | proc check_struct { t old new } { | |
104 | global gdb_prompt | |
105 | gdb_test "tbreak wack_struct_${t}" | |
106 | gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \ | |
107 | "continue set struct ${t}" | |
108 | gdb_test "next 2" "add_struct_${t} .u.;" | |
109 | gdb_test "print u" " = ${old}" "old check struct ${t}" | |
110 | gdb_test "set variable u = s_${t}" | |
111 | gdb_test "print u" " = ${new}" "new check struct ${t}" | |
112 | } | |
113 | ||
7634bb6e DJ |
114 | check_struct "1" "{s = \\{0}}" "{s = \\{1}}" |
115 | check_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}" | |
116 | check_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}" | |
117 | check_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}" | |
27e829d0 AC |
118 | |
119 | proc up_struct { t old new } { | |
120 | global gdb_prompt | |
121 | gdb_test "tbreak add_struct_${t}" | |
122 | gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \ | |
123 | "continue up struct ${t}" | |
124 | gdb_test "up" "u = add_struct_${t} .u.;" "up struct ${t}" | |
125 | gdb_test "print u" " = ${old}" "old up struct ${t}" | |
126 | gdb_test "set variable u = s_${t}" | |
127 | gdb_test "print u" " = ${new}" "new up struct ${t}" | |
128 | } | |
129 | ||
7634bb6e DJ |
130 | up_struct "1" "{s = \\{0}}" "{s = \\{1}}" |
131 | up_struct "2" "{s = \\{0, 0}}" "{s = \\{1, 2}}" | |
132 | up_struct "3" "{s = \\{0, 0, 0}}" "{s = \\{1, 2, 3}}" | |
133 | up_struct "4" "{s = \\{0, 0, 0, 0}}" "{s = \\{1, 2, 3, 4}}" | |
27e829d0 AC |
134 | |
135 | # | |
136 | ||
137 | proc check_field { t } { | |
138 | global gdb_prompt | |
139 | gdb_test "tbreak wack_field_${t}" | |
140 | gdb_test "continue" "register struct f_${t} u = f_${t};" \ | |
141 | "continue field ${t}" | |
81a58f5b AC |
142 | |
143 | # Match either the return statement, or the line immediatly after | |
144 | # it. The compiler can end up merging the return statement into | |
145 | # the return instruction. | |
146 | gdb_test "next" "(return u;|\})" "next field ${t}" | |
27e829d0 AC |
147 | |
148 | gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}" | |
149 | gdb_test "set variable u = F_${t}" | |
150 | gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}" | |
151 | ||
152 | gdb_test "set variable u = F_${t}, u.i = f_${t}.i" | |
153 | gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i" | |
154 | ||
155 | gdb_test "set variable u = F_${t}, u.j = f_${t}.j" | |
156 | gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j" | |
157 | ||
158 | gdb_test "set variable u = F_${t}, u.k = f_${t}.k" | |
159 | gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k" | |
160 | ||
161 | gdb_test "set variable u = f_${t}, u.i = F_${t}.i" | |
162 | gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i" | |
163 | ||
164 | gdb_test "set variable u = f_${t}, u.j = F_${t}.j" | |
165 | gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j" | |
166 | ||
167 | gdb_test "set variable u = f_${t}, u.k = F_${t}.k" | |
168 | gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k" | |
169 | ||
170 | } | |
171 | ||
172 | check_field 1 | |
173 | check_field 2 | |
174 | check_field 3 | |
175 | check_field 4 | |
176 | ||
177 | # | |
178 | ||
179 | # WANTED: A fairly portable way of convincing the compiler to split a | |
180 | # value across memory and registers. | |
181 |