From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] Demangler crash handler
Date: Fri, 09 May 2014 10:10:00 -0000 [thread overview]
Message-ID: <20140509100959.GC4760@blade.nx> (raw)
In-Reply-To: <20140509100656.GA4760@blade.nx>
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 <gbenson@redhat.com>
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 <gbenson@redhat.com>
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 <signal.h>
#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 <http://www.gnu.org/licenses/>.
+
+# 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.*"
next prev parent reply other threads:[~2014-05-09 10:10 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-09 10:07 [PATCH 0/2] " Gary Benson
2014-05-09 10:09 ` [PATCH 1/2] " Gary Benson
2014-05-09 10:10 ` Gary Benson [this message]
2014-05-09 11:20 ` [PATCH 0/2] " Mark Kettenis
2014-05-09 15:33 ` Gary Benson
2014-05-11 5:17 ` Doug Evans
2014-05-13 10:20 ` Gary Benson
2014-05-13 19:29 ` Tom Tromey
2014-05-14 13:07 ` Gary Benson
2014-05-13 19:39 ` Tom Tromey
2014-05-14 9:15 ` Gary Benson
2014-05-11 20:23 ` Mark Kettenis
2014-05-13 10:21 ` Gary Benson
2014-05-13 16:05 ` Pedro Alves
2014-05-15 13:24 ` Gary Benson
2014-05-15 14:07 ` Pedro Alves
2014-05-15 14:28 ` Gary Benson
2014-05-15 15:25 ` Pedro Alves
2014-05-16 11:06 ` Pedro Alves
2014-05-10 20:55 ` Florian Weimer
2014-05-11 5:10 ` Doug Evans
2014-05-13 10:22 ` Gary Benson
2014-05-13 18:22 ` Florian Weimer
2014-05-13 18:42 ` Pedro Alves
2014-05-13 19:16 ` Gary Benson
2014-05-13 19:19 ` Pedro Alves
2014-05-14 9:11 ` Gary Benson
2014-05-13 19:20 ` Florian Weimer
2014-05-13 19:22 ` Pedro Alves
2014-05-13 19:22 ` Gary Benson
2014-05-13 19:36 ` Tom Tromey
2014-05-14 9:13 ` Gary Benson
2014-05-14 14:18 ` Pedro Alves
2014-05-14 16:08 ` Andrew Burgess
2014-05-14 18:32 ` Pedro Alves
2014-05-15 13:25 ` Gary Benson
2014-05-15 16:01 ` Pedro Alves
2014-05-15 13:27 ` Gary Benson
2014-05-20 17:05 ` Tom Tromey
2014-05-20 18:40 ` Stan Shebs
2014-05-20 19:36 ` Tom Tromey
2014-05-20 20:23 ` Joel Brobecker
2014-05-22 12:56 ` Gary Benson
2014-05-22 13:09 ` Joel Brobecker
2014-05-22 14:13 ` Pedro Alves
2014-05-22 15:57 ` Gary Benson
2014-05-22 13:18 ` Gary Benson
2014-05-22 14:09 ` Gary Benson
2014-05-22 14:40 ` Mark Kettenis
2014-05-22 20:42 ` Gary Benson
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=20140509100959.GC4760@blade.nx \
--to=gbenson@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).