1# Copyright 2006, 2007 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# Test setting breakpoints on shared library functions provided by more 17# than one shared library, when one of the implementations is a "weak" 18# symbol. GDB should set a breakpoint at the first copy it finds. 19 20if {[skip_shlib_tests]} { 21 return 0 22} 23 24# These targets have shared libraries, but weak symbols are not meaningful. 25if {([istarget arm*-*-symbianelf*] 26 || [istarget *-*-mingw*] 27 || [istarget *-*-cygwin*] 28 || [istarget *-*-pe*])} { 29 return 0 30} 31 32# This test uses GCC-specific syntax. 33if [get_compiler_info not-used] { 34 return -1 35} 36 37if {![test_compiler_info "gcc-*"]} { 38 return 0 39} 40 41proc do_test { lib1opts lib2opts lib1first } { 42 global objdir srcdir subdir 43 44 set testopts "" 45 if {$lib1opts == ""} { 46 append testopts "lib1 nodebug, " 47 } else { 48 append testopts "lib1 debug, " 49 } 50 if {$lib2opts == ""} { 51 append testopts "lib2 nodebug, " 52 } else { 53 append testopts "lib2 debug, " 54 } 55 if {$lib1first} { 56 append testopts "lib1 first" 57 } else { 58 append testopts "lib2 first" 59 } 60 61 set testfile "solib-weak" 62 set srcfile ${testfile}.c 63 set binfile ${objdir}/${subdir}/${testfile} 64 65 set libfile1 "weaklib1" 66 set libfile2 "weaklib2" 67 set lib1src ${srcdir}/${subdir}/${libfile1}.c 68 set lib2src ${srcdir}/${subdir}/${libfile2}.c 69 set lib1 ${objdir}/${subdir}/${libfile1}.sl 70 set lib2 ${objdir}/${subdir}/${libfile2}.sl 71 72 if $lib1first { 73 set exec_opts [list debug shlib=${lib1} shlib=${lib2}] 74 set expected_file ${libfile1} 75 } else { 76 set exec_opts [list debug shlib=${lib2} shlib=${lib1}] 77 set expected_file ${libfile2} 78 } 79 80 if { [gdb_compile_shlib ${lib1src} ${lib1} ${lib1opts}] != "" 81 || [gdb_compile_shlib ${lib2src} ${lib2} ${lib2opts}] != "" 82 || [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable $exec_opts] != ""} { 83 return -1 84 } 85 86 gdb_exit 87 gdb_start 88 gdb_reinitialize_dir $srcdir/$subdir 89 gdb_load ${binfile} 90 gdb_load_shlibs $lib1 $lib2 91 92 runto_main 93 94 gdb_breakpoint "bar" 95 96 # If the library which will be used is compiled without debugging 97 # information, GDB will pick the wrong copy of "bar", i.e. the one 98 # with debugging information. 99 100 if {(${lib1opts} == "" && ${lib2opts} != "" && ${lib1first} == 1) 101 || (${lib1opts} != "" && ${lib2opts} == "" && ${lib1first} == 0)} { 102 setup_kfail *-*-* gdb/1824 103 } 104 105 gdb_test "continue" "Breakpoint .* bar .*${expected_file}\\..*" \ 106 "run to breakpoint - $testopts" 107} 108 109foreach lib1opts {{} {debug}} { 110 foreach lib2opts {{} {debug}} { 111 foreach lib1first {1 0} { 112 do_test $lib1opts $lib2opts $lib1first 113 } 114 } 115} 116