aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-04-22 17:05:44 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-04-28 09:56:19 +0100
commit913832e99c5a1576663e52a4929b13bb263bd692 (patch)
tree1506c80a86e2d4633e35628a8d421d9c6fc0122b
parenta3b5ef3e45642e2e162f02f125a2322c3d1ad95f (diff)
downloadgdb-913832e99c5a1576663e52a4929b13bb263bd692.zip
gdb-913832e99c5a1576663e52a4929b13bb263bd692.tar.gz
gdb-913832e99c5a1576663e52a4929b13bb263bd692.tar.bz2
gdb: ensure SIGINT is set to SIG_DFL during initialisation
In order for our SIGINT handling to work correctly with Python we require that SIGINT be set to SIG_DFL during Python's initialisation. Currently this is the case, but, in a later commit I plan to delay the initialisation of Python until after the point where GDB's own SIGINT handler has been installed. The consequence of this is that our SIGINT handling would become broken. In this commit I propose adding an RAII class that will ensure SIGINT is set to SIG_DFL during the call to each extension languages finish_initialization method. At this point this change should have not effect. gdb/ChangeLog: * extension.c (struct scoped_default_signal): New struct. (scoped_default_sigint): New typedef. (finish_ext_lang_initialization): Make use of scoped_default_sigint.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/extension.c28
2 files changed, 34 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c5db004..c417e81 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com>
+ * extension.c (struct scoped_default_signal): New struct.
+ (scoped_default_sigint): New typedef.
+ (finish_ext_lang_initialization): Make use of
+ scoped_default_sigint.
+
+2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com>
+
* main.c (captured_main_1): Don't pass argument to gdb_init.
* top.c (gdb_init): Remove unused argument, and add header
comment.
diff --git a/gdb/extension.c b/gdb/extension.c
index 85d410e..523079a 100644
--- a/gdb/extension.c
+++ b/gdb/extension.c
@@ -296,6 +296,29 @@ ext_lang_auto_load_enabled (const struct extension_language_defn *extlang)
return extlang->script_ops->auto_load_enabled (extlang);
}
+
+/* RAII class used to temporarily return SIG to its default handler. */
+
+template<int SIG>
+struct scoped_default_signal
+{
+ scoped_default_signal ()
+ { m_old_sig_handler = signal (SIG, SIG_DFL); }
+
+ ~scoped_default_signal ()
+ { signal (SIG, m_old_sig_handler); }
+
+ DISABLE_COPY_AND_ASSIGN (scoped_default_signal);
+
+private:
+ /* The previous signal handler that needs to be restored. */
+ sighandler_t m_old_sig_handler;
+};
+
+/* Class to temporarily return SIGINT to its default handler. */
+
+using scoped_default_sigint = scoped_default_signal<SIGINT>;
+
/* Functions that iterate over all extension languages.
These only iterate over external extension languages, not including
GDB's own extension/scripting language, unless otherwise indicated. */
@@ -310,7 +333,10 @@ finish_ext_lang_initialization (void)
{
if (extlang->ops != nullptr
&& extlang->ops->finish_initialization != NULL)
- extlang->ops->finish_initialization (extlang);
+ {
+ scoped_default_sigint set_sigint_to_default_handler;
+ extlang->ops->finish_initialization (extlang);
+ }
}
}