From patchwork Fri May 9 10:09:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 855 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 1095B3600C0 for ; Fri, 9 May 2014 03:10:07 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id A68DB158809E; Fri, 9 May 2014 03:10:06 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 1DB52158809B for ; Fri, 9 May 2014 03:10:06 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=TkJ1 hTaNYo1yEeV3QtVTy+OVaHYSHVwvuwq6l9JgKXe4OAw3EZbAlHjURTRyyjxdcWBt 7niiOwNMDIhOklcwScAnWOXn1le34mXxwXF27te/aP7IX3iOAbCiyA8jnGTfVpnI GT4pPPbm/ByxRmCXORJRBovVnXD+/ye9ndcVWNU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=v6nTxV2ocH h3clE4zvl7av2MQz8=; b=EbdmY8cLj5ZV7rhZg3XloiF6ZnwI3jcbIjO8RyV3Pg Pg2k5SrMfDTkqTgxu/wvNGPCnzvPA4jcs7L+NJZjlFW+mdQQA2wfUKbn0otk40fo ZX0HYo4qg6sjzgTTUCE1Vt/wJX3+RzOltAYICLQ9YKZ7Wb4z3Mae7cto81PQ7i2T c= Received: (qmail 5524 invoked by alias); 9 May 2014 10:10:04 -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 5508 invoked by uid 89); 9 May 2014 10:10:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 May 2014 10:10:01 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s49AA0DH022628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 9 May 2014 06:10:00 -0400 Received: from blade.nx (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s49A9xZu029457 for ; Fri, 9 May 2014 06:10:00 -0400 Received: by blade.nx (Postfix, from userid 1000) id 3DCF626234A; Fri, 9 May 2014 11:09:59 +0100 (BST) Date: Fri, 9 May 2014 11:09:59 +0100 From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Demangler crash handler Message-ID: <20140509100959.GC4760@blade.nx> References: <20140509100656.GA4760@blade.nx> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140509100656.GA4760@blade.nx> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in This patch wraps calls to the demangler with a segmentation fault handler. A warning is printed the first time a segmentation fault is caught. gdb/ 2014-05-09 Gary Benson PR backtrace/16817 * cp-support.c (signal.h): New include. (gdb_demangle_signal_handler): New function. (gdb_demangle): Install the above signal handler before calling bfd_demangle, and restore the original signal handler afterwards. gdb/testsuite/ 2014-05-09 Gary Benson PR backtrace/16817 * gdb.base/pr16817.exp: New file. diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 91533e8..f1a0d49 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -36,6 +36,7 @@ #include "value.h" #include "cp-abi.h" #include "language.h" +#include #include "safe-ctype.h" @@ -1505,12 +1506,71 @@ cp_lookup_rtti_type (const char *name, struct block *block) return rtti_type; } +/* Signal handler for gdb_demangle. */ + +static void +gdb_demangle_signal_handler (int signo) +{ + throw_error (GENERIC_ERROR, _("demangler failed with signal %d"), + signo); +} + /* A wrapper for bfd_demangle. */ char * gdb_demangle (const char *name, int options) { - return bfd_demangle (NULL, name, options); + char *result = NULL; + +#ifdef SIGSEGV + volatile struct gdb_exception except; + +#if defined (HAVE_SIGACTION) && defined (SA_RESTART) + struct sigaction sa, old_sa; + + sa.sa_handler = gdb_demangle_signal_handler; + sigemptyset (&sa.sa_mask); + sa.sa_flags = 0; + sigaction (SIGSEGV, &sa, &old_sa); +#else + void (*ofunc) (); + + ofunc = (void (*)()) signal (SIGSEGV, gdb_demangle_signal_handler); +#endif +#endif + + TRY_CATCH (except, RETURN_MASK_ALL) + { + result = bfd_demangle (NULL, name, options); + } + +#ifdef SIGSEGV +#if defined (HAVE_SIGACTION) && defined (SA_RESTART) + sigaction (SIGSEGV, &old_sa, NULL); +#else + signal (SIGSEGV, ofunc); +#endif +#endif + + if (except.reason < 0) + { + static int warning_printed = 0; + + if (!warning_printed) + { + warning ("internal error: %s\n" + "Unable to demangle '%s'\n" + "This is a bug, " + "please report it to the GDB maintainers.", + except.message, name); + + warning_printed = 1; + } + + result = NULL; + } + + return result; } /* Don't allow just "maintenance cplus". */ diff --git a/gdb/testsuite/gdb.base/pr16817.exp b/gdb/testsuite/gdb.base/pr16817.exp new file mode 100644 index 0000000..fff022c --- /dev/null +++ b/gdb/testsuite/gdb.base/pr16817.exp @@ -0,0 +1,25 @@ +# Copyright 2014 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 . + +# Test that a segmentation fault in the demangler does not cause GDB +# to crash. If the demangler becomes able to demangle the below +# symbol then another symbol will need to be found for this test. + +set symbol "_QueueNotification_QueueController__\$4PPPPPPPM_A_INotice___Z" + +gdb_exit +gdb_start +gdb_test_no_output "set lang c++" +gdb_test "maint demangle $symbol" ".*demangler failed.*"