diff options
author | Sandra Loosemore <sandra@codesourcery.com> | 2016-10-26 12:12:01 -0500 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-10-26 16:47:46 +0100 |
commit | ecf45d2cc7667ed4692d07e52fc77a2c9a8adf1c (patch) | |
tree | abc757e04ab221b35d3d0db5afba7f9f82da645a /gdb/testsuite | |
parent | Make symfile_add_flags and objfile->flags strongly typed (diff) | |
download | binutils-gdb-ecf45d2cc7667ed4692d07e52fc77a2c9a8adf1c.tar.gz binutils-gdb-ecf45d2cc7667ed4692d07e52fc77a2c9a8adf1c.tar.bz2 binutils-gdb-ecf45d2cc7667ed4692d07e52fc77a2c9a8adf1c.zip |
PR 20569, segv in follow_exec
The following testcases make GDB crash whenever an invalid sysroot is
provided, when GDB is unable to find a valid path to the symbol file:
gdb.base/catch-syscall.exp
gdb.base/execl-update-breakpoints.exp
gdb.base/foll-exec-mode.exp
gdb.base/foll-exec.exp
gdb.base/foll-vfork.exp
gdb.base/pie-execl.exp
gdb.multi/bkpt-multi-exec.exp
gdb.python/py-finish-breakpoint.exp
gdb.threads/execl.exp
gdb.threads/non-ldr-exc-1.exp
gdb.threads/non-ldr-exc-2.exp
gdb.threads/non-ldr-exc-3.exp
gdb.threads/non-ldr-exc-4.exp
gdb.threads/thread-execl.exp
The immediate cause of the segv is that follow_exec is passing a NULL
argument (the result of exec_file_find) to strlen.
However, the problem is deeper than that: follow_exec simply isn't
prepared for the case where sysroot translation fails to locate the
new executable. Actually all callers of exec_file_find have bugs due
to confusion between host and target pathnames. This commit attempts
to fix all that.
In terms of the testcases that were formerly segv'ing, GDB now prints
a warning but continues execution of the new program, so that the
tests now mostly FAIL instead. You could argue the FAILs are due to a
legitimate problem with the test environment setting up the sysroot
translation incorrectly.
A new representative test is added which exercises the ne wwarning
code path even with native testing.
Tested on x86_64 Fedora 23, native and gdbserver.
gdb/ChangeLog:
2016-10-25 Sandra Loosemore <sandra@codesourcery.com>
Luis Machado <lgustavo@codesourcery.com>
Pedro Alves <palves@redhat.com>
PR gdb/20569
* exceptions.c (exception_print_same): Moved here from exec.c.
* exceptions.h (exception_print_same): Declare.
* exec.h: Include "symfile-add-flags.h".
(try_open_exec_file): New declaration.
* exec.c (exception_print_same): Moved to exceptions.c.
(try_open_exec_file): New function.
(exec_file_locate_attach): Rename exec_file and full_exec_path
variables to avoid confusion between target and host pathnames.
Move pathname processing logic to exec_file_find. Do not return
early if pathname lookup fails; Call try_open_exec_file.
* infrun.c (follow_exec): Split and rename execd_pathname variable
to avoid confusion between target and host pathnames. Warn if
pathname lookup fails. Pass target pathname to
target_follow_exec, not hostpathname. Call try_open_exec_file.
* main.c (symbol_file_add_main_adapter): New function.
(captured_main_1): Use it.
* solib-svr4.c (open_symbol_file_object): Adjust to pass
symfile_add_flags to symbol_file_add_main.
* solib.c (exec_file_find): Incorporate fallback logic for relative
pathnames formerly in exec_file_locate_attach.
* symfile.c (symbol_file_add_main, symbol_file_add_main_1):
Replace 'from_tty' parameter with a symfile_add_file.
(symbol_file_command): Adjust to pass symfile_add_flags to
symbol_file_add_main.
* symfile.h (symbol_file_add_main): Replace 'from_tty' parameter
with a symfile_add_file.
gdb/testsuite/ChangeLog:
2016-10-25 Luis Machado <lgustavo@codesourcery.com>
* gdb.base/exec-invalid-sysroot.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/exec-invalid-sysroot.exp | 70 |
2 files changed, 74 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 460e6b9abc3..d0a2bc986ad 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-25 Luis Machado <lgustavo@codesourcery.com> + + * gdb.base/exec-invalid-sysroot.exp: New file. + 2016-10-24 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.base/morestack.exp: Try to build it using -fuse-ld=gold first. diff --git a/gdb/testsuite/gdb.base/exec-invalid-sysroot.exp b/gdb/testsuite/gdb.base/exec-invalid-sysroot.exp new file mode 100644 index 00000000000..9665b5fc330 --- /dev/null +++ b/gdb/testsuite/gdb.base/exec-invalid-sysroot.exp @@ -0,0 +1,70 @@ +# Copyright 1997-2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This test exercises PR20569. GDB would crash when attempting to follow +# an exec call when it could not resolve the path to the symbol file. +# This was the case when an invalid sysroot is provided. + +standard_testfile foll-exec.c + +global binfile +set binfile [standard_output_file "foll-exec"] +set testfile2 "execd-prog" +set srcfile2 ${testfile2}.c +set binfile2 [standard_output_file ${testfile2}] + +set compile_options debug + +# build the first test case +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } { + untested "could not compile test program ${binfile2}" + return -1 +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } { + untested "could not compile test program ${binfile}" + return -1 +} + +proc do_exec_sysroot_test {} { + global binfile srcfile srcfile2 testfile testfile2 + global gdb_prompt + + gdb_test_no_output "set sysroot /a/path/that/does/not/exist" + + # Start the program running, and stop at main. + # + if ![runto_main] then { + fail "Couldn't run ${testfile}" + return + } + + # Verify that the system supports "catch exec". + gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert exec catchpoint" + set test "continue to exec catchpoint" + gdb_test_multiple "continue" $test { + -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" { + unsupported $test + return + } + -re ".*Could not load symbols for executable.*$gdb_prompt $" { + pass $test + } + } +} + +# Start with a fresh gdb +clean_restart $binfile +do_exec_sysroot_test |