public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Tom Tromey <tom@tromey.com>
Cc: Christian Biesinger <cbiesinger@google.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix gdb crash due to SIGPIPE when the compile command fails
Date: Sat, 5 Jun 2021 13:44:03 +0200	[thread overview]
Message-ID: <AM8PR10MB470861E21A75983D4DA1CA19E43A9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <87zgw5oijf.fsf@tromey.com>

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

On 6/4/21 3:39 PM, Tom Tromey wrote:
>>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> 
> Bernd> I believe it is right to avoid the SIGPIPE before calling the plugin,
> Bernd> instead of doing that in gcc-trunk, since we don't know which version
> Bernd> we will be calling, and all versions I tried have failed like this.
> 
> That seems fine, but I think it would be better to install the handler
> just when working with the plugin, and then uninstall it afterward, sort
> of like what class scoped_ignore_sigttou does.
> 

Okay, done, that works for me.

Is this OK?


Thanks
Bernd.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-gdb-crash-due-to-SIGPIPE-when-the-compile-comman.patch --]
[-- Type: text/x-patch; name="0001-Fix-gdb-crash-due-to-SIGPIPE-when-the-compile-comman.patch", Size: 1833 bytes --]

From 3bb3966601a89c18ea2700c3eae4aa4f4e195269 Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date: Wed, 2 Jun 2021 19:21:15 +0200
Subject: [PATCH] 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-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* compile/compile.c (compile_to_object): Ignore SIGPIPE before calling
	the plugin.
---
 gdb/compile/compile.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8481d14..3431d4c 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -633,6 +633,33 @@ struct compile_options
   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 SIGTTOU
+    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 @@ struct compile_options
     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);
-- 
1.9.1


  reply	other threads:[~2021-06-05 11:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02 17:31 Bernd Edlinger
2021-06-02 18:21 ` Tom Tromey
2021-06-02 22:19   ` Christian Biesinger
2021-06-03  5:45     ` Bernd Edlinger
2021-06-04 13:39       ` Tom Tromey
2021-06-05 11:44         ` Bernd Edlinger [this message]
2021-06-05 12:04           ` Andrew Burgess
2021-06-05 12:27             ` Bernd Edlinger
2021-06-05 14:04               ` Tom Tromey
2021-06-14 11:41           ` Rainer Orth
2021-06-14 12:57             ` Bernd Edlinger
2021-06-14 12:59               ` Rainer Orth
2021-06-14 14:36                 ` Bernd Edlinger
2021-06-14 14:39                   ` Rainer Orth
2021-06-14 15:07                 ` Tom Tromey
2021-06-15 11:10                   ` Rainer Orth
2021-06-14 15:04               ` Tom Tromey
2021-06-14 23:35         ` Pedro Alves
2021-06-15  5:14           ` Bernd Edlinger
2021-06-15 11:16             ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM8PR10MB470861E21A75983D4DA1CA19E43A9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM \
    --to=bernd.edlinger@hotmail.de \
    --cc=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).