Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Christian Biesinger (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: Christian Biesinger <cbiesinger@google.com>,	gdb-patches@sourceware.org
Subject: [review] Allow not saving the signal state in SIGSETJMP
Date: Tue, 15 Oct 2019 23:22:00 -0000	[thread overview]
Message-ID: <20191015232240.4070226976@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1571181623000.Ib3010966050c64b4cc8b47d8cb45871652b0b3ea@gnutoolchain-gerrit.osci.io>

Christian Biesinger has uploaded a new patch set version (#2).

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-15  Christian Biesinger  <cbiesinger@google.com>

	* 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/cp-support.c
M gdb/gdbsupport/gdb_setjmp.h
2 files changed, 22 insertions(+), 3 deletions(-)



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
 


  reply	other threads:[~2019-10-15 23:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 23:20 [review] Don't save " Christian Biesinger (Code Review)
2019-10-15 23:22 ` Christian Biesinger (Code Review) [this message]
2019-10-16 15:30 ` [review] Allow not saving " Tom Tromey (Code Review)
2019-10-16 15:54 ` Christian Biesinger (Code Review)
2019-10-16 16:10 ` Christian Biesinger (Code Review)
2019-10-16 17:59 ` Tom Tromey (Code Review)
2019-10-16 21:15 ` Sourceware to Gerrit sync (Code Review)
2019-10-16 21:15 ` Sourceware to Gerrit sync (Code Review)

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=20191015232240.4070226976@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=cbiesinger@google.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