aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2021-06-02 19:21:15 +0200
committerBernd Edlinger <bernd.edlinger@hotmail.de>2021-06-05 19:35:44 +0200
commit4a977544657ae51a33447b4c4211009dacb09bdd (patch)
treee53a817d0288c549dc684c1859a1269575951de0 /gdb/compile
parent8ff8c543b4a6da9abbba7f406f13ba844cfe6d94 (diff)
downloadgdb-4a977544657ae51a33447b4c4211009dacb09bdd.zip
gdb-4a977544657ae51a33447b4c4211009dacb09bdd.tar.gz
gdb-4a977544657ae51a33447b4c4211009dacb09bdd.tar.bz2
Fix gdb crash due to SIGPIPE when the compile command fails
Due to the SIGPIPE the gdb process is killed here, which is not helpful. 2021-06-05 Bernd Edlinger <bernd.edlinger@hotmail.de> * compile/compile.c (scoped_ignore_sigpipe): New helper class. (compile_to_object): Ignore SIGPIPE before calling the plugin.
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8481d14..8247fc4 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -633,6 +633,33 @@ print_callback (void *ignore, const char *message)
fputs_filtered (message, gdb_stderr);
}
+/* RAII class used to ignore SIGPIPE in a scope. */
+
+class scoped_ignore_sigpipe
+{
+public:
+ scoped_ignore_sigpipe ()
+ {
+#ifdef SIGPIPE
+ m_osigpipe = signal (SIGPIPE, SIG_IGN);
+#endif
+ }
+
+ ~scoped_ignore_sigpipe ()
+ {
+#ifdef SIGPIPE
+ signal (SIGPIPE, m_osigpipe);
+#endif
+ }
+
+ DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigpipe);
+
+private:
+#ifdef SIGPIPE
+ sighandler_t m_osigpipe = NULL;
+#endif
+};
+
/* Process the compilation request. On success it returns the object
and source file names. On an error condition, error () is
called. */
@@ -755,6 +782,10 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
fnames.source_file ());
+ /* If we don't do this, then GDB simply exits
+ when the compiler dies. */
+ scoped_ignore_sigpipe ignore_sigpipe;
+
/* Call the compiler and start the compilation process. */
compiler->set_source_file (fnames.source_file ());
ok = compiler->compile (fnames.object_file (), compile_debug);