aboutsummaryrefslogtreecommitdiff
path: root/gdb/main.c
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2014-06-19 09:13:57 +0100
committerGary Benson <gbenson@redhat.com>2014-06-19 09:13:57 +0100
commit992c7d700f99002ed455b0588488e0e42719ba81 (patch)
treec24351fbcff74f41550b27263995ec03be1988ed /gdb/main.c
parenteae7090bea9d7f129be7dddf89f8e177cdb2003d (diff)
downloadgdb-992c7d700f99002ed455b0588488e0e42719ba81.zip
gdb-992c7d700f99002ed455b0588488e0e42719ba81.tar.gz
gdb-992c7d700f99002ed455b0588488e0e42719ba81.tar.bz2
Demangler crash handler
This commit wraps calls to the demangler with a segmentation fault handler. The first time a segmentation fault is caught a core file is generated and the user is prompted to file a bug and offered the choice to exit or to continue their GDB session. A maintainence option is provided to allow the user to disable the crash handler if required. gdb/ 2014-06-19 Gary Benson <gbenson@redhat.com> * configure.ac [AC_CHECK_FUNCS] <sigaltstack>: New check. * configure: Regenerate. * config.in: Likewise. * main.c (signal.h): New include. (setup_alternate_signal_stack): New function. (captured_main): Call the above. * cp-support.c (signal.h): New include. (catch_demangler_crashes): New flag. (SIGJMP_BUF): New define. (SIGSETJMP): Likewise. (SIGLONGJMP): Likewise. (gdb_demangle_jmp_buf): New static global. (gdb_demangle_attempt_core_dump): Likewise. (gdb_demangle_signal_handler): New function. (gdb_demangle): If catch_demangler_crashes is set, install the above signal handler before calling bfd_demangle, and restore the original signal handler afterwards. Display the offending symbol and call demangler_warning the first time a segmentation fault is caught. (_initialize_cp_support): New maint set/show command. gdb/doc/ 2014-06-19 Gary Benson <gbenson@redhat.com> * gdb.texinfo (Maintenance Commands): Document new "maint set/show catch-demangler-crashes" option.
Diffstat (limited to 'gdb/main.c')
-rw-r--r--gdb/main.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gdb/main.c b/gdb/main.c
index 108759d..0d4d512 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -45,6 +45,7 @@
#include "filenames.h"
#include "filestuff.h"
+#include <signal.h>
/* The selected interpreter. This will be used as a set command
variable, so it should always be malloc'ed - since
@@ -288,6 +289,27 @@ get_init_files (const char **system_gdbinit,
*local_gdbinit = localinit;
}
+/* Try to set up an alternate signal stack for SIGSEGV handlers.
+ This allows us to handle SIGSEGV signals generated when the
+ normal process stack is exhausted. If this stack is not set
+ up (sigaltstack is unavailable or fails) and a SIGSEGV is
+ generated when the normal stack is exhausted then the program
+ will behave as though no SIGSEGV handler was installed. */
+
+static void
+setup_alternate_signal_stack (void)
+{
+#ifdef HAVE_SIGALTSTACK
+ stack_t ss;
+
+ ss.ss_sp = xmalloc (SIGSTKSZ);
+ ss.ss_size = SIGSTKSZ;
+ ss.ss_flags = 0;
+
+ sigaltstack(&ss, NULL);
+#endif
+}
+
/* Call command_loop. If it happens to return, pass that through as a
non-zero return status. */
@@ -785,6 +807,9 @@ captured_main (void *data)
quiet = 1;
}
+ /* Try to set up an alternate signal stack for SIGSEGV handlers. */
+ setup_alternate_signal_stack ();
+
/* Initialize all files. Give the interpreter a chance to take
control of the console via the deprecated_init_ui_hook (). */
gdb_init (gdb_program_name);