From patchwork Wed Oct 16 21:15:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35062 Received: (qmail 34356 invoked by alias); 16 Oct 2019 21:15:35 -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 34281 invoked by uid 89); 16 Oct 2019 21:15:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Oct 2019 21:15:14 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id E011220956; Wed, 16 Oct 2019 17:15:09 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 1DFBF2064E; Wed, 16 Oct 2019 17:15:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id ED7A920AF6; Wed, 16 Oct 2019 17:15:03 -0400 (EDT) X-Gerrit-PatchSet: 3 Date: Wed, 16 Oct 2019 17:15:03 -0400 From: "Sourceware to Gerrit sync (Code Review)" To: Christian Biesinger , Tom Tromey , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review] Allow not saving the signal state in SIGSETJMP X-Gerrit-Change-Id: Ib3010966050c64b4cc8b47d8cb45871652b0b3ea X-Gerrit-Change-Number: 124 X-Gerrit-ChangeURL: X-Gerrit-Commit: 17bfe554b9a8c57c4d377bce930046138298fd8b In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191016211503.ED7A920AF6@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has uploaded a new patch set version (#3) to the change originally created by Christian Biesinger. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/124 ...................................................................... Allow not saving the signal state in SIGSETJMP Saving the signal state is very slow (this patch is a 14% speedup). The reason we need this code is because signal handler will leave the signal blocked when we longjmp out of it. But in this case we can just manually unblock the signal instead of taking the unconditional perf hit. gdb/ChangeLog: 2019-10-16 Christian Biesinger * gdbsupport/gdb_setjmp.h (SIGSETJMP): Allow passing in the value to pass on to sigsetjmp's second argument. * cp-support.c (gdb_demangle): Unblock SIGSEGV if we caught a crash. Change-Id: Ib3010966050c64b4cc8b47d8cb45871652b0b3ea --- M gdb/ChangeLog M gdb/cp-support.c M gdb/gdbsupport/gdb_setjmp.h 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d11dbfb..ba028ed 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-10-16 Christian Biesinger + + * gdbsupport/gdb_setjmp.h (SIGSETJMP): Allow passing in the value to + pass on to sigsetjmp's second argument. + * cp-support.c (gdb_demangle): Unblock SIGSEGV if we caught a crash. + 2019-10-16 Keith Seitz PR gdb/23567 diff --git a/gdb/cp-support.c b/gdb/cp-support.c index cd732b6..253369b 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1539,7 +1539,16 @@ ofunc = signal (SIGSEGV, gdb_demangle_signal_handler); #endif - crash_signal = SIGSETJMP (gdb_demangle_jmp_buf); + /* The signal handler may keep the signal blocked when we longjmp out + of it. If we have sigprocmask, we can use it to unblock the signal + afterwards and we can avoid the performance overhead of saving the + signal mask just in case the signal gets triggered. Otherwise, just + tell sigsetjmp to save the mask. */ +#ifdef HAVE_SIGPROCMASK + crash_signal = SIGSETJMP (gdb_demangle_jmp_buf, 0); +#else + crash_signal = SIGSETJMP (gdb_demangle_jmp_buf, 1); +#endif } #endif @@ -1559,6 +1568,14 @@ { static int error_reported = 0; +#ifdef HAVE_SIGPROCMASK + /* If we got the signal, SIGSEGV may still be blocked; restore it. */ + sigset_t segv_sig_set; + sigemptyset (&segv_sig_set); + sigaddset (&segv_sig_set, SIGSEGV); + sigprocmask (SIG_UNBLOCK, &segv_sig_set, NULL); +#endif + if (!error_reported) { std::string short_msg diff --git a/gdb/gdbsupport/gdb_setjmp.h b/gdb/gdbsupport/gdb_setjmp.h index d4ebbfa..4995970 100644 --- a/gdb/gdbsupport/gdb_setjmp.h +++ b/gdb/gdbsupport/gdb_setjmp.h @@ -23,11 +23,13 @@ #ifdef HAVE_SIGSETJMP #define SIGJMP_BUF sigjmp_buf -#define SIGSETJMP(buf) sigsetjmp((buf), 1) +#define SIGSETJMP(buf,val) sigsetjmp((buf), val) #define SIGLONGJMP(buf,val) siglongjmp((buf), (val)) #else #define SIGJMP_BUF jmp_buf -#define SIGSETJMP(buf) setjmp(buf) +/* We ignore val here because that's safer and avoids having to check + whether _setjmp exists. */ +#define SIGSETJMP(buf,val) setjmp(buf) #define SIGLONGJMP(buf,val) longjmp((buf), (val)) #endif