# Copyright 2002, 2004 # 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. # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@prep.ai.mit.edu # This file was written by Jason Molenda (jmolenda@apple.com) if $tracelevel then { strace $tracelevel } # Test an executable with a weak library. A "weak library" is unlike any # ELF thing; if all externally visible functions in a shared library are # marked as "weak" in their prototypes in a C file, then when that executable # is run, the shared library may be absent and the program will still work. # (as oppposed to the normal case, where you'd get an unresolved shared library # reference from the dynamic linker run-time). All the addresses of the # functions from the shared library will have a value of 0 in this case. set timeout 30 set prms_id 0 set bug_id 0 set testfile "weak-prog" set binfile ${objdir}/${subdir}/${testfile} set srcfile ${srcdir}/${subdir}/${testfile}.c set libfile "libweak" set libbinfile ${objdir}/${subdir}/${libfile}.dylib set libsrcfile ${srcdir}/${subdir}/${libfile}.c set additional_flags "additional_flags=-dynamiclib" if { [gdb_compile "${libsrcfile}" "${libbinfile}" executable [list debug $additional_flags]] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } global env set ::env(MACOSX_DEPLOYMENT_TARGET) "10.2" set additional_flags "additional_flags=-L${objdir}/${subdir} -lweak" if { [gdb_compile "${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } # Start with a fresh gdb gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_file_cmd "${binfile}" gdb_test "future-break foo" "Breakpoint 1 at $hex: file .*libweak.c.*, line $decimal." "Set breakpoint on foo" gdb_test "run" \ "Starting program: $binfile\[ \r\]* Reading symbols for shared libraries \[+\\.]+ done\[ \r\]* Breakpoint 1 at $hex: file .*libweak.c.*, line $decimal.\[ \r\]* hi, in main\[ \r\]* \[ \r\]* Breakpoint 1, foo.*libweak.c.*\[ \r\]*" \ "continue to weak library bp" gdb_test "info sharedlibrary" "$decimal libweak.dylib *- $hex *dyld Y Y $libbinfile at $hex \\(offset $hex\\).*" gdb_exit # Now move the library aside, try again remote_exec build "mv ${libbinfile} ${libbinfile}.hide" gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_test "file ${binfile}" "Reading symbols for shared libraries \\.+ done\r\nReading symbols from ${binfile}\\.+done.\[\r\n\]+" "load with missing weak lib, hope for no warnings" gdb_test "info sharedlibrary" ".*$decimal libweak.dylib *- - *w-init Y ! ${libbinfile}.*" "check sharedlibrary entry for missing weak library pre-run" gdb_test "future-break foo" "Function \"foo\" not defined..*Breakpoint 1 .foo. pending.*" "Set breakpoint on foo (2), not yet defined" send_gdb "run\n" gdb_expect { -re "Starting program: $binfile \[\r\n\]+\[\r\n\]+(Reading symbols for shared libraries (\\.)+ done\[\r\n\]+)+hi, in main\[\r\n\]+finished in main\[\r\n\]+Program exited with code $decimal\\.\[\r\n\]+$gdb_prompt $" { pass "test running weak program" } -re ".*$gdb_prompt $" { fail "test running weak program" } timeout { fail "(timeout) test running weak program" } } gdb_test "info sharedlibrary" ".*$decimal libweak.dylib *- - *c-w-init Y ! ${libbinfile}.*" "check sharedlibrary entry for missing weak library post-run" gdb_exit return 0