1 # Copyright
2017-2019 Free Software Foundation
, Inc.
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.
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.
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
/>.
17 # This test case verifies that GDB gracefully handles a shared library file
18 # vanishing after being dlopen
'ed. This consists of three nested function calls:
20 # main() -> foo() -> bar()
23 # - foo exists in solib-vanish-lib1.so, which is dlopen'ed by main
()
24 #
- bar
exists in solib
-vanish
-lib2.so
, which is dynamically linked into
25 # solib
-vanish
-lib1.so
27 # Immediately after dlopen
'ing solib-vanish-lib1.so, the so file is moved aside
28 # by renaming. The main executable and solib-vanish-lib2.so are still
31 # If a breakpoint is set on bar(), gdb throws an error when this breakpoint is
35 # Starting program: /local/gdb/git/pr_16577_repro/simple/solib-vanish-main
37 # Breakpoint 1, BFD: reopening ./solib-vanish-lib1.so: No such file or directory
39 # BFD: reopening ./solib-vanish-lib1.so: No such file or directory
43 # Notice that this does not print the current frame, i.e.:
44 # bar (y=1) at solib-vanish-lib2.c:19
45 # 19 return y + 1; /* break here */
48 # The current gdb git tip segfaults if we then try to step:
52 # This test verifies that:
53 # 1) GDB does not segfault when stepping
54 # 2) The stack frame is printed
56 if { [skip_shlib_tests] } {
61 set lib2name "solib-vanish-lib2"
62 set srcfile_lib2 ${srcdir}/${subdir}/${lib2name}.c
63 set binfile_lib2 [standard_output_file ${lib2name}.so]
64 set lib2_flags {debug}
67 set lib1name "solib-vanish-lib1"
68 set srcfile_lib1 ${srcdir}/${subdir}/${lib1name}.c
69 set binfile_lib1 [standard_output_file ${lib1name}.so]
70 set lib1_flags [list debug shlib=${binfile_lib2}]
73 set testfile "solib-vanish-main"
74 set srcfile ${srcdir}/${subdir}/${testfile}.c
75 set executable ${testfile}
76 set binfile [standard_output_file ${executable}]
77 set bin_flags [list debug shlib_load additional_flags=-DVANISH_LIB=\"${binfile_lib1}\"]
79 if { [gdb_compile_shlib ${srcfile_lib2} ${binfile_lib2} $lib2_flags] != ""
80 || [gdb_compile_shlib ${srcfile_lib1} ${binfile_lib1} $lib1_flags] != ""
81 || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
82 untested "failed to compile"
86 clean_restart $testfile
88 if { ![runto_main] } {
89 fail "can't run to main
"
95 set lib2_lineno
[gdb_get_line_number
"break here" ${srcfile_lib2}]
97 gdb_breakpoint
"${lib2name}.c:${lib2_lineno}" {allow-pending}
99 # Verify that both the location and source code are displayed
100 gdb_continue_to_breakpoint
"bar" \
101 ".*${lib2name}.c:${lib2_lineno}.*break here.*"
103 # This should not segfault