1 1.11 christos # Copyright 2006-2024 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.11 christos require allow_shlib_tests 21 1.1 christos 22 1.1 christos # These targets have shared libraries, but weak symbols are not meaningful. 23 1.10 christos if {([istarget *-*-mingw*] 24 1.1 christos || [istarget *-*-cygwin*] 25 1.1 christos || [istarget *-*-pe*])} { 26 1.1 christos return 0 27 1.1 christos } 28 1.1 christos 29 1.1 christos # This test uses GCC-specific syntax. 30 1.1 christos if {![test_compiler_info "gcc-*"]} { 31 1.1 christos return 0 32 1.1 christos } 33 1.1 christos 34 1.1 christos proc do_test { lib1opts lib2opts lib1first } { 35 1.1 christos global srcdir subdir 36 1.1 christos 37 1.1 christos set testfile "solib-weak" 38 1.1 christos set srcfile ${testfile}.c 39 1.1 christos 40 1.1 christos set libfile1 "weaklib1" 41 1.1 christos set libfile2 "weaklib2" 42 1.1 christos set lib1src ${srcdir}/${subdir}/${libfile1}.c 43 1.1 christos set lib2src ${srcdir}/${subdir}/${libfile2}.c 44 1.1 christos 45 1.1 christos # Select a unique name for this test. Give each library and 46 1.1 christos # executable a name reflecting its options, so that file caching 47 1.1 christos # on the target system does not pick up the wrong file. 48 1.1 christos set testopts "" 49 1.1 christos if {$lib1opts == ""} { 50 1.1 christos append testopts "lib1 nodebug, " 51 1.1 christos } else { 52 1.1 christos append testopts "lib1 debug, " 53 1.1 christos append lib1 "-dbg" 54 1.1 christos } 55 1.1 christos if {$lib2opts == ""} { 56 1.1 christos append testopts "lib2 nodebug, " 57 1.1 christos } else { 58 1.1 christos append testopts "lib2 debug, " 59 1.1 christos append lib2 "-dbg" 60 1.1 christos } 61 1.1 christos if {$lib1first} { 62 1.1 christos append testopts "lib1 first" 63 1.1 christos } else { 64 1.1 christos append testopts "lib2 first" 65 1.1 christos append testfile "-lib2" 66 1.1 christos } 67 1.1 christos 68 1.1 christos set binfile [standard_output_file ${testfile}] 69 1.1 christos set lib1 [standard_output_file ${libfile1}.sl] 70 1.1 christos set lib2 [standard_output_file ${libfile2}.sl] 71 1.1 christos 72 1.1 christos if $lib1first { 73 1.1 christos set exec_opts [list debug shlib=${lib1} shlib=${lib2}] 74 1.1 christos set expected_file ${libfile1} 75 1.1 christos } else { 76 1.1 christos set exec_opts [list debug shlib=${lib2} shlib=${lib1}] 77 1.1 christos set expected_file ${libfile2} 78 1.1 christos } 79 1.1 christos 80 1.1 christos if { [gdb_compile_shlib ${lib1src} ${lib1} ${lib1opts}] != "" 81 1.1 christos || [gdb_compile_shlib ${lib2src} ${lib2} ${lib2opts}] != "" 82 1.1 christos || [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable $exec_opts] != ""} { 83 1.1 christos return -1 84 1.1 christos } 85 1.1 christos 86 1.10 christos with_test_prefix $testopts { 87 1.11 christos clean_restart $binfile 88 1.10 christos gdb_load_shlib $lib1 89 1.10 christos gdb_load_shlib $lib2 90 1.1 christos 91 1.10 christos runto_main 92 1.1 christos 93 1.10 christos gdb_breakpoint "bar" 94 1.1 christos 95 1.10 christos gdb_test "continue" "Breakpoint .* \\.?bar .*${expected_file}\\..*" \ 96 1.10 christos "run to breakpoint" 97 1.10 christos } 98 1.1 christos } 99 1.1 christos 100 1.1 christos foreach lib1opts {{} {debug}} { 101 1.1 christos foreach lib2opts {{} {debug}} { 102 1.1 christos foreach lib1first {1 0} { 103 1.1 christos do_test $lib1opts $lib2opts $lib1first 104 1.1 christos } 105 1.1 christos } 106 1.1 christos } 107