]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/solib-vanish.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / solib-vanish.exp
CommitLineData
1d506c26 1# Copyright 2017-2024 Free Software Foundation, Inc.
41667530
MG
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
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:
19#
20# main() -> foo() -> bar()
21#
22# where:
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
26#
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
29# accessible.
30#
31# If a breakpoint is set on bar(), gdb throws an error when this breakpoint is
32# hit:
33#
34# (gdb) r
35# Starting program: /local/gdb/git/pr_16577_repro/simple/solib-vanish-main
36#
37# Breakpoint 1, BFD: reopening ./solib-vanish-lib1.so: No such file or directory
38#
39# BFD: reopening ./solib-vanish-lib1.so: No such file or directory
40#
41# (gdb)
42#
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 */
46# (gdb)
47#
48# The current gdb git tip segfaults if we then try to step:
49# (gdb) n
50# Segmentation fault
51
52# This test verifies that:
53# 1) GDB does not segfault when stepping
54# 2) The stack frame is printed
55
d6195dc9 56require allow_shlib_tests
41667530
MG
57
58# Library 2
59set lib2name "solib-vanish-lib2"
60set srcfile_lib2 ${srcdir}/${subdir}/${lib2name}.c
61set binfile_lib2 [standard_output_file ${lib2name}.so]
62set lib2_flags {debug}
63
64# Library 1
65set lib1name "solib-vanish-lib1"
66set srcfile_lib1 ${srcdir}/${subdir}/${lib1name}.c
67set binfile_lib1 [standard_output_file ${lib1name}.so]
68set lib1_flags [list debug shlib=${binfile_lib2}]
69
a1dfb76d
TV
70if { [gdb_compile_shlib ${srcfile_lib2} ${binfile_lib2} $lib2_flags] != ""
71 || [gdb_compile_shlib ${srcfile_lib1} ${binfile_lib1} $lib1_flags] != "" } {
72 untested "failed to compile"
73 return -1
74}
75
41667530
MG
76# Main program
77set testfile "solib-vanish-main"
78set srcfile ${srcdir}/${subdir}/${testfile}.c
79set executable ${testfile}
80set binfile [standard_output_file ${executable}]
a1dfb76d
TV
81set bin_flags [list debug shlib_load]
82set binfile_lib1_target [gdb_download_shlib $binfile_lib1]
83lappend bin_flags additional_flags=-DVANISH_LIB=\"$binfile_lib1_target\"
41667530 84
a1dfb76d
TV
85if {[is_remote target]} {
86 lappend cleanfiles_target $binfile_lib1_target.renamed
87}
88
89if { [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
41667530
MG
90 untested "failed to compile"
91 return -1
92}
93
94clean_restart $testfile
95
a1dfb76d
TV
96gdb_locate_shlib $binfile_lib1
97gdb_load_shlib $binfile_lib2
98
41667530 99if { ![runto_main] } {
41667530
MG
100 return
101}
102
103delete_breakpoints
104
105set lib2_lineno [gdb_get_line_number "break here" ${srcfile_lib2}]
106
107gdb_breakpoint "${lib2name}.c:${lib2_lineno}" {allow-pending}
108
109# Verify that both the location and source code are displayed
110gdb_continue_to_breakpoint "bar" \
d4330bde 111 ".*${lib2name}.c:${lib2_lineno}.*break here.*"
41667530
MG
112
113# This should not segfault
114gdb_test "next" \
115 "" \
116 "next succeeds"
117