From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2053.outbound.protection.outlook.com [40.107.20.53]) by sourceware.org (Postfix) with ESMTPS id 5EE833858D1E for ; Mon, 9 Oct 2023 14:07:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EE833858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cPaVKEhk5N3JXEekQXA7KI5QvJYaCF3wlOKs342q0lc=; b=m7WCZQ8d2xhi8XBrr0pHO2UfPtwfYz1ZJYh8xk9ttv0u7fOwBEu6mqrx8jwMF/Hxa0jgC3qyE7l05TI8KDfEmf97nfHitU65JHnFeaUxAC1xEdhcI4pfkVCD+TifbrsF43tJf88SdhEI+1lwzZG50KV3+LXJTYiUeicDakAoRj4= Received: from AS8PR04CA0160.eurprd04.prod.outlook.com (2603:10a6:20b:331::15) by GV2PR08MB9255.eurprd08.prod.outlook.com (2603:10a6:150:e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.36; Mon, 9 Oct 2023 14:07:37 +0000 Received: from AM7EUR03FT063.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:331:cafe::57) by AS8PR04CA0160.outlook.office365.com (2603:10a6:20b:331::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.37 via Frontend Transport; Mon, 9 Oct 2023 14:07:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT063.mail.protection.outlook.com (100.127.140.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.23 via Frontend Transport; Mon, 9 Oct 2023 14:07:37 +0000 Received: ("Tessian outbound fdf44c93bd44:v211"); Mon, 09 Oct 2023 14:07:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5a76796c5a61d9ee X-CR-MTA-TID: 64aa7808 Received: from 9cafe8e0f528.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 5B9DAC86-B47A-4EF6-B808-327FD93A5531.1; Mon, 09 Oct 2023 14:07:30 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9cafe8e0f528.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 09 Oct 2023 14:07:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=badIZ1tbA9HfL/+XLeVEgmX1ZX7nXkZmGGA70MkxslhNL6BD8Oj6HKlxXuc0SrhLp9S8Sc3kF0duWVRpcSGDsuvWKsK5mZpGO0UKPixi2exXrtl+f6HwNpchWsR8KzZJYuz0nxWajxeDyojhTxD4v4wvl9KyI/kE88A9BgzW4ZZcjcvNbBkqr8oQ87ixBdFbUcucjDAb3jCiHdE3dRd1sMY6K+IZyqQboyXewJglNNzzRo10boCilWhh0Xf2jfixBcgL9SxRg42DP+7h2LjGigqHew9phjQFqvFisv9MLvJIE+vH45fWp2oUH1gZRvi/c5fzC04V2xKQi9xZRbUpYw== 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=cPaVKEhk5N3JXEekQXA7KI5QvJYaCF3wlOKs342q0lc=; b=RyrPF3NdMOsMikalSqWVmjkkCORKiOdN2R+Yv0fsg5Z+eHdlkhZOq+GOwSk6Qp83D8bDG6CR7BVVnUr7X510Hi/bZhExEBxcZ7U6NAHcez57dK2xzDv45EXy99kQaYyRbQmSMV2xlt/nkUeApm6WrCDxCB6U3HvuDbD/sRY7EDZaaNlYmPiTWv5PEUcQU51v+atdkn4EU6oU1oGllP54wcUR9MwsDs3rRRlDmyRtAdvPBngNpsocrTxC3za/WlMJk8xFcsuFL2BJopHTs9tQ3ZuamyInbr1/5ZlPARLkWr8/tiwVCL0lk7FMDx4aTVCVKQLt9KflpLpEhDZquM1mbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cPaVKEhk5N3JXEekQXA7KI5QvJYaCF3wlOKs342q0lc=; b=m7WCZQ8d2xhi8XBrr0pHO2UfPtwfYz1ZJYh8xk9ttv0u7fOwBEu6mqrx8jwMF/Hxa0jgC3qyE7l05TI8KDfEmf97nfHitU65JHnFeaUxAC1xEdhcI4pfkVCD+TifbrsF43tJf88SdhEI+1lwzZG50KV3+LXJTYiUeicDakAoRj4= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3911.eurprd08.prod.outlook.com (2603:10a6:20b:80::27) by AM8PR08MB5603.eurprd08.prod.outlook.com (2603:10a6:20b:1d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Mon, 9 Oct 2023 14:07:27 +0000 Received: from AM6PR08MB3911.eurprd08.prod.outlook.com ([fe80::146d:342:e715:2475]) by AM6PR08MB3911.eurprd08.prod.outlook.com ([fe80::146d:342:e715:2475%7]) with mapi id 15.20.6838.040; Mon, 9 Oct 2023 14:07:27 +0000 Message-ID: Date: Mon, 9 Oct 2023 15:07:25 +0100 User-Agent: Mozilla Thunderbird Subject: [PING] [PATCH, v2] Only allow closure lookup by address if there are threads displaced-stepping Content-Language: en-US To: gdb-patches@sourceware.org, simon.marchi@polymtl.ca References: <20230929081503.4014732-1-luis.machado@arm.com> <20231002065636.695118-1-luis.machado@arm.com> From: Luis Machado In-Reply-To: <20231002065636.695118-1-luis.machado@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0179.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::23) To AM6PR08MB3911.eurprd08.prod.outlook.com (2603:10a6:20b:80::27) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3911:EE_|AM8PR08MB5603:EE_|AM7EUR03FT063:EE_|GV2PR08MB9255:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d9fe5a5-f4fc-48ee-e69c-08dbc8d117d4 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Rtkx9cUad0dOaeRy5X2b8/54/Au9GeWfhwg+RHLRp4ypBIcSDrundJrDi5jdZdphKlbbvrDyev0W4D/DWBJQphdAa8h4ebH9yrRGtj7pZRV46dNrNZzHMslUjd/W7ARThIjz/mp7HEyqQeoL2RQs71yqpaZaPe8U+/LxdNdUdNKB7nhh3g8gKXmp6OIcpwCIXcHls3fjgFMuhcept5HT0VJ3YLG+z+AL1PrPkkNE131yRTwS9XR/zALTU1ZFjXk2gouNWtCzdqIg9hmeRXDQYuh07UWirG4YA/ThMfZp8qGvvG50b2TzYkq1YSTsS8z/Risz6sKlofq/VOLRnE4HqmHq781phC4aJb/RdLp+2WsPXh5ltsZNig9kq/gX1ULgsOLmqlhdzOOtFf6LMzyGpRyID90QLrWvyyay5xb32HTfv7rVgd7G6MTo/lI4xoQ9eo2IfyxGczdSZcu836JIZSC8ilAPIW+9YMa3P+OJXVo10c8kwCPXo5mePVoF3h9tIp6eZSKh8LcRJDKNuVVLvgoFvdo7UQC5Tf8ryuw0aSQj8lOhDD8Sk96UvVy4asTc3MTYf00xeM9Dio6r5CsqADTj5fsD2Gt7t1I5VwjqjcwvRkzUdNly2onqaOGY1SsOv5zR0gyFcULd1TtyWZ26XPk3loH/9SaRAhl4AhNxuBr2R1noUseeegnbjKJs9yHD X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR08MB3911.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(396003)(366004)(376002)(346002)(39860400002)(230922051799003)(451199024)(1800799009)(186009)(64100799003)(31686004)(36756003)(31696002)(86362001)(2616005)(6512007)(5660300002)(44832011)(6486002)(53546011)(2906002)(478600001)(66946007)(66476007)(66556008)(41300700001)(316002)(6506007)(966005)(26005)(8676002)(8936002)(83380400001)(38100700002)(2004002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5603 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 3f0ed3c7-60bb-4b6e-2be8-08dbc8d11193 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aNY6otZpk/jvud8R1ibTi2nisd8eDWm0XBcjQJs2EVjsKdliyKFDyEPM/szjBxBpfq2AMEs9DfC0LCOx74LlHOLowKghmQUHvmLAxpZlhHgMzo2H0g0YLbIFRQMyvqh/aPRm+5twaV5insN9RCvG313uQkVmSw0bRrVRyu7YKfmJ8KLS5iZLIztdwzag7qqtMYMSvYAGaiLLZp8OPI1+rdTeVmctNQoIiiSTIhtndU5DrwC8Xm/vqHkX5grjeJsO+rfyUnwxNIAiZ0Z0qdHVKoNclZTd01Tg7wOK9J+iVBR46UQ35YOQI2bNyZb33B0yhMONOH+gquYwlWx8JufR3k925wKJNFTRa+5O+uIMC8rrOu7oR1rwMQmwqaDoR+BAjInDq1qx/YwCjK7OQOqo5KFxuSp7slGAwmkHhFeFeLPfIR6YqeVAmh4qVSJJWmjSOtqisC0WauKero+buGHrKTJmrmCryMeLNjBHXhEmb2bl5Sr53+blLEJDZWndjXGaKDFAqrUiDUXC2/5ti600w4kLBZvelPq/Owukm/AC5ie38zLqmQX4hmipvJHcWSem8E4Qtd5ZKiHwyzaPIq382pF5LfeNHDKdyr5AlYySxAW4X2NHHKfBkZMkeZGeVineYfZBLGBDRTzT2kCGcrxU1c4z7s16X50gQCgbGYDVcdNDZ7ds5bUt7dq9NLJCl2sz1P6EfKxhDZe7UsaaPThraEPunOJzAjYu0BFqjuLJY4dkSeg2Yd0kNnVMFbZGLDsYaLq5jF+0dS677zKxjvcjsWMqp5dnUXLetFyx3YkbsKX3SNnX3xhJ/vs9MbDMBRfV X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(39860400002)(136003)(346002)(396003)(230922051799003)(82310400011)(64100799003)(186009)(1800799009)(451199024)(46966006)(40470700004)(36840700001)(5660300002)(53546011)(2616005)(26005)(336012)(36860700001)(6512007)(478600001)(8676002)(47076005)(8936002)(83380400001)(2906002)(6506007)(70206006)(70586007)(6486002)(41300700001)(44832011)(966005)(316002)(40460700003)(81166007)(356005)(36756003)(86362001)(31696002)(82740400003)(40480700001)(31686004)(2004002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2023 14:07:37.5824 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d9fe5a5-f4fc-48ee-e69c-08dbc8d117d4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9255 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 10/2/23 07:56, Luis Machado via Gdb-patches wrote: > Updated on v2: > > - Added missing license to test file. > - Formatting fixes. > - Made the testcase always run. > > Since commit 1e5ccb9c5ff4fd8ade4a8694676f99f4abf2d679, we have an assertion in > displaced_step_buffers::copy_insn_closure_by_addr that makes sure a closure > is available whenever we have a match between the provided address argument and > the buffer address. > > That is fine, but the report in PR30872 shows this assertion triggering when > it really shouldn't. After some investigation, here's what I found out. > > The 32-bit Arm architecture is the only one that calls > gdbarch_displaced_step_copy_insn_closure_by_addr directly, and that's because > 32-bit Arm needs to figure out the thumb state of the original instruction > that we displaced-stepped through the displaced-step buffer. > > Before the assertion was put in place by commit > 1e5ccb9c5ff4fd8ade4a8694676f99f4abf2d679, there was the possibility of > getting nullptr back, which meant we were not doing a displaced-stepping > operation. > > Now, with the assertion in place, this is running into issues. > > It looks like displaced_step_buffers::copy_insn_closure_by_addr is > being used to return a couple different answers depending on the > state we're in: > > 1 - If we are actively displaced-stepping, then copy_insn_closure_by_addr > is supposed to return a valid closure for us, so we can determine the > thumb mode. > > 2 - If we are not actively displaced-stepping, then copy_insn_closure_by_addr > should return nullptr to signal that there isn't any displaced-step buffers > in use, because we don't have a valid closure (but we should always have > this). > > Since the displaced-step buffers are always allocated, but not always used, > that means the buffers will always contain data. In particular, the buffer > addr field cannot be used to determine if the buffer is active or not. > > For instance, we cannot set the buffer addr field to 0x0, as that can be a > valid PC in some cases. > > My understanding is that the current_thread field should be a good candidate > to signal that a particular displaced-step buffer is active or not. If it is > nullptr, we have no threads using that buffer to displaced-step. Otherwise, > it is an active buffer in use by a particular thread. > > The following fix modifies the displaced_step_buffers::copy_insn_closure_by_addr > function so we only attempt to return a closure if the buffer has an assigned > current_thread and if the buffer address matches the address argument. > > Alternatively, I think we could use a function to answer the question of > whether we're actively displaced-stepping (so we have an active buffer) or > not. > > I've also added a testcase that exercises the problem. It should reproduce > reliably on Arm, as that is the only architecture that faces this problem > at the moment. > > Regression-tested on Ubuntu 20.04. OK? > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30872 > --- > gdb/displaced-stepping.c | 3 +- > .../gdb.base/displaced-step-closure.c | 21 ++++++++++ > .../gdb.base/displaced-step-closure.exp | 39 +++++++++++++++++++ > 3 files changed, 62 insertions(+), 1 deletion(-) > create mode 100644 gdb/testsuite/gdb.base/displaced-step-closure.c > create mode 100644 gdb/testsuite/gdb.base/displaced-step-closure.exp > > diff --git a/gdb/displaced-stepping.c b/gdb/displaced-stepping.c > index bc59ef01478..41c3c999d1e 100644 > --- a/gdb/displaced-stepping.c > +++ b/gdb/displaced-stepping.c > @@ -277,7 +277,8 @@ displaced_step_buffers::copy_insn_closure_by_addr (CORE_ADDR addr) > { > for (const displaced_step_buffer &buffer : m_buffers) > { > - if (addr == buffer.addr) > + /* Make sure we have active buffers to compare to. */ > + if (buffer.current_thread != nullptr && addr == buffer.addr) > { > /* The closure information should always be available. */ > gdb_assert (buffer.copy_insn_closure.get () != nullptr); > diff --git a/gdb/testsuite/gdb.base/displaced-step-closure.c b/gdb/testsuite/gdb.base/displaced-step-closure.c > new file mode 100644 > index 00000000000..8540538e915 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/displaced-step-closure.c > @@ -0,0 +1,21 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2023 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 . */ > + > +int main (int argc, char **argv) > +{ > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/displaced-step-closure.exp b/gdb/testsuite/gdb.base/displaced-step-closure.exp > new file mode 100644 > index 00000000000..3389cd4f0de > --- /dev/null > +++ b/gdb/testsuite/gdb.base/displaced-step-closure.exp > @@ -0,0 +1,39 @@ > +# Copyright 2023 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 file is part of the gdb testsuite. > +# > +# Test a displaced stepping closure management bug, where a closure lookup > +# by address returns a match even if no displaced stepping is currently > +# taking place. > + > +standard_testfile > +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { > + return -1 > +} > + > +if ![runto_main] { > + return -1 > +} > + > +# We have a breakpoint at the current pc (from stopping at main). Step over > +# the breakpoint. > +gdb_test "stepi" ".*" "step-over breakpoint" > + > +# Now attempt to disassemble the entry point function, where the displaced > +# stepping buffer is. With the bug, gdb will crash when we attempt to list > +# the PC that was used to displaced-step the previous instruction. > +gdb_test "disassemble _start" ".*End of assembler dump\." \ > + "disassemble through displaced-step buffer"