From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by sourceware.org (Postfix) with ESMTPS id 4DD8B3858C2C for ; Wed, 23 Mar 2022 20:33:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4DD8B3858C2C ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T6HG996RQ8nk4Ly4V+WdrLKXxcrjMF15LEkMfgPDPU8PKITpG4Ru7pigfx6tRheczq33HmZcCeiFybvRIXpZZNaLCbAkKlCqrkp9MZNMaH+HLNl0PW0iSShZ++574f4j5Bu3UhmcTFwSaKnE0YeMwXShYmETn+UklJ4itQEN6jSLl56kRy8gluCJISEdniaifP17AgOREN5wGgGJ7YCosJ//ij75a6ng2+21YVXzB7fdK8PgmB0dP5fiWgpq24s0l8649hDDC12tqeezH5TGNofFl4+cRak3mK5Y7pISAjrCyBWRInEX3k5AICAQ85ZBCHkuOOOn4yZ5YDgtoosFpQ== 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=blSM9OjIEIYoboOCrBq8evtk/sxrx6xq9zYllVMZ2z4=; b=m8mxlEXBA8AADBehGmtV1d+0ImYJxBpgYndaAF+5TqrFtMo31mltPCztjljQAZ8RAaIBWhGA3gNL5Q79UReNSxZiBIir1a5T+QtkzbEBk00X3RfNyNxxNDPBYr3HtfIsLJyEs3+b/XU/bQxxRKQ76CNtOpWOdxJ6UTr8kCclWlTSeKOyZKflCvPt0k2qOaaTDuQlpqz/iJiuaENtCcMDV68MljsbF4btMQZJaaSvs6Ncp3GxKkxx+4hGyCIag8vg4zcvUI+q9mI5aoPuzuCkUt/4r0r7G2kuMJ+HgZd1DRuddx27KvoQ0Diq/z1vi21Wn6i3A5Hp5I8IY0+B6/IoOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=labware.com; dmarc=pass action=none header.from=labware.com; dkim=pass header.d=labware.com; arc=none Received: from DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) by MW5PR17MB5987.namprd17.prod.outlook.com (2603:10b6:303:1c7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.23; Wed, 23 Mar 2022 20:33:41 +0000 Received: from DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::b4e5:7f52:3fb8:ef7b]) by DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::b4e5:7f52:3fb8:ef7b%7]) with mapi id 15.20.5102.016; Wed, 23 Mar 2022 20:33:40 +0000 Message-ID: <8e9bae5ebe919d4ac9cc8a7cb6ef11c4ac2b0339.camel@labware.com> Subject: Re: [pushed] gdb/mi: consistently notify user when GDB/MI client uses -thread-select From: Jan Vrany To: Andrew Burgess , Simon Marchi , Simon Marchi , gdb-patches@sourceware.org Date: Wed, 23 Mar 2022 20:33:34 +0000 In-Reply-To: <87fsn8scy1.fsf@redhat.com> References: <20220316150914.1254897-1-jan.vrany@labware.com> <78570a7f-f6c0-5e1b-4178-c9ce401feab7@simark.ca> <897bd508133687e4d30994deecdd87786d71334d.camel@labware.com> <0bcb4286c01054c30c3539c76bd6426ff3b333eb.camel@labware.com> <14d27757ce39bcc7a19f74508e689acfa7fa33c2.camel@labware.com> <82992b26-8010-d7cd-8c27-5e07350d43ab@polymtl.ca> <87fsn8scy1.fsf@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.43.3-1+b1 X-ClientProxiedBy: LO2P265CA0086.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::26) To DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eddf8869-0afb-46f6-5ed0-08da0d0c6a86 X-MS-TrafficTypeDiagnostic: MW5PR17MB5987: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: 43c7sP++Wt/BLtDanXXVEvQfebFYcre0QUb16XMiBmTUr/kW5Luoh4vPc7iq0VYzEnGzO29rxW7lnQUZuKzNMCxxkX6yoUibw58mBUVmG3zW0zBew0bd+hjEhV/HmiKwWx7TPKOKzy/m8QHlVZd5Y8AZG1qDpBhOWJFtAO1i0UpZ0rfoD4Csqw/E31LNE6+GDiMwiR8lCYWbaGlGGFiQgnLOOmzLfcoxqNkctrDoIeaZzfvZvR0kKSFmSDX0vvz9LN0/l2uGHOPIT0Xv0ImJHAuU/InLszkMBcZc1IERL/AFxNzw3b3DOB+UDxaWId/V78s08pWEit5K1vtKWHtZ/ljhuoZRuxTf6I2SQmy7Yp+j0RzJPG6RJxZnlzUW8yB3Ylk5O6Wrmfo1UbuDocTwj5GS3erYnUd+q+v9bEB8H6B2sywVU+Go3DoBc7MSc7TQCvIEUmrevipzfyPfk+ZDqXxzZVyHmZwBULdZYpOJQcr8uf39DmG6+U84i9Rw847ACz6xszLTwNVbz6aD/kdV41lst1LxfobGgORyVFvmlVK6XBysXh74ngoPx9bwUBvdMn9zXdpPzG2krhDkZiDIhuMt3OyJLj5DMiVdBa6ujU/LNf9f6WjT4GuUBBNvbj6+tpFaYNxfBIpqliqutfTXcCkK5zg9rW8NyfZe/QiSdgvZrlnrMYMgoE0r1PWqnq1CJK3AvYfuVx+lfuTZ868SE7F5LYxlHYzEPJnnCrGYFFc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR17MB3113.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6666004)(2906002)(508600001)(966005)(86362001)(6512007)(6486002)(52116002)(6506007)(186003)(2616005)(38100700002)(83380400001)(66946007)(66476007)(66556008)(8676002)(110136005)(5660300002)(316002)(8936002)(44832011)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NmUvV3owMng3R1BwYm1pRkdXWFRpbVlWbnBtejd5WTFDWXdJVGViTFdHUkE2?= =?utf-8?B?TVNLRnU1bVNnNHB0VlkzSWlNakh1Y0F5aEtTZENDUzI1V0wvVnh2RlgxVkww?= =?utf-8?B?QnkraVhZbGQydkgxOFQwaXg5WGpzeW9nTUxoL3RjWGt5MzRJNDRVSEx4Z3dR?= =?utf-8?B?bHNiL3Y5R3VDbFh5dnlCTjc3RVpIRmlEaWlUTUdDSDAzSUprblhRb1NUN3N4?= =?utf-8?B?TEI1NVhQb3l4MkxzN2E0MjRXSVdMbTc2R1IzK05YMVYxNjBucStWZjhiWUIw?= =?utf-8?B?bFIyOHFsa2pJbmFFL2tOUkdyTlh6MnpnYnZkWTdDNll3TXNsNVZBREE1U1Fm?= =?utf-8?B?MDR4S203TU9LV0ZMNmY1N2oxQUtyQ3E0bENFMENuL01lQThsNzB4Yk9YeFJj?= =?utf-8?B?VDlaTWVTUlgyRU1aZ01xQVVWWU1iWDVaUWV3cEF2eDl5QmVSeHVqT0J2SXZP?= =?utf-8?B?cmJ2VXFKOHJHaGJ5UHhIS3F4N2NUdDlJakxjZ3ZnUGl1QnRPMFZrSVd1U2xR?= =?utf-8?B?TlNGWE11cWlHVXB1RzRSTlBkdnM2UUFqTk5kemJ1QlI4dXlhL1pScFdBbFlQ?= =?utf-8?B?QW1aaE9TMDYrTWtoT2RlQ2lEaWJEK25TcmlYa3RzemhuVEFSSytGNFVVVXZy?= =?utf-8?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CNzJDV0RjdDNxNmRvY1NR?= =?utf-8?B?S3RTMkdLOHVkWWp1TS9INXFiS3VGZHBCUVRtSjBVRko2dUR5R3RUbGZQMHRk?= =?utf-8?B?NTh0Z1gyQ0h1czJYeCs2L250bWlXRTFEbUhvZDFkVC9Fa2J2bUc4bnZ4Ykln?= =?utf-8?B?aWxEeDVKanRML2dnbDMxdzRiTjJTRXV1ZlV2NjdLV1VYM1hUcVNOUENpYUdl?= =?utf-8?B?V0huUENhaytQZC9FdHg5Q3g1NGFiSTQ1V1pQcEV1REhQRllSaDRuUFVicFZW?= =?utf-8?B?R013YzhGaGtubWF5Y29EdDI4V3pBdkpWbkVaOVdtSm1CWUhzL1N0U2RQbmFm?= =?utf-8?B?Q1orY1hDZUo4cXZUeE5SUStEcVRNaStoN0QzWEh5ZWRLaytsK3h6Z1hTUG9B?= =?utf-8?B?Yisvekl5U2gwNW1vT2c0Qnh4NnZnRDRyOEtRSUtaRW1yUzRXMFVUTFIyQXE4?= =?utf-8?B?eHhDLzBzYzFvUkdEL0JTWW5KRVE3R0RCenZQalFwRFN5ZEhUWGRMSFBJTEF1?= =?utf-8?B?WXExcmYwQzQ2L3ZJZTBwQXByQkR6a1ZqS0VwQT09?= X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: eddf8869-0afb-46f6-5ed0-08da0d0c6a86 X-MS-Exchange-CrossTenant-AuthSource: DM6PR17MB3113.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 20:33:40.7118 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +bfnysXv1XopJ1JywKxrou7aNyyrcFmehMWDgW4478vv2I1WwtSrurWIQcUtaJe4n8WiTpV9IQzyz0Oc8EUlDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR17MB5987 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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: Wed, 23 Mar 2022 20:33:46 -0000 On Wed, 2022-03-23 at 19:09 +0000, Andrew Burgess wrote: > Jan Vrany via Gdb-patches writes: >=20 > > On Wed, 2022-03-23 at 11:16 -0400, Simon Marchi wrote: > > > > I gave it a go but I'm sorry: everything seem to work as expected=20 > > > > here. I do not get "[Switching to thread 1 (process 1891548)]" mess= age > > > > on CLI when -thread-select already selected thread.=20 > > >=20 > > > Ok, strange. > > >=20 > > > > I must be doing something differently. What commit is failing for y= ou? > > > > What's your ./configure incantation? > > >=20 > > > My configure arguments are: > > >=20 > > > 'CC=3Dccache gcc-11' 'CXX=3Dccache g++-11' '--disable-binutils' '--di= sable-gold' '--disable-ld' '--disable-gprof' '--disable-gas' '--with-guile'= 'CFLAGS=3D-g3 -O0 > > > -fdiagnostics-color=3Dalways -fmax-errors=3D1 -fsanitize=3Daddress' '= CXXFLAGS=3D-std=3Dc++11 -g3 -O0 -fdiagnostics-color=3Dalways -fmax-errors= =3D1 -fsanitize=3Daddress - > > > D_GLIBCXX_DEBUG=3D1 -D_GLIBCXX_DEBUG_PEDANTIC=3D1 -D_GLIBCXX_SANITIZE= _VECTOR=3D1' 'LDFLAGS=3D-fuse-ld=3Dlld -fsanitize=3Daddress' '--prefix=3D/u= sr' '--enable-ubsan' '-- > > > with-python=3Dpython3' '--with-debuginfod' '--enable-silent-rules' '-= -enable-werror' > > >=20 > >=20 > > Thanks! Now it is failing for me too!=20 > > I just recompiled GDB using the above command. I'll have a=C2=A0 > > look tomorrow.=20 >=20 > These failures are totally my fault. Sorry! >=20 > The patch below should fix the problem. Let me know what you think. I wrote patch pretty much the same as yours when I noticed your email! "deprecated_SAFE_get_selected_frame()" turned out not to be as safe as we both thought it is :-) Thanks a lot! =20 Jan >=20 > Thanks, > Andrew >=20 > --- >=20 > commit fcac0d17e64a18e0600372c2bed51f9e2d9e9d6a > Author: Andrew Burgess > Date: Wed Mar 23 19:00:35 2022 +0000 >=20 > gdb/mi: fix use after free of frame_info causing spurious notificatio= ns > =20 > In commit: > =20 > commit a2757c4ed693cef4ecc4dcdcb2518353eb6b3c3f > Date: Wed Mar 16 15:08:22 2022 +0000 > =20 > gdb/mi: consistently notify user when GDB/MI client uses -threa= d-select > =20 > Changes were made to GDB to address some inconsistencies in when > notifications are sent from a MI terminal to a CLI terminal (when > multiple terminals are in use, see new-ui command). > =20 > Unfortunately, in order to track when the currently selected frame ha= s > changed, that commit grabs a frame_info pointer before and after an M= I > command has executed, and compares the pointers to see if the frame > has changed. > =20 > This is not safe. > =20 > If the frame cache is deleted for any reason then the frame_info > pointer captured before the command started, is no longer valid, and > any comparisons based on that pointer are undefined. > =20 > This was leading to random test failures for some folk, see: > =20 > https://urldefense.proofpoint.com/v2/url?u=3Dhttps-3A__sourceware.o= rg_pipermail_gdb-2Dpatches_2022-2DMarch_186867.html&d=3DDwIFaQ&c=3DsPZ6DeHL= iehUHQWKIrsNwWp3t7snrE-az24ztT0w7Jc&r=3DWpFFGgYa98Yp-c29WHTCwU1wAGFBvszA6a4= RzgpMSqc&m=3DfuC61Jpzxz_BRT-kfZ5C3exaG0I5TSRJt2JTG-bPdV8&s=3Dyf5HLpnQ2WSg3e= 1_HMVDT5XNWSyoRYDpTsxso1TMQOE&e=3D=20 > =20 > This commit changes GDB so we no longer hold frame_info pointers, but > instead store the frame_id and frame_level, this is safe even when th= e > frame cache is flushed. >=20 > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c > index abd033b22ae..4f32bb58939 100644 > --- a/gdb/mi/mi-main.c > +++ b/gdb/mi/mi-main.c > @@ -1974,27 +1974,40 @@ struct user_selected_context > { > /* Constructor. */ > user_selected_context () > - : m_previous_ptid (inferior_ptid), > - m_previous_frame (deprecated_safe_get_selected_frame ()) > - { /* Nothing. */ } > + : m_previous_ptid (inferior_ptid) > + { > + save_selected_frame (&m_previous_frame_id, &m_previous_frame_level); > + } > =20 > /* Return true if the user selected context has changed since this obj= ect > was created. */ > bool has_changed () const > { > + /* Grab details of the currently selected frame, for comparison. */ > + frame_id current_frame_id; > + int current_frame_level; > + save_selected_frame (¤t_frame_id, ¤t_frame_level); > + > + /* If we end up trying to compare two invalid frame-id's then these > + will always report themselves as not equal. However, if we are a= t > + the top-most level of the stack then we don't want to consider th= is > + as a frame change. */ > return ((m_previous_ptid !=3D null_ptid > && inferior_ptid !=3D null_ptid > && m_previous_ptid !=3D inferior_ptid) > - || m_previous_frame !=3D deprecated_safe_get_selected_frame ()); > + || current_frame_level !=3D m_previous_frame_level > + || (current_frame_level !=3D -1 > + && !frame_id_eq (current_frame_id, m_previous_frame_id))); > } > private: > /* The previously selected thread. This might be null_ptid if there w= as > no previously selected thread. */ > ptid_t m_previous_ptid; > =20 > - /* The previously selected frame. This might be nullptr if there was = no > - previously selected frame. */ > - frame_info *m_previous_frame; > + /* The previously selected frame. The frame_id might be null_frame_id > + if no frame is currently selected. */ > + frame_id m_previous_frame_id; > + int m_previous_frame_level; > }; > =20 > static void >=20