From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFC] Avoid crash when calling warning too early
Date: Sat, 06 Oct 2018 19:20:00 -0000 [thread overview]
Message-ID: <20181006192007.1945-1-tom@tromey.com> (raw)
I happened to notice 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 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 wasn't sure whether this warranted a test case, hence the RFC.
gdb/ChangeLog
2018-10-06 Tom Tromey <tom@tromey.com>
* target.c (target_supports_terminal_ours): Handle case where
current_top_target returns nullptr.
---
gdb/ChangeLog | 5 +++++
gdb/target.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/gdb/target.c b/gdb/target.c
index 2d98954b54..a261155f29 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -587,6 +587,11 @@ target_terminal::info (const char *arg, int from_tty)
int
target_supports_terminal_ours (void)
{
+ /* This can be called before there is any target, so we must check
+ for nullptr here. */
+ target_ops *top = current_top_target ();
+ if (top == nullptr)
+ return false;
return current_top_target ()->supports_terminal_ours ();
}
--
2.17.1
next reply other threads:[~2018-10-06 19:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-06 19:20 Tom Tromey [this message]
2018-10-06 19:32 ` Sergio Durigan Junior
2018-10-06 21:13 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181006192007.1945-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox