summaryrefslogtreecommitdiff
path: root/gdb/event-top.c
diff options
context:
space:
mode:
authorChristian Biesinger <cbiesinger@google.com>2021-03-09 08:16:23 -0600
committerChristian Biesinger <cbiesinger@google.com>2021-03-12 11:21:42 -0600
commitfece451c2aca57b095e7e4063e342781cf74aa75 (patch)
treeb1b52ba0a7f3399f65b4b416bc4af7f8ad7b754b /gdb/event-top.c
parentbe3b926d8d2dde16a55e9e303fadf95164e13ebf (diff)
downloadbinutils-gdb-fece451c2aca57b095e7e4063e342781cf74aa75.tar.gz
Use RAII to set the per-thread SIGSEGV handler
This avoids using a thread-local extern variable, which causes link errors on some platforms, notably Cygwin. But I think this is a better pattern even outside of working around linker bugs because it encapsulates direct access to the variable inside the class, instead of having a global extern variable. The cygwin link error is: cp-support.o: in function `gdb_demangle(char const*, int)': /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x6472): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler' /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x648b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler' collect2: error: ld returned 1 exit status 2021-03-12 Christian Biesinger <cbiesinger@google.com> PR threads/27239 * cp-support.c: Use scoped_segv_handler_restore. * event-top.c (thread_local_segv_handler): Made static. (scoped_segv_handler_restore::scoped_segv_handler_restore): New function. (scoped_segv_handler_restore::~scoped_segv_handler_restore): New function. * event-top.h (class scoped_segv_handler_restore): New class. (thread_local_segv_handler): Removed.
Diffstat (limited to 'gdb/event-top.c')
-rw-r--r--gdb/event-top.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c
index a33f6425140..fb0df943f65 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -850,9 +850,17 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
}
-/* See event-top.h. */
+/* The SIGSEGV handler for this thread, or NULL if there is none. GDB
+ always installs a global SIGSEGV handler, and then lets threads
+ indicate their interest in handling the signal by setting this
+ thread-local variable.
-thread_local void (*thread_local_segv_handler) (int);
+ This is a static variable instead of extern because on various platforms
+ (notably Cygwin) extern thread_local variables cause link errors. So
+ instead, we have scoped_segv_handler_restore, which also makes it impossible
+ to accidentally forget to restore it to the original value. */
+
+static thread_local void (*thread_local_segv_handler) (int);
static void handle_sigsegv (int sig);
@@ -1288,6 +1296,17 @@ gdb_disable_readline (void)
delete_file_handler (ui->input_fd);
}
+scoped_segv_handler_restore::scoped_segv_handler_restore (segv_handler_t new_handler)
+{
+ m_old_handler = thread_local_segv_handler;
+ thread_local_segv_handler = new_handler;
+}
+
+scoped_segv_handler_restore::~scoped_segv_handler_restore()
+{
+ thread_local_segv_handler = m_old_handler;
+}
+
static const char debug_event_loop_off[] = "off";
static const char debug_event_loop_all_except_ui[] = "all-except-ui";
static const char debug_event_loop_all[] = "all";