Fix for PR gdb/1543.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.arch / altivec-regs.exp
1 # Copyright (C) 2002, 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
15 #
16
17 # Tests for Powerpc AltiVec register setting and fetching
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 #
24 # Test the use of registers, especially AltiVec registers, for Powerpc.
25 # This file uses altivec-regs.c for input.
26 #
27
28 set prms_id 0
29 set bug_id 0
30
31 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
32 verbose "Skipping altivec register tests."
33 verbose -log "Skipping altivec register tests."
34 return
35 }
36
37 set testfile "altivec-regs"
38 set binfile ${objdir}/${subdir}/${testfile}
39 set srcfile ${testfile}.c
40
41 set compile_flags {debug nowarnings}
42 if [get_compiler_info $binfile] {
43 warning "get_compiler failed"
44 return -1
45 }
46
47 if [test_compiler_info gcc*] {
48 set compile_flags "$compile_flags additional_flags=-maltivec additional_flags=-mabi=altivec"
49 } elseif [test_compiler_info xlc*] {
50 set compile_flags "$compile_flags additional_flags=-qaltivec"
51 } else {
52 warning "unknown compiler"
53 return -1
54 }
55
56 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
57 untested altivec-regs.exp
58 return -1
59 }
60
61 gdb_start
62 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_load ${binfile}
64
65 #
66 # Run to `main' where we begin our tests.
67 #
68
69 if ![runto_main] then {
70 gdb_suppress_tests
71 }
72
73 # set all the registers integer portions to 1
74 for {set i 0} {$i < 32} {incr i 1} {
75 for {set j 0} {$j < 4} {incr j 1} {
76 gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]"
77 }
78 }
79
80 gdb_test "set \$vscr = 1" "" ""
81 gdb_test "set \$vrsave = 1" "" ""
82
83 # Now execute some target code, so that GDB's register cache is flushed.
84
85 gdb_test "next" "" ""
86
87 send_gdb "show endian\n"
88 set endianness ""
89 gdb_expect {
90 -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
91 pass "endianness"
92 set endianness $expect_out(2,string)
93 }
94 -re ".*$gdb_prompt $" {
95 fail "couldn't get endianness"
96 }
97 timeout { fail "(timeout) endianness" }
98 }
99
100 # And then read the AltiVec registers back, to see that
101 # a) the register write above worked, and
102 # b) the register read (below) also works.
103
104 if {$endianness == "big"} {
105 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.."
106 } else {
107 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.."
108 }
109
110 for {set i 0} {$i < 32} {incr i 1} {
111 gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i"
112 }
113
114 gdb_test "info reg vrsave" "vrsave.*0x1\t1" "info reg vrsave"
115 gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr"
116
117 # Now redo the same tests, but using the print command.
118 # Note: in LE case, the char array is printed WITHOUT the last character.
119 # Gdb treats the terminating null char in the array like the terminating
120 # null char in a string and doesn't print it. This is not a failure, but
121 # the way gdb works.
122
123 if {$endianness == "big"} {
124 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .0, 1, 0, 1, 0, 1, 0, 1., v16_int8 = .0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1.."
125 } else {
126 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .1, 0, 1, 0, 1, 0, 1, 0., v16_int8 = .1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.."
127 }
128
129 for {set i 0} {$i < 32} {incr i 1} {
130 gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
131 }
132
133 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
134 gdb_test "print \$vscr" ".* = 1" "print vscr"
135
136 for {set i 0} {$i < 32} {incr i 1} {
137 set pattern$i ".*vr$i.*"
138 append pattern$i $vector_register
139 }
140
141 send_gdb "info vector\n"
142 gdb_expect_list "info vector" ".*$gdb_prompt $" {
143 [$pattern0]
144 [$pattern1]
145 [$pattern2]
146 [$pattern3]
147 [$pattern4]
148 [$pattern5]
149 [$pattern6]
150 [$pattern7]
151 [$pattern8]
152 [$pattern9]
153 [$pattern10]
154 [$pattern11]
155 [$pattern12]
156 [$pattern13]
157 [$pattern14]
158 [$pattern15]
159 [$pattern16]
160 [$pattern17]
161 [$pattern18]
162 [$pattern19]
163 [$pattern20]
164 [$pattern21]
165 [$pattern22]
166 [$pattern23]
167 [$pattern24]
168 [$pattern25]
169 [$pattern26]
170 [$pattern27]
171 [$pattern28]
172 [$pattern29]
173 [$pattern30]
174 [$pattern31]
175 "\[ \t\n\r\]+vscr\[ \t\]+0x1"
176 "\[ \t\n\r\]+vrsave\[ \t\]+0x1"
177 }
178
179 gdb_test "break vector_fun" \
180 "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
181 "Set breakpoint at vector_fun"
182
183 # Actually it is nuch easier to see these results printed in hex.
184 gdb_test "set output-radix 16" \
185 "Output radix now set to decimal 16, hex 10, octal 20." \
186 "Set output radix to hex"
187
188 gdb_test "continue" \
189 "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \
190 "continue to vector_fun"
191
192 # Do a next over the assignment to vector 'a'.
193 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
194 "next (1)"
195
196 # Do a next over the assignment to vector 'b'.
197 gdb_test "next" "c = vec_add \\(a, b\\);" \
198 "next (2)"
199
200 # Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...'
201 gdb_test "print/x a" \
202 ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \
203 "print vector parameter a"
204
205 gdb_test "print/x b" \
206 ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
207 "print vector parameter b"
208
209 # If we do an 'up' now, and print 'x' and 'y' we should see the values they
210 # have in main, not the values they have in vector_fun.
211 gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \
212 "up to main"
213
214 gdb_test "print/x x" \
215 ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
216 "print vector x"
217
218 gdb_test "print/x y" \
219 ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
220 "print vector y"
221
222 # now go back to vector_func and do a finish, to see if we can print the return
223 # value correctly.
224
225 gdb_test "down" \
226 ".0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
227 "down to vector_fun"
228
229 gdb_test "finish" \
230 "Run till exit from .0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*in main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);.*Value returned is.*= .0x5050505, 0x5050505, 0x5050505, 0x5050505." \
231 "finish returned correct value"
232
233
234
This page took 0.03634 seconds and 4 git commands to generate.