Home | History | Annotate | Line # | Download | only in gdb.base
solib-weak.exp revision 1.1
      1  1.1  christos #   Copyright 2006-2014 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # Test setting breakpoints on shared library functions provided by more
     17  1.1  christos # than one shared library, when one of the implementations is a "weak"
     18  1.1  christos # symbol.  GDB should set a breakpoint at the first copy it finds.
     19  1.1  christos 
     20  1.1  christos if {[skip_shlib_tests]} {
     21  1.1  christos     return 0
     22  1.1  christos }
     23  1.1  christos 
     24  1.1  christos # These targets have shared libraries, but weak symbols are not meaningful.
     25  1.1  christos if {([istarget arm*-*-symbianelf*]
     26  1.1  christos      || [istarget *-*-mingw*]
     27  1.1  christos      || [istarget *-*-cygwin*]
     28  1.1  christos      || [istarget *-*-pe*])} {
     29  1.1  christos     return 0
     30  1.1  christos }
     31  1.1  christos 
     32  1.1  christos # This test uses GCC-specific syntax.
     33  1.1  christos if [get_compiler_info] {
     34  1.1  christos     return -1
     35  1.1  christos }
     36  1.1  christos 
     37  1.1  christos if {![test_compiler_info "gcc-*"]} {
     38  1.1  christos     return 0
     39  1.1  christos }
     40  1.1  christos 
     41  1.1  christos proc do_test { lib1opts lib2opts lib1first } {
     42  1.1  christos     global srcdir subdir
     43  1.1  christos 
     44  1.1  christos     set testfile "solib-weak"
     45  1.1  christos     set srcfile ${testfile}.c
     46  1.1  christos 
     47  1.1  christos     set libfile1 "weaklib1"
     48  1.1  christos     set libfile2 "weaklib2"
     49  1.1  christos     set lib1src ${srcdir}/${subdir}/${libfile1}.c
     50  1.1  christos     set lib2src ${srcdir}/${subdir}/${libfile2}.c
     51  1.1  christos 
     52  1.1  christos     # Select a unique name for this test.  Give each library and
     53  1.1  christos     # executable a name reflecting its options, so that file caching
     54  1.1  christos     # on the target system does not pick up the wrong file.
     55  1.1  christos     set testopts ""
     56  1.1  christos     if {$lib1opts == ""} {
     57  1.1  christos 	append testopts "lib1 nodebug, "
     58  1.1  christos     } else {
     59  1.1  christos 	append testopts "lib1 debug, "
     60  1.1  christos 	append lib1 "-dbg"
     61  1.1  christos     }
     62  1.1  christos     if {$lib2opts == ""} {
     63  1.1  christos 	append testopts "lib2 nodebug, "
     64  1.1  christos     } else {
     65  1.1  christos 	append testopts "lib2 debug, "
     66  1.1  christos 	append lib2 "-dbg"
     67  1.1  christos     }
     68  1.1  christos     if {$lib1first} {
     69  1.1  christos 	append testopts "lib1 first"
     70  1.1  christos     } else {
     71  1.1  christos 	append testopts "lib2 first"
     72  1.1  christos 	append testfile "-lib2"
     73  1.1  christos     }
     74  1.1  christos 
     75  1.1  christos     set binfile [standard_output_file ${testfile}]
     76  1.1  christos     set lib1 [standard_output_file ${libfile1}.sl]
     77  1.1  christos     set lib2 [standard_output_file ${libfile2}.sl]
     78  1.1  christos 
     79  1.1  christos     if $lib1first {
     80  1.1  christos 	set exec_opts [list debug shlib=${lib1} shlib=${lib2}]
     81  1.1  christos 	set expected_file ${libfile1}
     82  1.1  christos     } else {
     83  1.1  christos 	set exec_opts [list debug shlib=${lib2} shlib=${lib1}]
     84  1.1  christos 	set expected_file ${libfile2}
     85  1.1  christos     }
     86  1.1  christos 
     87  1.1  christos     if { [gdb_compile_shlib ${lib1src} ${lib1} ${lib1opts}] != ""
     88  1.1  christos 	 || [gdb_compile_shlib ${lib2src} ${lib2} ${lib2opts}] != ""
     89  1.1  christos 	 || [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable $exec_opts] != ""} {
     90  1.1  christos 	return -1
     91  1.1  christos     }
     92  1.1  christos 
     93  1.1  christos     gdb_exit
     94  1.1  christos     gdb_start
     95  1.1  christos     gdb_reinitialize_dir $srcdir/$subdir
     96  1.1  christos     gdb_load ${binfile}
     97  1.1  christos     gdb_load_shlibs $lib1 $lib2
     98  1.1  christos 
     99  1.1  christos     runto_main
    100  1.1  christos 
    101  1.1  christos     gdb_breakpoint "bar"
    102  1.1  christos 
    103  1.1  christos     gdb_test "continue" "Breakpoint .* \\.?bar .*${expected_file}\\..*" \
    104  1.1  christos 	"run to breakpoint - $testopts"
    105  1.1  christos }
    106  1.1  christos 
    107  1.1  christos foreach lib1opts {{} {debug}} {
    108  1.1  christos     foreach lib2opts {{} {debug}} {
    109  1.1  christos 	foreach lib1first {1 0} {
    110  1.1  christos 	    do_test $lib1opts $lib2opts $lib1first
    111  1.1  christos 	}
    112  1.1  christos     }
    113  1.1  christos }
    114