From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wARFCgiSFGItOgAAWB0awg (envelope-from ) for ; Tue, 22 Feb 2022 02:34:32 -0500 Received: by simark.ca (Postfix, from userid 112) id 21F221F3CB; Tue, 22 Feb 2022 02:34:32 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BF3B21F0E7 for ; Tue, 22 Feb 2022 02:34:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 317F3385ED4C for ; Tue, 22 Feb 2022 07:34:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 317F3385ED4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1645515270; bh=5Z54qof/OzUI6hepBpgP0fcTV2RMP+Yp+x8rO3K6/gY=; h=To:Subject:Date:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=F8UlTzmEsMI+z4r0LEoXiZ/RksLGQX4gfJcMy+LApFXzQKb8C//yZQ37qu2dCwPgM AX+QZ14NL+9TTIgSMBNusXG/CREr0ihHFrBeVcrbLsyyrNe6cHlsxNW3nAxAKe5B98 qGIsv006OR2InyRZknvUsv1BV4fL81wldyDsS5X8= Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id 2DE25385801C for ; Tue, 22 Feb 2022 07:33:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DE25385801C X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="312377542" X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="312377542" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 23:33:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="507882765" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by orsmga006.jf.intel.com with ESMTP; 21 Feb 2022 23:33:54 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 21 Feb 2022 23:33:53 -0800 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 21 Feb 2022 23:33:53 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) 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.20 via Frontend Transport; Mon, 21 Feb 2022 23:33:53 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.108) 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.20; Mon, 21 Feb 2022 23:33:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d+ZhoMxbLZUxuhsVxBYtVKGHKMnXz+2CzyAiIfga5bka/j0G/OFdUd4tpZUo1yzS/INWENK3nHfZ0mYzfGZ8nvJx2Z7PoT2GJPfqHhGOXm8Uag+eoayj0ZHjBmCJ2GWrI7vHFgt238EeIq7gHCRpTVxhDG7tBtBemNrSedmvGqjnWUOsz6N00wYDNPU0NfrgJfmZPP2IUTxDA/FuW+wAWjI4q4JjWtWzxMNMhpK0TDMOdRunZ22xtBAzE5L69Nabf/IyHiT/28KSgopYmY/lpRfi7t9v3SUJjkTmAI9zc0m9wVHUVhmgGjN3yav1QN51isHOd/QV7tzX6SLHzIV+Ag== 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=iiuEs/coDb+8KFKsqBg/OAWN4cOhAMn13h6tEr6M+tfHF//0PvEUKQMC4E5eCs4X22Qtmb9W+hyV0s0iD4+yRHhK0DU77m0KBIiD589NPNTIy8x6ovbc8PytRjWzp+tO7uB/suLeN2KB0/mP5O2NuGztCguSnGJ35e0g8qdbBV3GD0WkBHzu9KYMONiZZ0WHytcPWulFFIuO2iIXqiEuLmWLFxCZM0lzrQwox3nCcY3/x7ACenWSR8HYqujNkc1pPyPbtU8Wa+Rqb0yEiozxvOoLIyrxEzezMEUZ2c8ZVMlauFz+U3EWfKDFg12ksJa8Wvi+3g3KtWEjVzYzY2xWOw== 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 DM6PR11MB3210.namprd11.prod.outlook.com (2603:10b6:5:e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Tue, 22 Feb 2022 07:33:51 +0000 Received: from MWHPR1101MB2271.namprd11.prod.outlook.com ([fe80::acbc:9a8:49e2:4a38]) by MWHPR1101MB2271.namprd11.prod.outlook.com ([fe80::acbc:9a8:49e2:4a38%5]) with mapi id 15.20.4995.027; Tue, 22 Feb 2022 07:33:51 +0000 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: AQHYHYrKsEy5jWNowkWFlMMNVDjwZqyfQbeQ Date: Tue, 22 Feb 2022 07:33:51 +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.200.16 dlp-product: dlpe-windows dlp-reaction: no-action x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c12c5c29-240f-47ec-e4bf-08d9f5d5ac1c x-ms-traffictypediagnostic: DM6PR11MB3210: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: KmWNAbvsU/Hnmg5TC4majdxFHGRHAyYdZu25snFOEaj/d3JOPm5xDw4doM/F211E/Xa750lJY2deogCm13BufAET+aTXWbEAmsYQrF4D7BALon4wDZAdMSvCsg7hXz78O/JpwDFkYu3V+3QfVSwmo5LhHT1yri09K5fFFsQbOn1cXOQ9OIpXhnprvYBI/O3S9AM9P8PI1urrZkk4CSjpHeGYeR4R9QLyOd6s6YuKPwie/XrsJ+uBOSbakgbgboFzUAEdk2T7IVc3bal08opRthfadXxxzlrGsUE835gXAbzYYKd+hDTnLByORAAfbSNT32dodzbaRNdcPgkdb+NQiFjJ/6RqjaXdQv0kts2cjAUFrAwgmnFhedyql3JVFvaZAsJp7wwgNCxCpH0kqVYUQxSevVtZVXXkCSvGwamCSBkL47DRHrD8wsa0wbmiNgw32JDnA0D1jGufx6q+PIrOzvcLuUGixsfP0S3O1uaN5ntC0hm11Ahn6YMLYhG+Y5FNr4EVJvCReq9xe/RraCdrSsN4zoIbcEhCJshS0oBtWooH+q1EfPi5vx7Fwt2a62IBfFowGDC7ibEBUh12genH6p16U7DLITvR5c82WBHfvPMZK8G5DgUEkNPsVUJz6JJZkLvd3yIwyEcQeNRs09Dfuc77y7jwYfckoStS/lxZYFPJw6qp3g+RTHdQPLFeSJoQ8F9Np79QlNF0JRKbX6RxAEOa2ktlsVTUu4T+AyS8555JNbhbcJAa7C+LaAr2+coXjr7Y+nBJztSH0bpJBZO28WqxQzo3sjoEdiBCt1wGwhixQVdTxOpY2JK75ejo89IA 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)(33656002)(508600001)(66946007)(9686003)(53546011)(186003)(26005)(38070700005)(6916009)(55016003)(71200400001)(7696005)(316002)(86362001)(6506007)(2906002)(8936002)(38100700002)(76116006)(8676002)(122000001)(82960400001)(5660300002)(66556008)(66476007)(66446008)(64756008)(83380400001)(52536014)(30864003)(2004002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?2HyA9s8axdupulD45cHk9XrVFhZY2/kjia2XFE0Djt4Qh/l6c9Iq4TbkiThQ?= =?us-ascii?Q?aMbPslaDcBh6Avxc2+7Tb/CoRdLO7bMVM9kCro/3S8AITMZE4Pj9pA2DrILs?= =?us-ascii?Q?NsztXP8N51eBfxsjuUpzJMrXyYyDW/ImpLs2vPPXsCrRHENjCLjTCqr3WmgZ?= =?us-ascii?Q?a1tKdKN4Z3GSo957sInrDjOSsFgemDVBN8LHtXnYacHYY8FQQ1+8DiUxtQQ4?= =?us-ascii?Q?1Eueh6ui43iQcSJIk0TpgsjVoGYhej2dngOcZaVTRI9IWfKwOt42RTU8ViLB?= =?us-ascii?Q?FilTyBQtUZ+2jT+DAQ0FsHRh1X74HVg5nKsEgrw0YOWiMmoU0wDT95BKtFfb?= =?us-ascii?Q?XN5xYEajSLBsJnuy0ImlPDXbq76aayj0GCeRSHzhhMH7btWGk61OJJWRk93Y?= =?us-ascii?Q?cA3Rcrb3bqnRUkbo/0h1sqC3wny0uDVCRKqbqXv7KWFLKhL2IPaS4gYV8wAN?= =?us-ascii?Q?VQ3j+nSJsW31w+Bs9XVX6mwBh2B93+2VjPoWTlA209y+VsIJjRIrF7QLXrA8?= =?us-ascii?Q?1nBIeFnuDuhPgkFf1w/DFM+AAr5Gq5QJUEzmVCKsb9SctCq6+mHGtUFtumo3?= =?us-ascii?Q?VlhVEoJm/5xRZA0MyyTZE/B0Fd3yUYpRnvKHQ5D661TQJmXM5oJq1RjsgZCN?= =?us-ascii?Q?H+hn+EN7BgmtSDmgIF/1Az4/ZsPxWF5ErivdBPFEEyXl+1psOnHGhzcD3+39?= =?us-ascii?Q?eq1dG+o4i5tx24ihFHi2/hgGBvE899uIkHPDjuKhqmupX0MjAKeDlPwLJXdw?= =?us-ascii?Q?t22XDr3DopYYVK2D0H+XuIrYeXT2GPYRea/KjX1IzhPbjpIT1yQGietIvwcW?= =?us-ascii?Q?iO4t/l4vsME1TrekSZFy2EJwz2AoSIeP1JH/al4deZDM2972vA8aHksltlOk?= =?us-ascii?Q?w86roxzxyAe2cnU2TiO6W+y5Numr5WDRrG/9imWfsEYov4QnkagvvZLp8c4e?= =?us-ascii?Q?HXP2W3RatUFlmO2Wa56CEG9qq1ZJwoen0CCzFz37mYoJS/5hGzZU4A/9j1JR?= =?us-ascii?Q?CNjKY3OCWmNWZKScRfHmYxOGv0+IdmRMZC+cjLl+VodISUYuPpcM7oGxPJUe?= =?us-ascii?Q?aq62QtP1UHOmideBtP/LHbrDafJ0heIdKDgoWG6HMhlD0FrMx+djJ2X15Qtk?= =?us-ascii?Q?o4pPUWM2uoDXelynYbgTHIcV6v14lYhpvvWNweydBWqM55jqq3nvNbKbpFxZ?= =?us-ascii?Q?bVVUhVJhEOLd43dMSkhPqQPPY8/N6/S1q7zHZAmO/Gzt5Smuk2gHiqGr2/w7?= =?us-ascii?Q?sQH6YAYH1C0LXGOISh8lZM9nv6dm5EHyMNBPScnihkYmv7okQkOrghoZ8gwd?= =?us-ascii?Q?6tz6YwkiGWG+FwDW4iiGJjh8ZvxssqmA5IBkS2TH2EwKbpLs/ti93INQqLI/?= =?us-ascii?Q?In+gaAizcODwdHYaOSW9D4rxwTMMtdJg7zgC2rZwe8QJLZcB6R/v8X2N5Kq7?= =?us-ascii?Q?FFn42OaMBJcifeGzeI4SJYDiy9nVCeZwEknz4BYnL7ddgnynmKnuZmZxPwWg?= =?us-ascii?Q?fWGb+QVxEY/GFJDZwP5AzgdX8rRg74pbIjtYJbM9yJVyoDBJDP75qD36Heg7?= =?us-ascii?Q?BA7l5l4w/1r5vYRSEkyLhgKiIRcggjdpNEZ7nXrSckyGpVrlO8L73v00q1P0?= =?us-ascii?Q?JHBh+cRvCsCJdv84yOQ6lXDCkvD8Ib73EvP3A/5gWM/fKM2PUtpKyVFySuxC?= =?us-ascii?Q?6kZ4WQ=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: c12c5c29-240f-47ec-e4bf-08d9f5d5ac1c X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Feb 2022 07:33:51.3581 (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: TNcCY1R7cqCpyJlP2SWkSmbFeaqQHQ35wSuM2Be36Rfpy6nzdH52MoQKqHtxGXvryJ/xMjLfjBeg149VDBDs2JvEc329gbC13Z02J0EouaU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3210 X-OriginatorOrg: intel.com Content-Transfer-Encoding: quoted-printable 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: , From: "Aktemur, Tankut Baris via Gdb-patches" Reply-To: "Aktemur, Tankut Baris" Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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