From patchwork Sat Oct 6 19:20:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29666 Received: (qmail 17067 invoked by alias); 6 Oct 2018 19:20:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17053 invoked by uid 89); 6 Oct 2018 19:20:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=specially X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.152.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 06 Oct 2018 19:20:10 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 7D8D91840E for ; Sat, 6 Oct 2018 14:20:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 8s7VgUK0nRPoj8s7Vgn8CE; Sat, 06 Oct 2018 14:20:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nX9YNtAUuLfwaK7WZWExkiCxoAS3HWvzasmkCBs8efM=; b=N0fDW4RLIYopjY4g5JKlWcE9OT 1z5OYKbseYbiCBzvsAEYJQ6cxDlBcBO1RWsa70NLvK6JhDSoXyHa4cCGn4utnCSUbfyWh2DuIStcf v7PhVGx1QyGqy3fHHVFdxZWGZ; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:44806 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g8s7V-003Kms-9F; Sat, 06 Oct 2018 14:20:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC] Avoid crash when calling warning too early Date: Sat, 6 Oct 2018 13:20:07 -0600 Message-Id: <20181006192007.1945-1-tom@tromey.com> 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 * 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 (); }