public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Christian Biesinger <cbiesinger@google.com>, Tom Tromey <tom@tromey.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix gdb crash due to SIGPIPE when the compile command fails
Date: Thu, 3 Jun 2021 07:45:05 +0200	[thread overview]
Message-ID: <AM8PR10MB4708150476BB66FA3ECD5CB2E43C9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAPTJ0XHgMKfGrnu-0EFeZeJxTiyKtaREC6S7jxVAqFYPXqQ5iw@mail.gmail.com>

On 6/3/21 12:19 AM, Christian Biesinger wrote:
> On Wed, Jun 2, 2021 at 1:22 PM Tom Tromey <tom@tromey.com> wrote:
>>
>>>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>>
>> Bernd> Due to the SIGPIPE the gdb process is killed here, which is
>> Bernd> not helpful.
>>
>> Bernd> 2021-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>
>>
>> Bernd>  * compile/compile.c (compile_to_object): Ignore SIGPIPE before calling
>> Bernd>  the plugin.
>>
>> I don't understand why gdb gets a SIGPIPE here.
>> Could you explain it a bit more?
> 
> Also, if we determine that this is necessary, this does not seem like
> right way to do this. If gdb wants to globally ignore SIGPIPE, it
> should probably do that in general startup code, maybe in
> async_init_signals. If it should only be done for this specific call,
> it should reset it afterwards.
> 

Sorry, I apparently sent the reply to the wrong message.
I believe this is necessary, since this works around a bug
in a plugin that is not in the binutils-gdb source tree.

what I did is this:

gdb --args gdb ./compile-cplus-anonymous
GNU gdb (GDB) 11.0.50.20210601-git
...
(gdb) r
Starting program: /home/ed/gnu/gdb-install-1/bin/gdb ./compile-cplus-anonymous
...
(gdb) b main
Haltepunkt 1 at 0x401165: file /home/ed/gnu/gdb-build-1/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.compile/compile-cplus-anonymous.cc, line 71.
(gdb) r
Starting program: /home/ed/gnu/gdb-build-1/gdb/testsuite/outputs/gdb.compile/compile-cplus-anonymous/compile-cplus-anonymous 
(gdb) compile code var = anon_e
[Detaching after fork from child process 4880]
*** WARNUNG *** es gibt aktive Plugins – bitte Fehler nur dann melden, wenn diese auch ohne alle Plugins reproduziert werden können.
Ereignis                         | Plugins
PLUGIN_PRE_GENERICIZE            | libcp1plugin
PLUGIN_GGC_MARKING               | libcp1plugin
PLUGIN_PRAGMAS                   | libcp1plugin
gdb command line: In Funktion »void _gdb_expr(__gdb_regs*)«:
gdb command line:1:1: interner Compiler-Fehler: in set_decl_context_in_fn, bei cp/name-lookup.c:3359
0x6f03a1 set_decl_context_in_fn
	../../gcc-trunk/gcc/cp/name-lookup.c:3359
0x6f03a1 do_pushdecl
	../../gcc-trunk/gcc/cp/name-lookup.c:3633
0xa99c42 do_pushdecl
	../../gcc-trunk/gcc/cp/name-lookup.c:3852
0xa99c42 pushdecl(tree_node*, bool)
	../../gcc-trunk/gcc/cp/name-lookup.c:3852
0x7ffff7fa044c safe_pushdecl
	../../gcc-trunk/libcc1/libcp1plugin.cc:654
...
0x7ffff7fa6aa1 cc1_plugin::connection::do_wait(bool)
	../../gcc-trunk/libcc1/connection.cc:135
0x7ffff7f98f1d cc1_plugin::connection::wait_for_result()
	../../gcc-trunk/libcc1/connection.hh:75
0x7ffff7f98f1d cc1_plugin::status cc1_plugin::call<int, gcc_cp_oracle_request, char const*>(cc1_plugin::connection*, char const*, int*, gcc_cp_oracle_request, char const*)
	../../gcc-trunk/libcc1/rpc.hh:116
0x7ffff7f98f1d plugin_binding_oracle
	../../gcc-trunk/libcc1/libcp1plugin.cc:101
0xa965e7 query_oracle
	../../gcc-trunk/gcc/cp/name-lookup.c:2387
Thread 1 "gdb" received signal SIGPIPE, Broken pipe.
0x00007ffff704b34d in write () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0  0x00007ffff704b34d in write () from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007ffff7e1816f in cc1_plugin::connection::send (this=<optimized out>, c=<optimized out>)
    at ../../gcc-trunk/libcc1/connection.cc:33
#2  0x00007ffff7e128c4 in cc1_plugin::invoker<int, gcc_cp_oracle_request, char const*>::invoke<(anonymous namespace)::cp_call_binding_oracle> (conn=0xee03b0) at ../../gcc-trunk/libcc1/libcp1.cc:81
#3  0x00007ffff7e183c2 in cc1_plugin::connection::do_wait (this=0xee03b0, want_result=<optimized out>)
    at ../../gcc-trunk/libcc1/connection.cc:135
