From patchwork Tue May 13 10:20:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 883 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 2431E360079 for ; Tue, 13 May 2014 03:20:47 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id B7BCD15AF01D; Tue, 13 May 2014 03:20:46 -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 8A03E15AF009 for ; Tue, 13 May 2014 03:20:46 -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:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=Dk8v NW9BQ/gR93qKaH687YbYvLqKulftbfKKy+jj0MRm2tqlaSZM/6ypJl9VTgUZNLUv 8KESxa9XjrTK3uVrxbhv2sh8kkpgBCEOa/ghilB64T8br0MCOB+J69IY/47R8gcW TMD9wDVs6OFpyfrfeQmlqPrkl94QEmnXmtTa9pg= 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:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=dicWcGhRrc PhWqL8UrY3QHCn54Y=; b=Fm84TjaNXn9dJkWJHFkeRlRxsGTDdRc+mMpTKYPy0r mWWllCY8+966J/nrcFQj9oSe2iyPkBcBcUsyXZ9ptuMTOUW6k7EG4oUxOpn5b9DV aOu/+w7VGsrdZLb5llC72Wocj0lIrM4nMVBHjTEX4mlyeY9A0n2Kf8AR6IkPDoa1 Q= Received: (qmail 1404 invoked by alias); 13 May 2014 10:20:44 -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 1386 invoked by uid 89); 13 May 2014 10:20:43 -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; Tue, 13 May 2014 10:20:39 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4DAKbEe023928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 May 2014 06:20:37 -0400 Received: from blade.nx (ovpn-116-68.ams2.redhat.com [10.36.116.68]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4DAKavu015883; Tue, 13 May 2014 06:20:37 -0400 Received: by blade.nx (Postfix, from userid 1000) id E09CD26234A; Tue, 13 May 2014 11:20:35 +0100 (BST) Date: Tue, 13 May 2014 11:20:35 +0100 From: Gary Benson To: Doug Evans Cc: Mark Kettenis , "gdb-patches@sourceware.org" Subject: Re: [PATCH 0/2] Demangler crash handler Message-ID: <20140513102035.GA17805@blade.nx> References: <20140509100656.GA4760@blade.nx> <201405091120.s49BKO1f010622@glazunov.sibelius.xs4all.nl> <20140509153305.GA13345@blade.nx> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in Doug Evans wrote: > On Fri, May 9, 2014 at 8:33 AM, Gary Benson wrote: > > [...] > > + if (crash_signal != 0) > > + { > > + static int warning_printed = 0; > > + > > + if (!warning_printed) > > + { > > + warning ("internal error: demangler failed with signal %d\n" > > + "Unable to demangle '%s'\n" > > + "This is a bug, " > > + "please report it to the GDB maintainers.", > > + crash_signal, name); > > + > > + warning_printed = 1; > > + } > > + > > + result = NULL; > > + } > > + > > + return result; > > Applying "Consistency Is Good" to this patch, I wonder if we should > do something similar to what we do for internal errors. I'm not > sure I would use the same flag (grep for internal_problem_modes and > friends in utils.c), but OTOH I wouldn't want a proliferation of > options for controlling each particular kind of "crash". > > What do you think? I did not realize internal_error had the ability to continue over an error. Rather than doing something similar to internal_error I can just update the patch to use it. I actually prefer this to using regular warning as the user has to explicity continue over the error. They cannot miss that something is wrong and that they are now in uncharted territory, but at the same time they have to option to try and continue using GDB to debug their program. I attached an updated patch that uses internal_warning below. It might be desirable to create a new warning (demangler_warning) that would work like internal_warning but not offer the possibility of saving a not-particularly-useful core dump. That's a refinement I'm not sure is necessary, however: this isn't everyday code. As an aside, would it be worth printing an extra line or two from internal_vproblem asking the user to report the bug and directing them to the bug tracker and/or the mailing lists? Thanks, Gary diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 91533e8..a99c827 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,88 @@ cp_lookup_rtti_type (const char *name, struct block *block) return rtti_type; } +#ifdef SIGSEGV + +/* PortabiWrap set/long jmp so that it's more portable. */ + +#if defined(HAVE_SIGSETJMP) +#define SIGJMP_BUF sigjmp_buf +#define SIGSETJMP(buf) sigsetjmp((buf), 1) +#define SIGLONGJMP(buf,val) siglongjmp((buf), (val)) +#else +#define SIGJMP_BUF jmp_buf +#define SIGSETJMP(buf) setjmp(buf) +#define SIGLONGJMP(buf,val) longjmp((buf), (val)) +#endif + +/* Stack context and environment for demangler crash recovery. */ + +static SIGJMP_BUF gdb_demangle_jmp_buf; + +/* Signal handler for gdb_demangle. */ + +static void +gdb_demangle_signal_handler (int signo) +{ + SIGLONGJMP (gdb_demangle_jmp_buf, signo); +} + +#endif + /* A wrapper for bfd_demangle. */ char * gdb_demangle (const char *name, int options) { - return bfd_demangle (NULL, name, options); + char *result = NULL; + int crash_signal = 0; + +#ifdef SIGSEGV +#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 + + crash_signal = SIGSETJMP (gdb_demangle_jmp_buf); +#endif + + if (crash_signal == 0) + 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 (crash_signal != 0) + { + static int error_reported = 0; + + if (!error_reported) + { + internal_warning (__FILE__, __LINE__, + _("unable to demangle '%s' " + "(demangler failed with signal %d)"), + name, crash_signal); + + error_reported = 1; + } + + result = NULL; + } + + return result; } /* Don't allow just "maintenance cplus". */