1 # Copyright 2017-2023 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/>.
16 # This file is part of the gdb testsuite.
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>.
23 # We cannot expect remote hosts to see environment variables set on
25 if { [is_remote host] } {
26 unsupported "can't set environment variables on remote host"
30 # Spawn GDB with LIB preloaded with LD_PRELOAD. CMDLINE_OPTS are
31 # command line options passed to GDB.
33 proc gdb_spawn_with_ld_preload {lib cmdline_opts} {
36 save_vars { env(LD_PRELOAD) env(ASAN_OPTIONS)} {
37 if { ![info exists env(LD_PRELOAD) ]
38 || $env(LD_PRELOAD) == "" } {
39 set env(LD_PRELOAD) "$lib"
41 append env(LD_PRELOAD) ":$lib"
44 # Prevent address sanitizer error:
45 # ASan runtime does not come first in initial library list; you should
46 # either link runtime to your application or manually preload it with
48 set_sanitizer_default ASAN_OPTIONS verify_asan_link_order 0
50 gdb_spawn_with_cmdline_opts $cmdline_opts
54 proc test_libsegfault {} {
57 set libsegfault "libSegFault.so"
59 # When started normally, if libSegFault.so is preloaded, GDB
60 # should warn about not being able to propagate the signal
61 # disposition of SIGSEGV.
63 gdb_spawn_with_ld_preload $libsegfault ""
65 set test "gdb emits custom handler warning"
66 gdb_test_multiple "" $test {
67 -re "cannot be preloaded.*\r\n$gdb_prompt $" {
69 # ERROR: ld.so: object 'libSegFault.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
70 untested "cannot preload libSegFault.so"
73 -re "Found custom handler.*won't be propagated.*\r\n$gdb_prompt $" {
78 # "-q" should disable the warning, though.
80 gdb_spawn_with_ld_preload $libsegfault "-q"
82 set test "quiet suppresses custom handler warning"
83 gdb_test_multiple "" $test {
84 -re "^$gdb_prompt $" {