8c0fae4 Introduce thread-safe way to handle SIGSEGV

Authored and Committed by Tom Tromey 4 years ago
    Introduce thread-safe way to handle SIGSEGV
    
    The gdb demangler installs a SIGSEGV handler in order to protect gdb
    from demangler bugs.  However, this is not thread-safe, as signal
    handlers are global to the process.
    
    This patch changes gdb to always install a global SIGSEGV handler, and
    then lets threads indicate their interest in handling the signal by
    setting a thread-local variable.
    
    This patch then arranges for the demangler code to use this; being
    sure to arrange for calls to warning and the like to be done on the
    main thread.
    
    One thing I wondered while writing this patch is if there are any
    systems that do not have "sigaction".  If gdb could assume this, it
    would simplify this code.
    
    gdb/ChangeLog
    2019-09-30  Tom Tromey  <tom@tromey.com>
    
    	* event-top.h (thread_local_segv_handler): Declare.
    	* event-top.c (thread_local_segv_handler): New global.
    	(install_handle_sigsegv, handle_sigsegv): New functions.
    	(async_init_signals): Install SIGSEGV handler.
    	* cp-support.c (gdb_demangle_jmp_buf): Change type.  Now
    	thread-local.
    	(report_failed_demangle): New function.
    	(gdb_demangle): Make core_dump_allowed atomic.  Remove signal
    	handler-setting code, instead use segv_handler.  Run warning code
    	on main thread.
    
        
file modified
+13 -0
file modified
+70 -73
file modified
+41 -0
file modified
+6 -0