1 # Copyright 2009-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Contributed by Markus Deuling <deuling@de.ibm.com>.
18 # Support library for testing the combined debugger for Linux
19 # on the Cell Broadband Engine.
21 # Compile SPU objects.
22 proc gdb_compile_cell_spu {source dest type options} {
25 # Save and unset multilib flags; these are not appropriate
26 # for the SPU compiler.
27 set board [target_info name]
28 set save_multilib_flag [board_info $board multilib_flags]
29 unset_board_info "multilib_flags"
31 set options_spu [concat $options [list compiler=spu-gcc]]
32 set ccout [gdb_compile $source $dest $type $options_spu]
34 set_board_info multilib_flags $save_multilib_flag
38 # Compile PPU objects. This is just like gdb_compile_pthreads, except that we
39 # always add the libspe2 library for compiling Cell/B.E. programs.
40 proc gdb_compile_cell_ppu {source dest type options} {
41 # We do not need to try multiple names for the pthread library
42 # -lpthread works on all Cell/B.E. systems
43 set lib "-lspe2 -lpthread"
44 set options_ppu [concat $options [list libs=$lib]]
45 return [gdb_compile $source $dest $type $options_ppu]
48 # Embed SPU executable into a PPU object.
49 proc gdb_cell_embedspu {source dest options} {
52 if [info exists CC_FOR_TARGET] {
53 set compiler $CC_FOR_TARGET
55 set compiler [board_info [target_info name] compiler]
58 # We assume the PPU compiler is called gcc or ppu-gcc,
59 # and find the appropriate embedspu based on that.
60 regsub gcc "$compiler" embedspu embedspu
62 # Determine default embedded symbol name from source filename.
63 set path [split "$source" /]
64 set filename [lindex $path [expr [llength $path] - 1]]
65 regsub -all -- "\[-\.\]" "$filename" "_" symbol
67 set options_embed [concat $options [list compiler=$embedspu]]
68 return [gdb_compile "$symbol $source $dest" "" none $options_embed]
71 # Run a test on the target to see if it supports Cell/B.E. hardware.
72 # Return 0 if so, 1 if it does not.
73 gdb_caching_proc skip_cell_tests {
74 global srcdir subdir gdb_prompt inferior_exited_re
76 set me "skip_cell_tests"
78 # Set up, compile, and execute a combined Cell/B.E. test program.
79 # Include the current process ID in the file names to prevent conflicts
80 # with invocations for multiple testsuites.
81 set src [standard_temp_file cell[pid].c]
82 set exe [standard_temp_file cell[pid].x]
83 set src_spu [standard_temp_file cell[pid]-spu.c]
84 set exe_spu [standard_temp_file cell[pid]-spu.x]
87 puts $f "#include <libspe2.h>"
88 puts $f "extern spe_program_handle_t cell[pid]_spu_x;"
89 puts $f "int main (void) {"
90 puts $f "unsigned int entry = SPE_DEFAULT_ENTRY;"
91 puts $f "spe_context_ptr_t ctx = spe_context_create (0, NULL);"
92 puts $f "spe_program_load (ctx, &cell[pid]_spu_x);"
93 puts $f "return spe_context_run (ctx, &entry, 0, NULL, NULL, NULL); }"
96 set f [open $src_spu "w"]
97 puts $f "int main (void) { return 0; }"
100 verbose "$me: compiling testfile $src" 2
101 set compile_flags {debug nowarnings quiet}
104 if { [gdb_compile_cell_spu $src_spu $exe_spu executable $compile_flags] != "" } {
105 verbose "$me: compiling spu binary failed, returning 1" 2
108 if { ! $skip && [gdb_cell_embedspu $exe_spu $exe_spu-embed.o $compile_flags] != "" } {
109 verbose "$me: embedding spu binary failed, returning 1" 2
112 if { ! $skip && [gdb_compile_cell_ppu [list $src $exe_spu-embed.o] $exe executable $compile_flags] != "" } {
113 verbose "$me: compiling ppu binary failed, returning 1" 2
119 file delete $exe_spu-embed.o
125 # Compilation succeeded so now run it via gdb.
129 gdb_reinitialize_dir $srcdir/$subdir
133 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
134 verbose -log "\n$me: Cell/B.E. hardware detected"
137 -re ".*$inferior_exited_re with code.*${gdb_prompt} $" {
138 verbose -log "\n$me: Cell/B.E. hardware not detected"
142 verbose -log "\n$me Cell/B.E. hardware not detected (default case)"
147 remote_file build delete $exe
149 verbose "$me: returning $result" 2
153 # Delete all breakpoints and stop on the next new SPU thread
154 proc cont_spu_main { } {
156 gdb_test "set spu stop-on-load on"
157 gdb_test "continue" \
158 "Continuing.*Temporary breakpoint .*main .*" \
159 "continue to SPU main"
163 proc c_to { marker srcfile } {
164 set line [gdb_get_line_number $marker $srcfile]
165 gdb_test "break $line" \
166 "Breakpoint.*at.*file.*$srcfile.*line $line.*" \
168 gdb_test "continue" \
169 "Continuing.*Breakpoint.*at.*$srcfile.*$line.*" \
173 # Check if the current thread has SPU architecture
174 proc check_spu_arch { msg } {
176 set msg "spu architecture is spu256K"
178 gdb_test "show architecture" \
179 "The target architecture is set automatically.*currently spu:256K.*" \