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# This file is part of the gdb testsuite. 17 18# Test that GDB tolerates being started with libSegFault.so preloaded 19# with LD_PRELOAD, and that GDB warns about a custom SIGSEGV custom 20# handler. See PR gdb/18653 21# <https://sourceware.org/bugzilla/show_bug.cgi?id=18653#c7>. 22 23# We cannot expect remote hosts to see environment variables set on 24# the local machine. 25if { [is_remote host] } { 26 unsupported "can't set environment variables on remote host" 27 return -1 28} 29 30# Spawn GDB with LIB preloaded with LD_PRELOAD. CMDLINE_OPTS are 31# command line options passed to GDB. 32 33proc gdb_spawn_with_ld_preload {lib cmdline_opts} { 34 global env 35 36 save_vars { env(LD_PRELOAD) } { 37 if { ![info exists env(LD_PRELOAD) ] 38 || $env(LD_PRELOAD) == "" } { 39 set env(LD_PRELOAD) "$lib" 40 } else { 41 append env(LD_PRELOAD) ":$lib" 42 } 43 44 gdb_spawn_with_cmdline_opts $cmdline_opts 45 } 46} 47 48proc test_libsegfault {} { 49 global gdb_prompt 50 51 set libsegfault "libSegFault.so" 52 53 # When started normally, if libSegFault.so is preloaded, GDB 54 # should warn about not being able to propagate the signal 55 # disposition of SIGSEGV. 56 gdb_exit 57 gdb_spawn_with_ld_preload $libsegfault "" 58 59 set test "gdb emits custom handler warning" 60 gdb_test_multiple "" $test { 61 -re "cannot be preloaded.*\r\n$gdb_prompt $" { 62 # Glibc 2.22 outputs: 63 # ERROR: ld.so: object 'libSegFault.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. 64 untested "cannot preload libSegFault.so" 65 return 66 } 67 -re "Found custom handler.*won't be propagated.*\r\n$gdb_prompt $" { 68 pass $test 69 } 70 } 71 72 # "-q" should disable the warning, though. 73 gdb_exit 74 gdb_spawn_with_ld_preload $libsegfault "-q" 75 76 set test "quiet suppresses custom handler warning" 77 gdb_test_multiple "" $test { 78 -re "^$gdb_prompt $" { 79 pass $test 80 } 81 } 82} 83 84test_libsegfault 85