]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/altivec-abi.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / altivec-abi.exp
1 # Copyright (C) 2002-2016 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 ABI
18
19
20 #
21 # This file uses altivec-abi.c for input.
22 #
23
24 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
25 verbose "Skipping altivec abi tests."
26 return
27 }
28
29 set testfile "altivec-abi"
30 set binfile ${objdir}/${subdir}/${testfile}
31 set srcfile ${testfile}.c
32
33 if [get_compiler_info] {
34 warning "get_compiler failed"
35 return -1
36 }
37
38 proc altivec_abi_tests { extra_flags force_abi } {
39 global testfile binfile srcfile srcdir subdir
40 global gdb_prompt
41
42 set compile_flags "debug nowarnings $extra_flags"
43
44 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
45 untested altivec-abi.exp
46 return -1
47 }
48
49 if { "$force_abi" == "auto" } {
50 # If the toolchain does not record attributes, skip auto-ABI tests.
51 set readelf_program [gdb_find_readelf]
52 set result [catch "exec $readelf_program -A $binfile" output]
53
54 if {$result == 0 && ![regexp Tag_GNU_Power_ABI_Vector $output]} {
55 untested "ABI not marked"
56 return
57 }
58 }
59
60 gdb_exit
61 gdb_start
62 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_load ${binfile}
64
65 # Run to `main' where we begin our tests.
66 if ![runto_main] then {
67 untested altivec-abi.exp
68 return -1
69 }
70
71 gdb_test "set print frame-arguments all"
72 gdb_test "set powerpc vector-abi $force_abi"
73
74 gdb_test "b marker" "Breakpoint 2 at.*file.*altivec-abi.c, line \[0-9\]+." "break marker"
75 gdb_test "continue" "Breakpoint 2.*marker.*altivec-abi.c.*" "continue to marker"
76 gdb_test "finish" "Run till exit from .0.*marker.*at.*altivec-abi.c.*main \\(\\) at.*altivec-abi.c.*result = vec_func \\(vshort,.*goes in v2.*" "back to main (1)"
77
78 # now all the arguments of vec_fun are initialized
79
80 set pattern "vec_func .vshort_f=.111, 222, 333, 444, 555, 666, 777, 888., vushort_f=.100, 200, 300, 400, 500, 600, 700, 800., vint_f=.-10, -20, -30, -40., vuint_f=.1111, 2222, 3333, 4444., vchar_f=.97, 98, 99, 100, 101, 102, 103, 104, 105, 108, 109, 110, 111, 112, 113, 114., vuchar_f=.65, 66, 67, 68, 69, 70, 71, 72, 73, 76, 77, 78, 79, 80, 81, 82., vfloat_f=.1.25, 3.75, 5.5, 1.25., x_f=.1, 2, 3, 4, 5, 6, 7, 8., y_f=.12, 22, 32, 42., a_f=.118, 101, 99, 116, 111, 114, 32, 111, 102, 32, 99, 104, 97, 114, 115, 46., b_f=.5.5, 4.5, 3.75, 2.25., c_f=.1.25, 3.5, 5.5, 7.75., intv_on_stack_f=.12, 34, 56, 78.."
81
82 set pattern1 $pattern
83 append pattern1 " at.*altivec-abi.c.*vint_res = vec_add.*vint_f, intv_on_stack_f.;"
84
85 # Now let's call the function. This function has > 12 args,
86 # the last one will go on the stack.
87 set msg "call inferior function with vectors (1)"
88 gdb_test "p vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack)" \
89 ".\[0-9\]+ = .14, 36, 58, 80." "call inferior function with vectors (1)"
90
91
92 # Let's call the function again with dummy arguments. This is to clean
93 # up the contents of the vector registers before the next call.
94 gdb_test "p vec_func(vshort_d,vushort_d,vint_d,vuint_d,vchar_d,vuchar_d,vfloat_d,x_d,y_d,a_d,b_d,c_d,intv_on_stack_d)" \
95 ".\[0-9\]+ = .0, 0, 0, 0." "call inferior function with vectors (2)"
96
97 # Attempt to take address of the return value of vec_func.
98 gdb_test "p &vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack)" \
99 "Attempt to take address of value not located in memory." \
100 "Attempt to take address of the return value of vec_func"
101
102 # Attempt to assign a value to the return value of vec_func.
103 gdb_test "set variable vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack) = {0,1,2,3}" \
104 "Left operand of assignment is not an lvalue." \
105 "Attempt to assign a value to the return value of vec_func"
106
107 # Let's step into the function, to see if the args are printed correctly.
108 gdb_test "step" \
109 $pattern1 \
110 "step into vec_fun"
111
112 set pattern2 $pattern
113 append pattern2 " at.*altivec-abi.c.*main.*result = vec_func .vshort,.*goes in v2.*Value returned is.*= .14, 36, 58, 80."
114
115 # Let's see if the result is returned correctly.
116 set message "vector value returned correctly"
117 gdb_test_multiple "finish" $message {
118 -re "Run till exit from .0.*$pattern2.*$gdb_prompt $" {
119 pass $message
120 }
121 -re "Run till exit from .0.*Cannot determine contents.*$gdb_prompt $" {
122 # This happens in those cases where the vector is returned by
123 # reference (generic vectors on 64-bit GNU/Linux).
124 pass $message
125 }
126 }
127
128 # can we print the args correctly for this function?
129 gdb_test "break struct_of_vector_func" "" ""
130
131 set pattern "struct_of_vector_func .vector_struct=.vshort1 = .1, 2, 3, 4, 5, 6, 7, 8., vshort2 = .11, 12, 13, 14, 15, 16, 17, 18., vshort3 = .21, 22, 23, 24, 25, 26, 27, 28., vshort4 = .31, 32, 33, 34, 35, 36, 37, 38... at.*altivec-abi.c.*"
132
133 gdb_test "continue" \
134 "Breakpoint 3, $pattern.*vector_struct.vshort1 = vec_add .vector_struct.vshort1, vector_struct.vshort2.;" \
135 "continue to struct_of_vector_func"
136
137 gdb_test "finish" \
138 "Run till exit from .0 $pattern\[ \r\n\]+main.*altivec-abi.c.*array_of_vector_func.*" \
139 "back to main (2)"
140
141 gdb_test "step" "" "step into array_of_vector_func"
142 gdb_test "p matrix\[0\]" ".*= .1, 2, 3, 4, 5, 6, 7, 8." "print first vector"
143 gdb_test "p matrix\[1\]" ".*= .11, 12, 13, 14, 15, 16, 17, 18." "print second vector"
144 gdb_test "p matrix\[2\]" ".*= .21, 22, 23, 24, 25, 26, 27, 28." "print third vector"
145 gdb_test "p matrix\[3\]" ".*= .31, 32, 33, 34, 35, 36, 37, 38." "print fourth vector"
146 }
147
148 if [test_compiler_info gcc*] {
149 with_test_prefix "default ABI, auto" {
150 altivec_abi_tests "additional_flags=-maltivec" "auto"
151 }
152
153 # On GNU/Linux, we can mix -mabi=no-altivec and -mabi=altivec.
154 # So test some combinations.
155 if { [istarget "powerpc*-linux*"] } {
156 # On 64-bit GNU/Linux with GCC 4.1 and 4.2, -mabi=no-altivec
157 # was broken, so skip those tests there.
158 if { ![is_lp64_target] || ![test_compiler_info "gcc-4-\[12\]-*"] } {
159 set binfile ${objdir}/${subdir}/${testfile}-ge-ge
160 with_test_prefix "generic ABI, forced" {
161 altivec_abi_tests "additional_flags=-maltivec additional_flags=-mabi=no-altivec" "generic"
162 }
163
164 set binfile ${objdir}/${subdir}/${testfile}-ge-auto
165 with_test_prefix "generic ABI, auto" {
166 altivec_abi_tests "additional_flags=-maltivec additional_flags=-mabi=no-altivec" "auto"
167 }
168 }
169
170 set binfile ${objdir}/${subdir}/${testfile}-av-av
171 with_test_prefix "AltiVec ABI, forced" {
172 altivec_abi_tests "additional_flags=-maltivec additional_flags=-mabi=altivec" "altivec"
173 }
174
175 set binfile ${objdir}/${subdir}/${testfile}-av-auto
176 with_test_prefix "AltiVec ABI, auto" {
177 altivec_abi_tests "additional_flags=-maltivec additional_flags=-mabi=altivec" "auto"
178 }
179 }
180 } elseif [test_compiler_info xlc*] {
181 altivec_abi_tests "additional_flags=-qaltivec" "auto"
182 } else {
183 warning "unknown compiler"
184 return -1
185 }