gdb: ensure SIGINT is set to SIG_DFL during initialisation
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 22 Apr 2021 16:05:44 +0000 (17:05 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 28 Apr 2021 08:56:19 +0000 (09:56 +0100)
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.

gdb/ChangeLog
gdb/extension.c

index c5db0041e525e6b5b1b60b41a4837c24a31bbd78..c417e81b893534af43dff7c67d126c472157f1f3 100644 (file)
@@ -1,3 +1,10 @@
+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.
index 85d410e8a7aea72719f7ec0856ca1799c7941272..523079a1a6a760891d0280e6fa35a3874aad5111 100644 (file)
@@ -296,6 +296,29 @@ ext_lang_auto_load_enabled (const struct extension_language_defn *extlang)
   return extlang->script_ops->auto_load_enabled (extlang);
 }
 \f
+
+/* 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);
+       }
     }
 }
 
This page took 0.032229 seconds and 4 git commands to generate.