diff options
author | Tom Tromey <tom@tromey.com> | 2018-10-05 14:54:35 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-11-08 16:10:21 -0700 |
commit | 20f0d60db4fb5083779c4c9182bbc692f7d2bac5 (patch) | |
tree | 4b194b7c74bf9200bb4b3811c8b426843afa56a0 /gdb/testsuite | |
parent | d4718d5c9f9b5c41d88254429c61010c63139130 (diff) | |
download | gdb-20f0d60db4fb5083779c4c9182bbc692f7d2bac5.zip gdb-20f0d60db4fb5083779c4c9182bbc692f7d2bac5.tar.gz gdb-20f0d60db4fb5083779c4c9182bbc692f7d2bac5.tar.bz2 |
Avoid crash when calling warning too early
I noticed that if you pass the name of an existing file (not a
directory) as the argument to --data-directory, gdb will crash:
$ ./gdb -nx --data-directory ./gdb
../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops'
This was later reported as PR gdb/23838.
This happens because warning ends up calling
target_supports_terminal_ours, which calls current_top_target, which
returns nullptr this early.
This fixes the problem by handling this case specially in
target_supports_terminal_ours. I also changed
target_supports_terminal_ours to return bool.
gdb/ChangeLog
2018-11-08 Tom Tromey <tom@tromey.com>
PR gdb/23555:
PR gdb/23838:
* target.h (target_supports_terminal_ours): Return bool.
* target.c (target_supports_terminal_ours): Handle case where
current_top_target returns nullptr. Return bool.
gdb/testsuite/ChangeLog
2018-11-08 Tom Tromey <tom@tromey.com>
PR gdb/23555:
PR gdb/23838:
* gdb.base/warning.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/warning.exp | 36 |
2 files changed, 42 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e0bb838..a0e614f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-11-08 Tom Tromey <tom@tromey.com> + + PR gdb/23555: + PR gdb/23838: + * gdb.base/warning.exp: New file. + 2018-11-08 Jan Beulich <jbeulich@suse.com> * testsuite/gdb.arch/i386-avx512.c, diff --git a/gdb/testsuite/gdb.base/warning.exp b/gdb/testsuite/gdb.base/warning.exp new file mode 100644 index 0000000..53067f4 --- /dev/null +++ b/gdb/testsuite/gdb.base/warning.exp @@ -0,0 +1,36 @@ +# Copyright 2018 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/>. + +# Test that an early warning does not cause a crash. + +if {[is_remote host]} { + unsupported "warning.exp can only run on local host" + return +} + +set tname [standard_temp_file warning] +set fd [open $tname w] +puts $fd "anything" +close $fd + +set save $INTERNAL_GDBFLAGS +set INTERNAL_GDBFLAGS "-nw -nx -data-directory $tname" + +gdb_start + +# Make sure gdb started up. +gdb_test "echo 23\\n" "23" + +set INTERNAL_GDBFLAGS $save |