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