From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065057.outbound.protection.outlook.com [40.92.65.57]) by sourceware.org (Postfix) with ESMTPS id 0F2F6386102D for ; Thu, 3 Jun 2021 05:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0F2F6386102D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DXf3S6QCsyK43W6VNRaVShgm3sIFKvh4aeg+LubYCrXBWO9KWutUddHf1iQbmKidLI4e38Vtc2lAQ44EUm5M2EdAfvZPqwkzxk+ol3t5OwpAMLdYgyZwtbrNkVCo86dr7kfzBIvNTkj3hX/Y0p30KAf0ESrFYDZCvrvo+uQHQNMfP8Uf5gI2ghsUojQ7o2E/hlQdXOEjQhda7LgXc+5V6ZzaktLXED+PKCQmuNdefxY8Pv5C9Ui5i8jqiK7/JUehB9JCk7QIGC2yTcY7IOdL8aTIRGMR9IWtQLc907eetpPmK1SiqAcsGy5oLqVWyPY1d26bu6pg+ifa7gcERfL3fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GYbWXnGjlQPjqhepWROBm9uCB22pcLND7R7ZdqdS+Xw=; b=M0bVAP1z/rpPVoiBgNtNfe0yyJdyiVFOx7gpLp1kgcbArBVuki/j+lAF6TCtvZAA6RZjXexmZFyqz58HZe+r1lx3Szzn506+I4VdZkrUmVtS1tmMAXfPw3/rdemEKGXdogxEO70dNo9eQw8kPwIPMwVOPHMNMHR4AJb5dHMep1oRLkjNJYqg14p1ZYUHJAzRfHBV5EhDW180GWzqS0SbjhfYUjBKzrFjBXs3z6ybM4TuZNKAPDR/eFTB9v2wRkn+FYpb40XTWdHFsiE02Vke6TeGYnm4+J4uEaS96OYKNafy8UvMGt2RX3oUZBd9RcdKBnQBUZeh+ps1GhtPqIi/IQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DB5EUR01FT029.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e1a::49) by DB5EUR01HT136.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e1a::497) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18; Thu, 3 Jun 2021 05:45:07 +0000 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:7e1a::4c) by DB5EUR01FT029.mail.protection.outlook.com (2a01:111:e400:7e1a::241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18 via Frontend Transport; Thu, 3 Jun 2021 05:45:07 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:71DFF87DC7E4AC1517F9A38D4CAFBEFDDB03914267BC93DFAEAD4FDCB6C10F09; UpperCasedChecksum:0487559387DFB58BE674D6156626C39FD90B738446DAE6C02431FBE2B64E9B9B; SizeAsReceived:8881; Count:48 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::ad12:6a2c:b949:f65d]) by AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::ad12:6a2c:b949:f65d%5]) with mapi id 15.20.4195.023; Thu, 3 Jun 2021 05:45:07 +0000 Subject: Re: [PATCH] Fix gdb crash due to SIGPIPE when the compile command fails To: Christian Biesinger , Tom Tromey Cc: "gdb-patches@sourceware.org" References: <87tumgp1ob.fsf@tromey.com> From: Bernd Edlinger Message-ID: Date: Thu, 3 Jun 2021 07:45:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TMN: [NLz9GJsivGktJVCoBqLUHP1qJ3gq1fTx] X-ClientProxiedBy: PR3P189CA0025.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:52::30) To AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:364::23) X-Microsoft-Original-Message-ID: <449fb528-a06e-9a1f-b71d-88e7a04a87a4@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (84.57.61.94) by PR3P189CA0025.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:52::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Thu, 3 Jun 2021 05:45:06 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: cb354eb2-e9fd-43ad-505c-08d92652be0c X-MS-TrafficTypeDiagnostic: DB5EUR01HT136: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L1eyntEuXjv4rQK4EN4Kthxp/uTEZNkB3sVUe5rhb6b4BvuwbHvifvp9vuv+ImtdpsLY+lF5jh8RUykddUGj7hMHEng0D9MnjhUrs4/yfS0awHfHdx2sPrZMTJtgaFCL9Txx1B2e9V6AXCeftWWHIWrgAxbsxHms66pE+ejJqQTOuIB2c42oJBu/FKNKz89CN0O6PHHLbooLU+znBZt9i8KTJFizDjnabiwohqXn2ue9wI538U1SjGIP6nNWdlP/qGXgBE/PZrlGC+V0lvNxFEXGe1bkKK/B6Bm227gmfcSFbp5BrBLAgPSeTdxE/kesP0cgsK7ZG2DpZb92WAm+RZdgqAxdQpTjWw0B7xh54jrdKB2qijlgGWtF+1/HLEoTtTwQMK1JSqd/cBy5+giKDA== X-MS-Exchange-AntiSpam-MessageData: XWmUCKP1dYo2mNM8M+K36+jYV+mQBtSTQTvGSe3XsNHxyHfTd0jgussUtMoiXapZZmCxV5UObblWAEOHaKkO+KqTe1bwS8iX/R11pm5y8BkNrD76HALNPFWNdyYbb+KJbxpLGkpfoyVx6yQNbm70UA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb354eb2-e9fd-43ad-505c-08d92652be0c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2021 05:45:07.0075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB5EUR01FT029.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR01HT136 X-Spam-Status: No, score=4.2 required=5.0 tests=BAYES_00, FOREIGN_BODY, FOREIGN_BODY1, FORGED_MUA_MOZILLA, FREEMAIL_FROM, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: **** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2021 05:45:11 -0000 On 6/3/21 12:19 AM, Christian Biesinger wrote: > On Wed, Jun 2, 2021 at 1:22 PM Tom Tromey wrote: >> >>>>>>> "Bernd" == Bernd Edlinger writes: >> >> Bernd> Due to the SIGPIPE the gdb process is killed here, which is >> Bernd> not helpful. >> >> Bernd> 2021-06-02 Bernd Edlinger >> >> 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(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=, c=) at ../../gcc-trunk/libcc1/connection.cc:33 #2 0x00007ffff7e128c4 in cc1_plugin::invoker::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=) at ../../gcc-trunk/libcc1/connection.cc:135 #4 0x00007ffff7e1708c in cc1_plugin::connection::wait_for_query (this=) at ../../gcc-trunk/libcc1/connection.hh:82 #5 cc1_plugin::base_gdb_plugin::fork_exec (stderr_fds=0x7fffffffd778, spair_fds=0x7fffffffd770, argv=0x12fe060, this=) at ../../gcc-trunk/libcc1/gdbctx.hh:248 #6 cc1_plugin::base_gdb_plugin::do_compile (s=, filename=) at ../../gcc-trunk/libcc1/gdbctx.hh:315 #7 0x00000000005058e4 in compile_instance::compile (this=, filename=, verbose_level=) at ../../binutils-gdb/gdb/compile/compile.c:914 #8 0x0000000000506387 in compile_to_object (scope=, cmd_string=, cmd=) 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=, from_tty=) at ../../binutils-gdb/gdb/compile/compile.c:341 #11 0x00000000004ddbb2 in cmd_func (cmd=, args=, from_tty=) at ../../binutils-gdb/gdb/cli/cli-decode.c:2176 #12 0x0000000000776c82 in execute_command (p=, 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=) at ../../binutils-gdb/gdb/event-top.c:193 #19 0x000000000059d940 in stdin_event_handler (error=, 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=, argv=) 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.