#4  0x00007ffff7e1708c in cc1_plugin::connection::wait_for_query (this=<optimized out>) at ../../gcc-trunk/libcc1/connection.hh:82
#5  cc1_plugin::base_gdb_plugin<gcc_cp_context>::fork_exec (stderr_fds=0x7fffffffd778, spair_fds=0x7fffffffd770, argv=0x12fe060, 
    this=<optimized out>) at ../../gcc-trunk/libcc1/gdbctx.hh:248
#6  cc1_plugin::base_gdb_plugin<gcc_cp_context>::do_compile (s=<optimized out>, filename=<optimized out>)
    at ../../gcc-trunk/libcc1/gdbctx.hh:315
#7  0x00000000005058e4 in compile_instance::compile (this=<optimized out>, filename=<optimized out>, verbose_level=<optimized out>)
    at ../../binutils-gdb/gdb/compile/compile.c:914
#8  0x0000000000506387 in compile_to_object (scope=<optimized out>, cmd_string=<optimized out>, cmd=<optimized out>)
    at /home/ed/gnu/install/include/c++/12.0.0/bits/basic_string.h:193
#9  eval_compile_command (cmd=0x0, cmd_string=0x124bb4d "var = anon_e", scope=COMPILE_I_SIMPLE_SCOPE, scope_data=0x0)
    at ../../binutils-gdb/gdb/compile/compile.c:789
#10 0x00000000005070dc in compile_code_command (args=<optimized out>, from_tty=<optimized out>)
    at ../../binutils-gdb/gdb/compile/compile.c:341
#11 0x00000000004ddbb2 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>)
    at ../../binutils-gdb/gdb/cli/cli-decode.c:2176
#12 0x0000000000776c82 in execute_command (p=<optimized out>, p@entry=0x124bb40 "compile code var = anon_e", from_tty=1)
    at ../../binutils-gdb/gdb/top.c:674
#13 0x000000000059e8ed in command_handler (command=0x124bb40 "compile code var = anon_e") at ../../binutils-gdb/gdb/event-top.c:588
#14 0x000000000059ec0b in command_line_handler (rl=...) at ../../binutils-gdb/gdb/event-top.c:773
#15 0x000000000059f1d0 in gdb_rl_callback_handler (rl=0xcce3c0 "compile code var = anon_e")
    at ../../binutils-gdb/gdb/event-top.c:218
#16 0x00000000007f8e08 in rl_callback_read_char () at ../../../binutils-gdb/readline/readline/callback.c:281
#17 0x000000000059db2e in gdb_rl_callback_read_char_wrapper_noexcept () at ../../binutils-gdb/gdb/event-top.c:176
#18 0x000000000059f0be in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at ../../binutils-gdb/gdb/event-top.c:193
#19 0x000000000059d940 in stdin_event_handler (error=<optimized out>, client_data=0xcccd10)
    at ../../binutils-gdb/gdb/event-top.c:515
#20 0x00000000008ca836 in gdb_wait_for_event (block=block@entry=1) at ../../binutils-gdb/gdbsupport/event-loop.cc:701
#21 0x00000000008caa7d in gdb_wait_for_event (block=1) at ../../binutils-gdb/gdbsupport/event-loop.cc:597
#22 gdb_do_one_event () at ../../binutils-gdb/gdbsupport/event-loop.cc:237
#23 0x0000000000654f05 in start_event_loop () at ../../binutils-gdb/gdb/main.c:421
#24 captured_command_loop () at ../../binutils-gdb/gdb/main.c:481
#25 0x00000000006568d5 in captured_main (data=data@entry=0x7fffffffdd80) at ../../binutils-gdb/gdb/main.c:1353
#26 gdb_main (args=args@entry=0x7fffffffddb0) at ../../binutils-gdb/gdb/main.c:1368
#27 0x0000000000427b65 in main (argc=<optimized out>, argv=<optimized out>) at ../../binutils-gdb/gdb/gdb.c:32


So the plugin forks, executes gcc, and does something that
causes gcc to crash.
Now the plugin uses a pipe to send more commands to the already died
gcc, and since the write is sending data to a closed pipe, the SIGPIPE
is sent to the gdb process which dies immediately.

I believe it is right to avoid the SIGPIPE before calling the plugin,
instead of doing that in gcc-trunk, since we don't know which version
we will be calling, and all versions I tried have failed like this.


Bernd.


  reply	other threads:[~2021-06-03  5:45 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 [this message]
2021-06-04 13:39       ` Tom Tromey
2021-06-05 11:44         ` Bernd Edlinger
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=AM8PR10MB4708150476BB66FA3ECD5CB2E43C9@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).