# Copyright 2005 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # We added a "-arch" option to gdb to allow you to run the 32 bit side of a Universal # binary on a machine which would ordinarily run the 32 bit version. # This tests that. set using_dsym 0 foreach x $board_variant_list { if {$x == ""} { continue } switch $x { dsym {set using_dsym 1} default {} } } if {$using_dsym} { gdb_suppress_entire_file "This test doesn't work when forcing dsym testing" return 0 } if {[istarget "powerpc-apple-darwin*"]} { set arch_name(32) "ppc" set arch_name(64) "ppc64" } elseif {[istarget "i686-apple-darwin*"]} { set arch_name(32) "i386" set arch_name(64) "x86_64" } else { puts "Unsupported architecture" return } set testfile arch-test set srcfile $testfile.c set binfile $objdir/$subdir/$testfile set arches [list ppc i386 ppc64 x86_64] # We need to take the -arch whatever flags out of the cflags, or we will # be building each time for two architectures. # Be sure to put it back when we are done. if {[board_info target exists cflags]} { set old_board_flags [board_info target cflags] regsub -- {-arch *[^ ]*} $old_board_flags {} new_board_flags unset_currtarget_info cflags set_currtarget_info cflags $new_board_flags set put_cflags_back 1 } else { set pub_cflags_back 0 } foreach arch $arches { set additional_flags "additional_flags=-arch\\ $arch" if { [gdb_compile "$srcdir/$subdir/$testfile.c" "$binfile-$arch.o" object "debug $additional_flags"] != "" } { gdb_suppress_entire_file "Testcase compile failed for arch $arch in $test_name, so all tests in this file will automatically fail." } if { [gdb_compile "$binfile-$arch.o" "$binfile-$arch" executable "debug $additional_flags"] != "" } { gdb_suppress_entire_file "Testcase compile failed for arch $arch in $test_name, so all tests in this file will automatically fail." } } if {$put_cflags_back == 1} { unset_currtarget_info cflags set_currtarget_info cflags $old_board_flags } set command "lipo -create -output \"$binfile\"" foreach arch $arches { set command "$command -arch $arch \"$binfile-$arch\"" } set status [remote_exec host $command] if {[lindex $status 0] != 0} { puts [lindex $status 1] gdb_suppress_entire_file "lipo command failed for $test_name, so all tests in this file will automatically fail." } # Make sure we get an error if we try to set arch to 64 on a file that only has 32 bit. gdb_exit gdb_start "--arch $arch_name(32)" gdb_reinitialize_dir $srcdir/$subdir gdb_test "file $binfile-$arch_name(64)" \ ".*Architecture of file.*does not match user selected architecture.*" \ "Got an error passing the wrong architecture" # This tests that we can run BITSIZE side of the Universal binary. # Test both values of START_WITH_SHELL, since "0" uses posix_spawn and "1" uses "exec arch". proc run_one_test {bitsize start_with_shell} { global GDBFLAGS global srcdir srcfile subdir binfile arch_name global gdb_prompt hex gdb_exit set this_test "$bitsize bit start-with-shell: $start_with_shell" gdb_start "--arch $arch_name($bitsize)" gdb_reinitialize_dir $srcdir/$subdir gdb_file_cmd "$binfile" send_gdb "set width 0\n" gdb_expect -re "$gdb_prompt \$" gdb_test "set start-with-shell $start_with_shell" "" "$this_test: set start-with-shell" gdb_test "set env FROM_GDB passed" "" "$this_test: set FROM_GDB environment variable" gdb_test "set arg this that" "" "$this_test set args" gdb_test "break [gdb_get_line_number {Good place to put a breakpoint}]" \ "Breakpoint 1 at $hex: file.*, line.*\\." \ "$this_test: Set breakpoint on line 'Good place to put a breakpoint'" gdb_test "run" "Starting program: $binfile this that *\r\n\.*Reading symbols for shared libraries \(\[.+\]\)+ done.*I am $bitsize bit.*Breakpoint 1, main.*" \ "$this_test: run to \"Good place to put a breakpoint\"" gdb_test {print argc} {\$[0-9]+ = 3} "$this_test: Make sure both arguments got passed." gdb_test {print argv[1]} {\$[0-9]+ = .* "this"} "$this_test: argv\[1\] == this" gdb_test {show env FROM_GDB} {FROM_GDB = passed} "$this_test: Make sure environ got passed." } run_one_test 32 0 run_one_test 32 1 run_one_test 64 0 run_one_test 64 1