1# Copyright 2017-2020 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 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 56if { [skip_shlib_tests] } { 57 return 0 58} 59 60# Library 2 61set lib2name "solib-vanish-lib2" 62set srcfile_lib2 ${srcdir}/${subdir}/${lib2name}.c 63set binfile_lib2 [standard_output_file ${lib2name}.so] 64set lib2_flags {debug} 65 66# Library 1 67set lib1name "solib-vanish-lib1" 68set srcfile_lib1 ${srcdir}/${subdir}/${lib1name}.c 69set binfile_lib1 [standard_output_file ${lib1name}.so] 70set lib1_flags [list debug shlib=${binfile_lib2}] 71 72# Main program 73set testfile "solib-vanish-main" 74set srcfile ${srcdir}/${subdir}/${testfile}.c 75set executable ${testfile} 76set binfile [standard_output_file ${executable}] 77set bin_flags [list debug shlib_load additional_flags=-DVANISH_LIB=\"${binfile_lib1}\"] 78 79if { [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" 83 return -1 84} 85 86clean_restart $testfile 87 88if { ![runto_main] } { 89 fail "can't run to main" 90 return 91} 92 93delete_breakpoints 94 95set lib2_lineno [gdb_get_line_number "break here" ${srcfile_lib2}] 96 97gdb_breakpoint "${lib2name}.c:${lib2_lineno}" {allow-pending} 98 99# Verify that both the location and source code are displayed 100gdb_continue_to_breakpoint "bar" \ 101 ".*${lib2name}.c:${lib2_lineno}.*break here.*" 102 103# This should not segfault 104gdb_test "next" \ 105 "" \ 106 "next succeeds" 107 108