From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2084.outbound.protection.outlook.com [40.107.14.84]) by sourceware.org (Postfix) with ESMTPS id 852DA3858414 for ; Sat, 30 Sep 2023 08:14:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 852DA3858414 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=qOcMzaoHIYv7iWSxkHkgJfOvUW0HJ1GhoxaWA0QaGho=; b=PM8zTdqsX80rjDUhqnEBfzNErzDLutQv4NJXwzBVGtuC4poZ+6NBC5c4ZNrZQYWZ6vksBjT6bd/GXptorKF3azyKqR0cL7MmyuHY7qdXtpfCWynJViyFceMNyEoRoMt4LQ0smc+MW57gfJMl9UPyHbbW7pRgrSj4miaspFLnd0c= Received: from DU2PR04CA0211.eurprd04.prod.outlook.com (2603:10a6:10:2b1::6) by DU0PR08MB7994.eurprd08.prod.outlook.com (2603:10a6:10:3e1::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26; Sat, 30 Sep 2023 08:14:23 +0000 Received: from DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b1:cafe::8) by DU2PR04CA0211.outlook.office365.com (2603:10a6:10:2b1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26 via Frontend Transport; Sat, 30 Sep 2023 08:14:23 +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 DBAEUR03FT039.mail.protection.outlook.com (100.127.142.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21 via Frontend Transport; Sat, 30 Sep 2023 08:14:23 +0000 Received: ("Tessian outbound fb5c0777b309:v211"); Sat, 30 Sep 2023 08:14:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 29474d0dffbf0e36 X-CR-MTA-TID: 64aa7808 Received: from 3125dd39de4b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 93C95AD9-C5C2-479F-B34E-6C773826190B.1; Sat, 30 Sep 2023 08:14:17 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3125dd39de4b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sat, 30 Sep 2023 08:14:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lFDQ5SBacw5YIvLHbRZbuY2T8LYCVUJVSt4g0e9oqX7lHH0V1JDDbOQtmVi9S1eL7Kq1f+hqi/r5+Nmz12UH8Lww6KmBw+quFJol91iltzBdMFEJz9LWtXfgIQNL0LQjgL/yn6u5lzACmoW5uvlG/R2MC3eO7qKxIEuJnpnDZb8ErBK87dXohLbfy9z0Oo0RNWVn2kFg2jlH8UzIs7BcoCA2FeND20BJxIV+Bx8rJ63cJ7bIOjCGrb2BYR7mvWlpF7RjqKSElPHUMeAb98h0HNs7OlJlf0HGPjqeS2XK2RIcTrr8/TeMoiBzvCfA/y81UVreCdcZEhbXMRnsclvWJQ== 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=qOcMzaoHIYv7iWSxkHkgJfOvUW0HJ1GhoxaWA0QaGho=; b=hAily1lJTiuHY6BeMjGbwhXPhlZp2ErY7FYd/IxkvsWjYLh6xKozEpoOyHpKZ6E72v/wj7HW8qfqjL6w+RLTN1ux9GQCgg5hRjas1D/tsxFDsc+8qseydLRfHQIPA9NFvptI/AMIHI0Asx7bNNbWsh6220pKYdSmQhq3NyoTDITmvhzc+Vj0YJvnb7490Xgw19jdmWEymlLq1z9fdW2uXedre/YLZEc/sozUX4WH+xusyYrEAu0FayHP7T3zJ43XHshnU7RkpldwTEXatbib+TVuqG1tz8RkbU7Q0oWkgwHz82cmgGJ1QxngBpHSpmdJIGbjaHk1HB4I3HXwu6GOGQ== 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=qOcMzaoHIYv7iWSxkHkgJfOvUW0HJ1GhoxaWA0QaGho=; b=PM8zTdqsX80rjDUhqnEBfzNErzDLutQv4NJXwzBVGtuC4poZ+6NBC5c4ZNrZQYWZ6vksBjT6bd/GXptorKF3azyKqR0cL7MmyuHY7qdXtpfCWynJViyFceMNyEoRoMt4LQ0smc+MW57gfJMl9UPyHbbW7pRgrSj4miaspFLnd0c= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AS8PR08MB6677.eurprd08.prod.outlook.com (2603:10a6:20b:39a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28; Sat, 30 Sep 2023 08:14:15 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::ec3b:5cf4:e970:6f67]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::ec3b:5cf4:e970:6f67%6]) with mapi id 15.20.6838.023; Sat, 30 Sep 2023 08:14:14 +0000 Message-ID: <42caa650-9cca-f908-ba9b-d0a325edb3ad@arm.com> Date: Sat, 30 Sep 2023 09:14:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] [gdb/arm] Only allow closure lookup by address if there are threads displaced-stepping To: Simon Marchi , gdb-patches@sourceware.org References: <20230929081503.4014732-1-luis.machado@arm.com> Content-Language: en-US From: Luis Machado In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LNXP265CA0003.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::15) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB6677:EE_|DBAEUR03FT039:EE_|DU0PR08MB7994:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d28dc10-b410-45ad-7bec-08dbc18d4164 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: 13lPKA5hn0DGtQ3uwXMMpYktAQT3SG93i/TF3zezqqU04bkv7v/SHZMpBm8Pb9zj1gIjSKll+Acjcxk8rTaS6uyf7g+7nG/Z0eLLeC/DQ53gyfUIpLWZcYpbMwChkGesKjJMU8bUZm5LgFie/iEsNNuRFJKhLXluEPIp6PXSXB6yYxhHporHxyougjLIQbbV+hjlTfho+l4606Fj4dGL77hsUKfI1eKbBmxZXK3lSD9lLVqLZ/v8DV2rTeRcNb60K+zUzYFNAePn3g8KjPyHYI1eBRT1gFGrvaegNGyi3Rcribcf/59FvAUOPH8OSypQ1h9Xowg0cttWa1esncCIRmzIsRsY49nrI9WqPV5XRMjvEsLj4sTNQ1/385ydXVmu1oz03beReQ9qD77ys4cFsa1Fc4LDb1xaQYhWzzWVU13xpN606RfBfAPx1S/PifN0thuzSBCw8SXpnyTtuQG/hTzO9sShvxPDUBMM5sFiFzonaadu/DveuZyVDYCZPkhYaJCSxVLM9hCA09lseErAb0yQt6iwVKU8tsKUcxaBhBAydLvyYQ4CqU6bSGmD0ct/JYi+PKo3JXfFW0hs7deS7g/G2koZcwLcL6fk01aBBhAfsHjwOzY7UOW2atDPGeyYDwLQcERmklyyqBInSMeEXG3vPU0H7Zjhy865c3jJqH18rUyhKlGoPnC/b0J9YvFugOdLs4hVAwo8Dtd8w0OyUZiZtafkSRUZOUQBkIZR8tKGFA/51rCQif6Rxm3VVIfo X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(376002)(39860400002)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(478600001)(26005)(966005)(6486002)(6512007)(53546011)(6506007)(38100700002)(6666004)(8676002)(8936002)(44832011)(5660300002)(66556008)(66946007)(66476007)(41300700001)(316002)(36756003)(2906002)(31696002)(86362001)(31686004)(83380400001)(2004002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6677 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: DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 6e85c80e-5d39-4978-d85c-08dbc18d3b6c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rTnUDvfLecymNSHwAzHrhy+nNyRw6N8Nm5SEsRgWiJbAXqxhXd7XD85tAIaFlU81Q7vScVIMPxzuJbsmU/XZz2d4M1eEf73N13XiyCQM1RIVp/bd3zYkxyUfxlOX2l7Sg8b5WxdIvX65cYc4X3a0HAEfEoRk5Uq36Ft/2zFg6O2hbo7hh6bo0sW5kqIDuiuawyeC56r79fLDnd5KXm72sROb8oDjflHzOPHhTCCNZA2Nfy/GrRQoFKIw8Ws+1mzKSeIc75C57qiiCM3r5Jxx9qvPwiRyZX0UMmUGVp/uypIElMxu9zJYsA1njWs6FS82gsqDdQlepTEAcTDyXELcVRRFTuZ7w4nCgtfQ1k1GbQTdvZo6rEzwkTea3Hnu8RPLJ3hBjn8e8F/uz4yWP3Z3SEo1r407F4pORBadI9RLp3mRo2o7EFi1gY4kFMkhg4TsLvYs24Dpc3pEDIPDtkhvf37PyaVC+Flh5FqAF28KWubGi314MRn23IA8CaSFPbgeXGq0h+F7L7bwHoYh5FBJ6xipejTnOVNirfuLniOMfBjb1oDCvRvTmbY50MglSbDypuqXk8qb8GRhwShycE/TTYKEce2b0ZoKIYJqfA1cKesv00lz7Dy6TmvyuVtgFZjUwVAIitXwC2Qotw/5HigBWVji9d9J6AcScXrAttbGoJRsvu9mXENKFpr+2+zzdRW48ivD1nhsPnbYBl1I2ib3t+sTcjoISx1pNHAGIscH9m1rbpuxyAW3h4CI7mDEIACKNzUalfDCWzPC+ElJhUJyM9xGXgngAS8YNVixBMO5GvQ5s1leUF+n3erpj3zddmU2 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)(136003)(39860400002)(346002)(376002)(396003)(230922051799003)(451199024)(82310400011)(1800799009)(186009)(64100799003)(40470700004)(46966006)(36840700001)(53546011)(6506007)(6512007)(83380400001)(44832011)(70586007)(316002)(70206006)(41300700001)(966005)(6666004)(478600001)(6486002)(31686004)(40480700001)(8676002)(26005)(8936002)(36756003)(2906002)(40460700003)(47076005)(5660300002)(86362001)(82740400003)(31696002)(81166007)(336012)(356005)(36860700001)(2616005)(2004002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:14:23.4711 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d28dc10-b410-45ad-7bec-08dbc18d4164 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: DBAEUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7994 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_SHORT,NICE_REPLY_A,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 9/29/23 18:59, Simon Marchi wrote: > On 9/29/23 04:15, Luis Machado via Gdb-patches wrote: >> 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, restricted to 32-bit >> Arm, as that is the only architecture that faces this problem. >> >> Regression-tested on Ubuntu 20.04. OK? >> >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30872 >> --- >> gdb/displaced-stepping.c | 3 +- >> .../gdb.arch/arm-displaced-step-closure.c | 5 +++ >> .../gdb.arch/arm-displaced-step-closure.exp | 41 +++++++++++++++++++ >> 3 files changed, 48 insertions(+), 1 deletion(-) >> create mode 100644 gdb/testsuite/gdb.arch/arm-displaced-step-closure.c >> create mode 100644 gdb/testsuite/gdb.arch/arm-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); > > This code change looks correct to me. We indeed only have a > copy_insn_closure when the buffer is being used by a thread. > >> diff --git a/gdb/testsuite/gdb.arch/arm-displaced-step-closure.c b/gdb/testsuite/gdb.arch/arm-displaced-step-closure.c >> new file mode 100644 >> index 00000000000..085e682be50 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.arch/arm-displaced-step-closure.c >> @@ -0,0 +1,5 @@ >> +int main (int argc, char **argv) >> + >> +{ >> + return 0; >> +} > > Missing license, and apply GNU formatting. > Oops. Fixed locally. >> diff --git a/gdb/testsuite/gdb.arch/arm-displaced-step-closure.exp b/gdb/testsuite/gdb.arch/arm-displaced-step-closure.exp >> new file mode 100644 >> index 00000000000..ddac04ebe76 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.arch/arm-displaced-step-closure.exp >> @@ -0,0 +1,41 @@ >> +# 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. >> + >> +require is_aarch32_target >> + >> +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" > > I don't see anything inherently ARM-specific with the test. Can we have > it as a general test? We could. Though I don't think it would exercise anything useful until some other target decides it needs to call gdbarch_displaced_step_copy_insn_closure_by_addr directly (like Arm does). For instance, we use disassemble in the testcase to cause the crash because Arm needs to figure out the thumb state, and we check the situation of the displaced-stepping closure while at it. I'm fine either way though.