From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id 4F46D3858C74 for ; Mon, 7 Mar 2022 07:59:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F46D3858C74 X-IronPort-AV: E=McAfee;i="6200,9189,10278"; a="315045085" X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="315045085" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2022 23:59:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,161,1643702400"; d="scan'208";a="595415556" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by fmsmga008.fm.intel.com with ESMTP; 06 Mar 2022 23:59:46 -0800 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sun, 6 Mar 2022 23:59:46 -0800 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sun, 6 Mar 2022 23:59:45 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Sun, 6 Mar 2022 23:59:45 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.102) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Sun, 6 Mar 2022 23:59:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ck9V0cF6Kb36FIWRU60ZunXRTiq5MtOpPIvR0+C7ppacoM9qC8K34T5VkA3n3sextvfUMjUKT2DIWgXENPPXxCNK9n3/JHaVN8gsebDxpErh2zFEpSDBPGwo3xBpCmQ5G8KJu1b5LZIQ37G4jwt92WB90/7p4DFyqKEjVXYaXGlLrL45iRKf68by5KAuollpHksuXjTSWIJI5bcw4grpfwrQ+2x0AjFrzhduqsINjcrEXcUIgKWo8qUjg3tD11Xg9rjBMxlJSE5phja3XOr7vHZhCViZo/4Sc0nYGX7yRRm24vkth+HVtSPurU1Tr8a8ee1iC7W779r8rv9MFD/9pg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2YgbzbRzKW+AAsUL575xnXlkQyH2iWrvAwy2Y3OY66g=; b=BDbwy575Y35utcPQ2OpsQ7vof8n7r/hJtzxnNQDIx+/g1MRuSoQ3VY7g8WrYDcyhdarBXZ05d9CU4wXpcijdz6d4BhxM5JoSK/tJDvxRVyTNoKJJDgHhNoxwSeov8uQFdFN8qMYGbiExaG2NZhqSJ8QM744b/cjsXVn6/qgN5Ow4QPCTilNVf09viQ1wdHzwlotwYGoc+p94hBhyx82RRjsaAFT7pAN1J7m1304K5ZzbEGoHSZeLqtitoo567u33oKH4SPc+HJRaO9lQnWkW5FKbS3kiZjiWCT80HExM3NyKmeNlQMjepQsM4ouxmllwVn2vdu0H5LD5ubQtp9EwvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MWHPR1101MB2271.namprd11.prod.outlook.com (2603:10b6:301:52::23) by CY4PR11MB2037.namprd11.prod.outlook.com (2603:10b6:903:2f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Mon, 7 Mar 2022 07:59:43 +0000 Received: from MWHPR1101MB2271.namprd11.prod.outlook.com ([fe80::f973:7917:ae14:e120]) by MWHPR1101MB2271.namprd11.prod.outlook.com ([fe80::f973:7917:ae14:e120%9]) with mapi id 15.20.5038.027; Mon, 7 Mar 2022 07:59:43 +0000 From: "Aktemur, Tankut Baris" To: "gdb-patches@sourceware.org" Subject: RE: [PATCH] gdb/remote: use current_inferior in read_ptid if multi-process not supported Thread-Topic: [PATCH] gdb/remote: use current_inferior in read_ptid if multi-process not supported Thread-Index: AQHYHYrKsEy5jWNowkWFlMMNVDjwZqyztzoA Date: Mon, 7 Mar 2022 07:59:42 +0000 Message-ID: References: <20220209075824.3070-1-tankut.baris.aktemur@intel.com> In-Reply-To: <20220209075824.3070-1-tankut.baris.aktemur@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.401.20 dlp-product: dlpe-windows dlp-reaction: no-action x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d3b04c2e-eca8-412c-75f6-08da00107052 x-ms-traffictypediagnostic: CY4PR11MB2037:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2KLVpQWsa4Svw73amnlH2HaGtW9fMH3FbnmCcV1VX8oJ7qDy4/CQp/xwuWQ1pofwtICVZbPLgX1QN7oA9Rkc51iyeU3aCHySuzZ+GYSmgfnpF46uUHGSgHWLOsx/OFzTAzPUX0qNCz9FI5lC441UViEGn7bprxsN2NTAaY+QsLGVjv6P3ecSUzmHU6X2poW4HLqjRnsBdv/XZXbUgzbieiuNOlR19B0o1/IdUGAMWkFG1WItuWrwRKgZCwqV+eKoaTyTPSXQe6JXfLxaXK67buCDfegoYL1YRxO0PdIeYdpvkfg2/Z2NN+FfCr2fRjbWG+McUtkeIInWnXAgWfqS9zdfQRsVqETr8NHLQMlixFCBm/PeDPsVrciN97RNYdAj+Q9na7K09UP6nS7XxUkjs9a02/FqJfhKsktzvryFhH9HUyvgutAzqdhKWaAHk4/og+CZ+UnbmbBDQFWzPBaWPGb3uK8I5mO81t6Akm0/etxLgZReETDW7TV1D9JdKci89MoYw1BXEKwEELP8Br1dtwwA1jTwTSVWaNUxFt1ddOeL8jXPUbrHNmi2ZIu5viz46cQRR83WT6x8B8Q2I1EI9D63rexTQKrizZq0EDrZVCrDBFAk8YSxsVWCnIaQPS6YCBrm2Qtj3MtIA5WNPK8jNSpi3bfOio0H5/gHfdROkukCPFxCCscY6tC6mJ/XJrpz7xK579z1VywH7xCpA1Un29Zs5m0nNCRDF0F1lxZv9Gy6BV8HTidUV5MJ9+lHwx597Sv2LcHsbDdgazDLZo5/Gtp/u0KOmrejOSpKZuCUFmWgzHI9m7TcyEjKtJ1q0p06 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1101MB2271.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(5660300002)(82960400001)(2906002)(122000001)(186003)(83380400001)(86362001)(33656002)(508600001)(8936002)(6916009)(55016003)(30864003)(66946007)(316002)(66446008)(66556008)(66476007)(52536014)(76116006)(9686003)(64756008)(8676002)(38100700002)(38070700005)(6506007)(71200400001)(7696005)(53546011)(26005)(2004002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?LfeyKOrWfDlhg9xt0tUrxTJ6kzQClzEjpk4W755y9Hr8Z/6Cla1Tq4G65oJY?= =?us-ascii?Q?tlhSrfrLzhKVu4YzMSMyvio0Zw/+/Hgk7wrqdMYw5RteKFPwz87oXTvXXLEH?= =?us-ascii?Q?nLImyLy6eVaGOeBiWlPQlE9a5134KYvW5jTdh2kiHpfge2gSD1ReXn4BYzpz?= =?us-ascii?Q?dCHPvm+RVfE4+HVsLuwsAeKZj4WvCiCTJL+KuirlQM0hp3jxIIg+NbVSj+LF?= =?us-ascii?Q?Tx0mHMpR3p37pMGV8Eu+joqdznnByEJ7ouW7dURy8qy1sFWxsEQpAXhdWdlk?= =?us-ascii?Q?BKaQpfP8VOyGJvCR6yGcXU6vcUUHME3g/6N8JUA0Asz/kA+FxHJkNXIwj5rQ?= =?us-ascii?Q?1wSkH7b+22i7cIHVFylT3K1luLiMKE3OEzBrvc0HRO0xAdbDZsPfhvbDpOUb?= =?us-ascii?Q?JRD3t4QKaB1gOExDoR745YdfNa2iUxy0TZHuAd0SZtBxZ7CLaH+24W5grLF2?= =?us-ascii?Q?2sH8vpe0JqCqkkJ5NAa9SKTRE6o7uSkj7U6m4OOhyrWg0UT3KzxMpSybOWWv?= =?us-ascii?Q?B60DGlml6ocLRT+w2SnWVHJGOHC+No7VggNQiTTLfgqBJw3qsY/OKnyZKc7r?= =?us-ascii?Q?w8ws5C0/C9UoV+MJGj9XK+zI4xzfaSdJNuFtwY6SrodYf8OvgNbvJGp08ZDw?= =?us-ascii?Q?GufRKyQAy0zm3uX36bPK75jj6rZfkTjdo9sfM+hGNgEzfgU9WZxiHxFnAr8x?= =?us-ascii?Q?SBIGCGjBcBGwp4cTLABvUgTCT9LdT55RfWPIfAi/i4Rfo7Jf7//ugesyNzhI?= =?us-ascii?Q?T/U683KkP8uBz0MT3EKOXhvzT6OICSfJ1XrAnqzlkpmYKkTlAc2s/zmV7Ljc?= =?us-ascii?Q?qI+x58IOsfjiDTXr9YBSFj7M23y8VLaMlCkDlx6edem4RlS6iFwhnMnGJxex?= =?us-ascii?Q?AoFsYNHdI6IaLQNXv83Tlra3ovbovcXJYs+e+rNVR/wijyOsgwq/lsQbCbc1?= =?us-ascii?Q?0hSKsi5gIZnbBuUVYemnXM6aKI6dWsNp1PyY194N/lzeo1SyiXjg5CKUCUMu?= =?us-ascii?Q?c2KI23FGCpYqYqepmXuNJY7KmwZnOMHXtpI3zCHDPt7ewx/FG9VhXKNTJqGd?= =?us-ascii?Q?l9YXAFIc1pl85UbebjRGhI43aPcKy0+9rDg4ufr9lIz3/wMOEikEKwWhkQGl?= =?us-ascii?Q?XaIth09s1PC9N0pLsSUMAlyC+Tjf3Y1418a2P72HMagu1mijwZm9gyr85CPm?= =?us-ascii?Q?/zTKCei+OIrVhbY2oM/mRjOAFeQrQKka+GqkXK9UUdTuUkwiqI+Sejr9ZUE3?= =?us-ascii?Q?jQWCKZdJzOdPXXt7i9V2R4DufjHOdtLzW0/wp0xoFbo6htW3DMlWFgRixChE?= =?us-ascii?Q?ZZ3usvDKeNJBQDisonDBPRSG6xPimBfKOFk7/npYQpSgZ5JGgCqvaCLqp+Tu?= =?us-ascii?Q?xVFggKC+Bxm5BcnrLPw0W9JOnDqBK3uuWVkUMn4g9bKwMYAG1pHwM4eLcNLJ?= =?us-ascii?Q?LlbXHZb3msq0XG82R6AiwBaSJN3AiGsY/YeD8js+25jD1GSgA0hOXW7AZU33?= =?us-ascii?Q?mj9dZzlpFjAHUuVdl1h0KdPKzWI9fp4UD9VJ6ShcdsU0Ck/Bchc9QvpJ1uCd?= =?us-ascii?Q?SYHYlehQk2GTWTx0ARQpqK+yae8psUJC/j9e1FFaTRJ8hMDnvXPuN60UJ6l/?= =?us-ascii?Q?h7kf5ktPhuwUwg740anAqj6Vgg/CNnOsx4WwUY8YQZexerUAghQVogTy/SMI?= =?us-ascii?Q?fNSgfA=3D=3D?= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR1101MB2271.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3b04c2e-eca8-412c-75f6-08da00107052 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Mar 2022 07:59:42.9025 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: YcyDpDL6+ZjscVLYPmEDV70w9Psirs4Y9U0F9HNVg4zNhia5AnRsb7WInR9d9GsT4jqO/lNJhqxMxjCXALpd7UpehLdQyqPa1rpHJkRh+9g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR11MB2037 X-OriginatorOrg: intel.com Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 07 Mar 2022 08:00:00 -0000 Kindly pinging. = Thanks -Baris On Wednesday, February 9, 2022 8:58 AM, Aktemur, Tankut Baris wrote: > When parsing the ptid out of a reply package, if the multi-process > extensions are not supported, use current_inferior's pid as the pid of > the reported thread, instead of inferior_ptid. This is needed because > the inferior_ptid may be null_ptid although a legit context exists, > due to a prior context switch via switch_to_inferior_no_thread. > = > Below is a scenario that illustrates what could go wrong. First, > setup a multi-target scenario. This is needed, because in a > multi-target setting, the inferior_ptid is cleared out before waiting > on targets. The second inferior below sits on top of a remote target. > Multi-process packets are disabled. > = > $ # First, spawn a process with PID 26253 to attach to later. > $ gdb-up a.out > Reading symbols from a.out... > (gdb) maint set target-non-stop on > (gdb) set remote multiprocess-feature-packet off > (gdb) start > ... > (gdb) add-inferior -no-connection > [New inferior 2] > Added inferior 2 > (gdb) inferior 2 > [Switching to inferior 2 [] ()] > (gdb) target extended-remote | gdbserver --multi - > Remote debugging using | gdbserver --multi - > Remote debugging using stdio > (gdb) attach 26253 > Attaching to Remote target > Attached; pid =3D 26253 > [New Thread 26253] > [New inferior 3] > Reading /tmp/a.out from remote target... > ... > [New Thread 26253] > ... > Reading /usr/local/lib/debug/....debug from remote target... > >>> GDB seems to hang here. > = > After attaching to a process and reading some library files, GDB > seems to hang. One interesting thing to note is that > = > [New Thread 26253] > = > appears twice. We also see > = > [New inferior 3] > = > Running the same scenario with "debug infrun on" reveals more details. > = > ... > (gdb) attach 26253 > [infrun] scoped_disable_commit_resumed: reason=3Dattaching > Attaching to Remote target > Attached; pid =3D 26253 > [New Thread 26253] > [infrun] infrun_async: enable=3D1 > [infrun] attach_command: immediately after attach: > [infrun] attach_command: thread 26253.26253.0, executing =3D 1, resum= ed =3D 0, state =3D > RUNNING > [infrun] clear_proceed_status_thread: 26253.26253.0 > [infrun] reset: reason=3Dattaching > [infrun] maybe_set_commit_resumed_all_targets: not requesting commit-re= sumed for target > native, no resumed threads > [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed = for target > extended-remote > [infrun] fetch_inferior_event: enter > [infrun] scoped_disable_commit_resumed: reason=3Dhandling event > [infrun] do_target_wait: Found 2 inferiors, starting at #1 > [infrun] random_pending_event_thread: None found. > [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], s= tatus) =3D > [infrun] print_target_wait_results: 26253.26253.0 [Thread 26253], > [infrun] print_target_wait_results: status->kind =3D STOPPED, sig = =3D GDB_SIGNAL_0 > [infrun] handle_inferior_event: status->kind =3D STOPPED, sig =3D GDB= _SIGNAL_0 > [infrun] start_step_over: enter > [infrun] start_step_over: stealing global queue of threads to step,= length =3D 0 > [infrun] operator(): step-over queue now empty > [infrun] start_step_over: exit > [infrun] context_switch: Switching context from 0.0.0 to 26253.26253.0 > [infrun] handle_signal_stop: stop_pc=3D0x7f849d8cf151 > [infrun] stop_waiting: stop_waiting > [infrun] stop_all_threads: starting > [infrun] stop_all_threads: pass=3D0, iterations=3D0 > [New inferior 3] > Reading /tmp/a.out from remote target... > warning: File transfers from remote targets can be slow. Use "set sysro= ot" to access files > locally instead. > Reading /tmp/a.out from remote target... > Reading symbols from target:/tmp/a.out... > [New Thread 26253] > [infrun] stop_all_threads: 4723.4723.0 not executing > [infrun] stop_all_threads: 26253.26253.0 not executing > [infrun] stop_all_threads: 42000.26253.0 executing, need stop > [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], s= tatus) =3D > [infrun] print_target_wait_results: -1.0.0 [Thread 0], > [infrun] print_target_wait_results: status->kind =3D IGNORE > [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], s= tatus) =3D > [infrun] print_target_wait_results: -1.0.0 [Thread 0], > [infrun] print_target_wait_results: status->kind =3D IGNORE > = > GDB tried to stop Thread 42000.26253.0, which does not exist, and we > are waiting for a stop event that will never happen. The PID in > '42000.26253.0', namely 42000, is the PID of magic_null_ptid. > It comes from gdb/remote.c:read_ptid: > = > /* Since the stub is not sending a process id, then default to > what's in inferior_ptid, unless it's null at this point. If so, > then since there's no way to know the pid of the reported > threads, use the magic number. */ > if (inferior_ptid =3D=3D null_ptid) > pid =3D magic_null_ptid.pid (); > else > pid =3D inferior_ptid.pid (); > = > if (obuf) > *obuf =3D pp; > return ptid_t (pid, tid); > = > Because multi-process was turned off, GDB did not parse an explicitly > specified PID. Furthermore, inferior_ptid =3D=3D null_ptid, and > eventually GDB picked the PID from magic_null_ptid. > = > If target-non-stop is not turned on at the beginning, the same bug > reveals itself as a duplicated thread as shown below. > = > # Same setup as above, without 'maint set target-non-stop on'. > ... > (gdb) attach 26253 > Attaching to Remote target > Attached; pid =3D 26253 > [New inferior 3] > ... > [New Thread 26253] > ... > (gdb) info threads > Id Target Id Frame > 1.1 process 13517 "a.out" main () at test.c:3 > * 2.1 Thread 26253 "a.out" 0x00007f12750c5151 in read () from target:= /lib/x86_64-linux- > gnu/libc.so.6 > 3.1 Thread 26253 "a.out" Remote 'g' packet reply is too long (expec= ted 560 bytes, got > 2496 bytes): > 00feffffffffffff000a3a75127f000051510c75127f0000000400000000000060d24ef6a= f550000000000000000 > 0000680d000000000000b85b31e3fc7f0000c0283a75127f000000e55b75127f000010d04= ef6af55000046020000 > 0000000060c73975127f0000a0d23975127f0000000a3a75127f000000000000000000005= 1510c75127f00004602 > 0000330000002b00000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 00000000000000000000000000007f03000000000000ffff0000000000000000000000000= 0000000000000000000 > 80143a75127f000080143a75127f000040143a75127f000040143a75127f00007d0000007= e0000007f0000008000 > 0000300c3a75127f0000300c3a75127f00000e000000000000000e0000000000000000000= 0000000000000000000 > 00000000ffffffffffffffffffffffffffffffff040000000400000004000000040000002= 0143a75127f00002014 > 3a75127f00000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000801f00000000000000000= 00000e55b75127f0000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000= 0000000000000000000 > 000000000000000000000000 > (gdb) > = > Fix the problem by preferring current_inferior()'s pid instead of > magic_null_ptid. > = > Regression-tested on X86-64 Linux. > = > Co-authored-by: Aleksandar Paunovic > --- > gdb/remote.c | 9 +- > .../gdb.multi/attach-no-multi-process.c | 34 +++++++ > .../gdb.multi/attach-no-multi-process.exp | 90 +++++++++++++++++++ > 3 files changed, 129 insertions(+), 4 deletions(-) > create mode 100644 gdb/testsuite/gdb.multi/attach-no-multi-process.c > create mode 100644 gdb/testsuite/gdb.multi/attach-no-multi-process.exp > = > diff --git a/gdb/remote.c b/gdb/remote.c > index 49eeb63445d..281260af971 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -3145,14 +3145,15 @@ read_ptid (const char *buf, const char **obuf) > return null_ptid; > } > = > - /* Since the stub is not sending a process id, then default to > - what's in inferior_ptid, unless it's null at this point. If so, > + /* Since the stub is not sending a process id, default to > + what's current_inferior, unless it's null at this point. If so, > then since there's no way to know the pid of the reported > threads, use the magic number. */ > - if (inferior_ptid =3D=3D null_ptid) > + inferior *inf =3D current_inferior (); > + if (inf =3D=3D nullptr || inf->pid =3D=3D 0) > pid =3D magic_null_ptid.pid (); > else > - pid =3D inferior_ptid.pid (); > + pid =3D inf->pid; > = > if (obuf) > *obuf =3D pp; > diff --git a/gdb/testsuite/gdb.multi/attach-no-multi-process.c > b/gdb/testsuite/gdb.multi/attach-no-multi-process.c > new file mode 100644 > index 00000000000..df09dd69ccc > --- /dev/null > +++ b/gdb/testsuite/gdb.multi/attach-no-multi-process.c > @@ -0,0 +1,34 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2020-2022 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see .= */ > + > +/* This program is intended to be started outside of gdb, and then > + attached to by GDB. */ > + > +#include > + > +int > +main () > +{ > + /* Don't run forever in case GDB crashes and DejaGNU fails to kill > + this program. */ > + alarm (10); > + > + while (1) > + ; > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.multi/attach-no-multi-process.exp > b/gdb/testsuite/gdb.multi/attach-no-multi-process.exp > new file mode 100644 > index 00000000000..0ba99351ec5 > --- /dev/null > +++ b/gdb/testsuite/gdb.multi/attach-no-multi-process.exp > @@ -0,0 +1,90 @@ > +# This testcase is part of GDB, the GNU debugger. > + > +# Copyright 2020-2022 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test attaching to a process, as a second inferior, through a > +# gdbserver that does not support multi-process extensions. > + > +load_lib gdbserver-support.exp > + > +standard_testfile > + > +# The plain remote target can't do multiple inferiors. > +if {[target_info gdb_protocol] !=3D ""} { > + return > +} > + > +if {![can_spawn_for_attach]} { > + return > +} > + > +if {[build_executable "build" $testfile $srcfile {debug}] =3D=3D -1} { > + return -1 > +} > + > +proc test {target_non_stop} { > + global binfile > + > + save_vars { ::GDBFLAGS } { > + # Make GDB read files from the local file system, not through the > + # remote targets, to speed things up. > + set ::GDBFLAGS "${::GDBFLAGS} -ex \"set sysroot\"" > + clean_restart ${binfile} > + } > + > + gdb_test_no_output "set remote multiprocess-feature-packet off" > + gdb_test_no_output "maint set target-non-stop ${target_non_stop}" > + > + # Start the first inferior. > + if {![runto_main]} { > + return > + } > + > + # The second inferior is an extended remote. > + gdb_test "add-inferior -no-connection" "Added inferior 2.*" \ > + "add the second inferior" > + gdb_test "inferior 2" ".*Switching to inferior 2.*" \ > + "switch to inferior 2" > + set res [gdbserver_start "--multi" ""] > + set gdbserver_gdbport [lindex $res 1] > + gdb_target_cmd "extended-remote" $gdbserver_gdbport > + > + # Start a program, then attach to it. > + set spawn_id_list [spawn_wait_for_attach [list $binfile]] > + set test_spawn_id [lindex $spawn_id_list 0] > + set testpid [spawn_id_get_pid $test_spawn_id] > + gdb_test "attach $testpid" \ > + "Attaching to Remote target.*" \ > + "attach to the program via remote" > + > + # Check that we have two threads. Bad GDB duplicated the > + # thread coming from the remote when target-non-stop is off; > + # or hanged during attach when target-non-stop is on. > + gdb_test "info threads" \ > + [multi_line \ > + " Id\[^\r\n\]+" \ > + " 1\.1\[^\r\n\]+" \ > + ". 2\.1\[^\r\n\]+" > + ] > + > + # Clean the spawned process and gdbserver. > + gdbserver_exit 0 > + kill_wait_spawned_process $test_spawn_id > +} > + > +foreach_with_prefix target_non_stop {off on} { > + test $target_non_stop > +} > -- > 2.33.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva = Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928