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