From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id jmf5J3M5BWNoNSwAWB0awg (envelope-from ) for ; Tue, 23 Aug 2022 16:32:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 9AB131E4A7; Tue, 23 Aug 2022 16:32:51 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=INg4jI/g; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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,UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 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 C83181E13B for ; Tue, 23 Aug 2022 16:32:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4EA93858289 for ; Tue, 23 Aug 2022 20:32:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4EA93858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661286767; bh=kqRU60/u57C5jp30ASqSJh0OmtNGP18m6B+/Yl4ZQ4A=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=INg4jI/g11UL4TirmxeUUt4uZEeyKZuVK9zx+VRwlgqLKLoj0wW1zJCaylRPq/esW Y3XRjcBxZmomwApq+g1QJiSbjrKDghUbqsgLqay9/KhHX5s0M/GFHyyEP+34Siyvrx dEcMNwzRrOVTN3kIpXnMxO3mCUzNFcYNnjcMR5EQ= Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2082.outbound.protection.outlook.com [40.107.105.82]) by sourceware.org (Postfix) with ESMTPS id 2AF643858D1E for ; Tue, 23 Aug 2022 20:32:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2AF643858D1E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=AF4SlcnjAzVVWlDld/O7ac5UBOd10NyXdQP3OFRQ971Wpzy92pl0TmZpusFwvVIxPqXyTPUnqPAWmi12CZyp2DuxFv49pnIAfz4FNmXV1nWxrPsIETIRpYHqAghgQy1REyUGS+Ut3z08UUCm0NrLUewOPAUIl3EVS+3EA8fW3krsj2zzgEYFjwSCKc72swYkGPTY0N3gT+tzUXXV6EwO3I11oGGFmGR4rNy4JDNIrRi7TZnQ8PD+XMqnZ2DNoOcLAG6lWAP+xF6tiE0lAkIMxeriAiwfv5MPX9VQzbfgQmSRK5vy94Z9yWE9ZlgF+ZBsfKXddVB+Ivvr93JykvF+KQ== ARC-Message-Signature: i=2; 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=kqRU60/u57C5jp30ASqSJh0OmtNGP18m6B+/Yl4ZQ4A=; b=Ex0UIi/NQLIkPrBQkDqSJzi87O0k0yh4nxmEdhu8KPJ+U5dc4DAnFNLALz/swSwlDoBttL9kurk2fp5lw4/FKv2/d7gWLFucbMVTFxLFMhC0IwBdVX7LJsQWdGpoaLsVQoEqT6lX038Lkp3/hwqLb/S235+ycXMxiqsbJCrssIIyuyGnqP+1cteaEGjdhUlagf/V10HNOh/+QEb0D2k4mWbsOF3cHPmQF38JcTyUd4dh/Di/6KYtuu2hF8NSFnuSR2jrzJcI+4VtbffdpH1F3DRXxGvUnaFS/9OpFNS+zyAO7S38Bwft5nNXynwzaGYOkmJjRSwTQ9fAYwPbH2QTxA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from AM6P194CA0079.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:8f::20) by DBBPR08MB4540.eurprd08.prod.outlook.com (2603:10a6:10:c1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.18; Tue, 23 Aug 2022 20:32:21 +0000 Received: from AM7EUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8f:cafe::a3) by AM6P194CA0079.outlook.office365.com (2603:10a6:209:8f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.20 via Frontend Transport; Tue, 23 Aug 2022 20:32:21 +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 AM7EUR03FT056.mail.protection.outlook.com (100.127.140.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.15 via Frontend Transport; Tue, 23 Aug 2022 20:32:21 +0000 Received: ("Tessian outbound c883b5ba7b70:v123"); Tue, 23 Aug 2022 20:32:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 02334f22cff3f9cc X-CR-MTA-TID: 64aa7808 Received: from ea3c3c321f1d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A189CC1C-F8F2-46EE-94A2-6E90FFAB059D.1; Tue, 23 Aug 2022 20:32:13 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ea3c3c321f1d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 23 Aug 2022 20:32:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ekjP3PxEci8m0NpKKeiB63e5xZDiEfoypnzttUfINRRcqJWf2OPUUw4XXHCWJJ+NVy6/GjDpxP3hJEHsuz60yH5y/glIIMIjEzoLPyCAz8Ax3vGPNEOpdZhzxiiWaBMLyfHon9RaF9YDwPVfV+7af1hytrQ5sk4axJtlvLkDrS0cArAfcBU5Ed6nnJ9MAGL+FOYaw/iFN3g6JkOk/RjBGU16aRlaQDF7e2rFBWGjBcbLaC6tJ+2KHXcs1aT5G6O7dM6awu1KSqai+otlG/yZdyIT2AZepb6RC5QQi07IoFtRnNDzbGol+Sesqzyy8lTIYa3i0XKbjTQSGYkpJOS02w== 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=kqRU60/u57C5jp30ASqSJh0OmtNGP18m6B+/Yl4ZQ4A=; b=NgMQNoy/wQpOws+RnzJ+Q323a+avNgc6/IcsuWpKS8txjZREAcYxIoJC0Iixrtav3RC3Vvv84z9bo1k1S1LjnPt2fb00wLxuF34bW33t74Eyfv28jqBBUQWJYzNnflzRac/s76vPlRT8CmZQKGgf6q/TJHiolfwobHClBA8id3VfLIfK+VHMvalWOMczCpEqpcAm0eGMqOi5xaQycVic/zVTNOIAh4fLAWH6ojWkAYNMrwWAQjvfE3XIQvD6p88qr9jIHb88km5ext2Uczrks5GFuqA+x3WpP+WhN1c6UnqdmJyQn41KWq6kSlJzVck7a1+cLglm+EWfZI6j1uAJzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR0801CA0060.eurprd08.prod.outlook.com (2603:10a6:4:2b::28) by DB7PR08MB2988.eurprd08.prod.outlook.com (2603:10a6:5:18::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Tue, 23 Aug 2022 20:32:11 +0000 Received: from DBAEUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:2b:cafe::3f) by DB6PR0801CA0060.outlook.office365.com (2603:10a6:4:2b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.18 via Frontend Transport; Tue, 23 Aug 2022 20:32:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT020.mail.protection.outlook.com (100.127.143.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5546.15 via Frontend Transport; Tue, 23 Aug 2022 20:32:11 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9; Tue, 23 Aug 2022 20:32:11 +0000 Received: from e129171.arm.com (10.57.15.33) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.9 via Frontend Transport; Tue, 23 Aug 2022 20:32:10 +0000 To: Subject: [PATCH,v2] [Arm] Fix endianness handling for arm record self tests Date: Tue, 23 Aug 2022 21:32:10 +0100 Message-ID: <20220823203210.1561735-1-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220808101203.168954-1-luis.machado@arm.com> References: <20220808101203.168954-1-luis.machado@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 3db52708-9917-437d-ef34-08da8546948d X-MS-TrafficTypeDiagnostic: DB7PR08MB2988:EE_|AM7EUR03FT056:EE_|DBBPR08MB4540:EE_ 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: lTFsxNHscvtooyk0+PsEexQY3pTq0WFRmoMQZWyVTKS4x2IMi2CjbaQb6l72Huw5+eODbIWyfryIfwQWevn+xJa6a7TSBXzWC8x/zq/2AGAqvGuelIzXcb6osAnjVn15zoI8r60UKKYAs03xUehZzA4Q8kYObjluGPirS2sm3i8+4abteTwoXN1eeREH5g9EqcL3rLvmYIo+uvUaG0QPizDI3BWDoOw8I4/PmMuRLnuFJI9Isixu8AzZgXrjhEQa12vGbW2tHYPjRNTpDlg9ilaEOVXYVJ9TTkNc/k1rTeyIl3zf06NqTUEZRvW3xQE3AFByVimOo6ewRqZrHcfGr5yhZN7cLElZAEqh00ltjBkxmbsLlvmLEmk/OAovq0g1GdI0XXrzcnSPy5DCJy4nb7FQ70DtyEmTksiSkJTIRnCNy+2doGDIEJoMPgQkuWsgjir+N0VNYII9+boAWkoHTllu+vbK4h/fiZEii0HrzwzLz6cvJ05gvCQV2O+QECfO9hoAwQAAQTugBrQjZt12OcPSTiWX6SGxsqkFkCgzaL41JrGteAElZmyKW3H40CHJi1bO1eKBi+tnz+ODkK5odMLKnSY2oGiVcaN+PrQHYlzF7XCJUYk3w0CCfrE9JM5OxSaQFVQTaqBNNXf/hv85cbkAe47TSbOooCO9RtXrZk3glKsfnmK7pWqlVLNMZq246j5sXTLFnjBjb+BiC4V+MR5x1LvV7UdBig4n5fZbHobjCNSHpGZS5e5OBF97eNrNVZig2WW0EkkmQ5Ke1u7ntKV4CgCApL0MgPs8Bpsu/AJyayh/foROkGjmwUB7tvkCDwLAlmPWMlXCPp64GIRRqw== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(396003)(346002)(39860400002)(136003)(376002)(40470700004)(36840700001)(46966006)(2616005)(8676002)(70206006)(86362001)(4326008)(356005)(70586007)(6916009)(54906003)(36860700001)(36756003)(81166007)(82740400003)(186003)(336012)(26005)(426003)(47076005)(7696005)(1076003)(478600001)(966005)(316002)(41300700001)(40480700001)(8936002)(2906002)(82310400005)(5660300002)(83380400001)(44832011)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB2988 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b8753ba4-a6dd-46e6-3208-08da85468eb4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7RkKC5rgLQCseXJPt9dxL0zA1hV3H7N1YqtBzpgB+Ng/3gb5DqUgFNYqHTz0lbcispDLQcDGRzZmBMGWYjI4kH0NoYHsKxGw5MOeEE7c81QeTnGDH7ss2bSanWvqbbWQ2wR6zi1CIUmiNDTmQBtVb1n4PUZGxMzyp0dprBSTknRMvfy8gzhRDKwVFuHcSbjIOszhyguad0m/rfUVIjHxBKWxmb6RXDNtlSWCuMN0JDNTHslinpn38qbPyBANfu6x4C8WDSBkX578D3uA1mpxr2woeXepHBqXik3qccDP4bVCjjhNqScJiQesk5JV+J5EIzMUCgoaP1aBOcmqUlXF4meaK6VcLA4vRXPHLHOvbk7qvj/h5GbTzAqytekby8Wyaotgv61aojp3BCPx7vXIji/AHSJromZAhWTc2PKS2Sf75YbyKqHghJDry0PCVrNOQNaRbZov1rNNs5GhU2jdwjphrfIuD6MUSAtBrGW4+F4czQBzc2rrhC25mx9YNg3Cti/oiHHqC+pz2t26Z9M3kSw3Jz3P9uA3aSpMU0oVfVpkxJeShdKFEDVA4w3w0bJNPbCrGTG8bNpdMcOkDf/DvQx5NqguucpePYPgupHHn1l4DYCEdEHrid+gD4r8qScCCN1+VmusZEpoBkgYC8aGRuf4dikULTatzLBftQit4rIUcds0Mog7FcQktNggyGG0RHmf/jw1eAQ0wLfbHcLYr2xdELtEqZaiZsp1bw98pG3HSinKvVGRoOfkcNxAhLt2ACoMUySgjfE8dCDpKPSEcszwPi+6Bk4XXLkI2xuSbHc= 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:(13230016)(4636009)(39860400002)(376002)(396003)(346002)(136003)(46966006)(40470700004)(36840700001)(26005)(86362001)(47076005)(426003)(2616005)(1076003)(82740400003)(336012)(81166007)(4326008)(83380400001)(36860700001)(8676002)(70206006)(186003)(70586007)(40460700003)(82310400005)(6916009)(54906003)(5660300002)(2906002)(8936002)(36756003)(44832011)(107886003)(316002)(7696005)(41300700001)(40480700001)(966005)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2022 20:32:21.2100 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3db52708-9917-437d-ef34-08da8546948d 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: AM7EUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4540 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: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: mark@klomp.org, tdevries@suse.de Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" v2: - Add 32-bit Arm instruction selftest - Refactored abstract memory reader into abstract instruction reader - Adjusted code to use templated type and to use host endianness as opposed to target endianness. The arm record tests handle 16-bit and 32-bit thumb instructions, but the code is laid out in a way that handles the 32-bit thumb instructions as two 16-bit parts. This is fine, but it is prone to host-endianness issues given how the two 16-bit parts are stored and how they are accessed later on. Arm is little-endian by default, so running this test with a GDB built with --enable-targets=all and on a big endian host will run into the following: Running selftest arm-record. Process record and replay target doesn't support syscall number -2036195 Process record does not support instruction 0x7f70ee1d at address 0x0. Self test failed: self-test failed at ../../binutils-gdb/gdb/arm-tdep.c:14482 It turns out the abstract memory reader class is more generic than it needs to be, and we can simplify the code a bit by assuming we have a simple instruction reader that only reads up to 4 bytes, which is the length of a 32-bit instruction. Instead of returning a bool, we return instead the instruction that has been read. This way we avoid having to deal with the endianness conversion, and use the host endianness instead. The Arm selftests can be executed on non-Arm hosts. While at it, Tom suggested adding a 32-bit Arm instruction selftest to increase the coverage of the selftests. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29432 Co-authored-by: Tom de Vries --- gdb/arm-tdep.c | 150 ++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 82 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 0091d14708f..ead9bbf46c5 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -14252,59 +14252,39 @@ thumb2_record_decode_insn_handler (arm_insn_decode_record *thumb2_insn_r) } namespace { -/* Abstract memory reader. */ +/* Abstract instruction reader. */ -class abstract_memory_reader +class abstract_instruction_reader { public: - /* Read LEN bytes of target memory at address MEMADDR, placing the - results in GDB's memory at BUF. Return true on success. */ + /* Read one instruction of size LEN from address MEMADDR and using + BYTE_ORDER endianness. */ - virtual bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) = 0; + virtual ULONGEST read (CORE_ADDR memaddr, const size_t len, + enum bfd_endian byte_order) = 0; }; /* Instruction reader from real target. */ -class instruction_reader : public abstract_memory_reader +class instruction_reader : public abstract_instruction_reader { public: - bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) override + ULONGEST read (CORE_ADDR memaddr, const size_t len, + enum bfd_endian byte_order) override { - if (target_read_memory (memaddr, buf, len)) - return false; - else - return true; + return read_code_unsigned_integer (memaddr, len, byte_order); } }; } // namespace -/* Extracts arm/thumb/thumb2 insn depending on the size, and returns 0 on success -and positive val on failure. */ - -static int -extract_arm_insn (abstract_memory_reader& reader, - arm_insn_decode_record *insn_record, uint32_t insn_size) -{ - gdb_byte buf[insn_size]; - - memset (&buf[0], 0, insn_size); - - if (!reader.read (insn_record->this_addr, buf, insn_size)) - return 1; - insn_record->arm_insn = (uint32_t) extract_unsigned_integer (&buf[0], - insn_size, - gdbarch_byte_order_for_code (insn_record->gdbarch)); - return 0; -} - typedef int (*sti_arm_hdl_fp_t) (arm_insn_decode_record*); /* Decode arm/thumb insn depending on condition cods and opcodes; and dispatch it. */ static int -decode_insn (abstract_memory_reader &reader, +decode_insn (abstract_instruction_reader &reader, arm_insn_decode_record *arm_record, record_type_t record_type, uint32_t insn_size) { @@ -14339,20 +14319,12 @@ decode_insn (abstract_memory_reader &reader, uint32_t ret = 0; /* return value: negative:failure 0:success. */ uint32_t insn_id = 0; + enum bfd_endian code_endian + = gdbarch_byte_order_for_code (arm_record->gdbarch); + arm_record->arm_insn + = reader.read (arm_record->this_addr, insn_size, code_endian); - if (extract_arm_insn (reader, arm_record, insn_size)) - { - if (record_debug) - { - gdb_printf (gdb_stdlog, - _("Process record: error reading memory at " - "addr %s len = %d.\n"), - paddress (arm_record->gdbarch, - arm_record->this_addr), insn_size); - } - return -1; - } - else if (ARM_RECORD == record_type) + if (ARM_RECORD == record_type) { arm_record->cond = bits (arm_record->arm_insn, 28, 31); insn_id = bits (arm_record->arm_insn, 25, 27); @@ -14412,36 +14384,35 @@ decode_insn (abstract_memory_reader &reader, #if GDB_SELF_TEST namespace selftests { -/* Provide both 16-bit and 32-bit thumb instructions. */ +/* Instruction reader class for selftests. + + For 16-bit Thumb instructions, an array of uint16_t should be used. -class instruction_reader_thumb : public abstract_memory_reader + For 32-bit Thumb instructions and regular 32-bit Arm instructions, an array + of uint32_t should be used. */ + +template +class instruction_reader_selftest : public abstract_instruction_reader { public: template - instruction_reader_thumb (enum bfd_endian endian, - const uint16_t (&insns)[SIZE]) - : m_endian (endian), m_insns (insns), m_insns_size (SIZE) + instruction_reader_selftest (const T (&insns)[SIZE]) + : m_insns (insns), m_insns_size (SIZE) {} - bool read (CORE_ADDR memaddr, gdb_byte *buf, const size_t len) override + ULONGEST read (CORE_ADDR memaddr, const size_t length, + enum bfd_endian byte_order) override { - SELF_CHECK (len == 4 || len == 2); - SELF_CHECK (memaddr % 2 == 0); - SELF_CHECK ((memaddr / 2) < m_insns_size); + SELF_CHECK (length == sizeof (T)); + SELF_CHECK (memaddr % sizeof (T) == 0); + SELF_CHECK ((memaddr / sizeof (T)) < m_insns_size); - store_unsigned_integer (buf, 2, m_endian, m_insns[memaddr / 2]); - if (len == 4) - { - store_unsigned_integer (&buf[2], 2, m_endian, - m_insns[memaddr / 2 + 1]); - } - return true; + return m_insns[memaddr / sizeof (T)]; } private: - enum bfd_endian m_endian; - const uint16_t *m_insns; - size_t m_insns_size; + const T *m_insns; + const size_t m_insns_size; }; static void @@ -14461,6 +14432,8 @@ arm_record_test (void) memset (&arm_record, 0, sizeof (arm_insn_decode_record)); arm_record.gdbarch = gdbarch; + /* Use the endian-free representation of the instructions here. The test + will handle endianness conversions. */ static const uint16_t insns[] = { /* db b2 uxtb r3, r3 */ 0xb2db, @@ -14468,8 +14441,7 @@ arm_record_test (void) 0x58cd, }; - enum bfd_endian endian = gdbarch_byte_order_for_code (arm_record.gdbarch); - instruction_reader_thumb reader (endian, insns); + instruction_reader_selftest reader (insns); int ret = decode_insn (reader, &arm_record, THUMB_RECORD, THUMB_INSN_SIZE_BYTES); @@ -14495,13 +14467,14 @@ arm_record_test (void) memset (&arm_record, 0, sizeof (arm_insn_decode_record)); arm_record.gdbarch = gdbarch; - static const uint16_t insns[] = { - /* 1d ee 70 7f mrc 15, 0, r7, cr13, cr0, {3} */ - 0xee1d, 0x7f70, + /* Use the endian-free representation of the instruction here. The test + will handle endianness conversions. */ + static const uint32_t insns[] = { + /* mrc 15, 0, r7, cr13, cr0, {3} */ + 0x7f70ee1d, }; - enum bfd_endian endian = gdbarch_byte_order_for_code (arm_record.gdbarch); - instruction_reader_thumb reader (endian, insns); + instruction_reader_selftest reader (insns); int ret = decode_insn (reader, &arm_record, THUMB2_RECORD, THUMB2_INSN_SIZE_BYTES); @@ -14510,6 +14483,27 @@ arm_record_test (void) SELF_CHECK (arm_record.reg_rec_count == 1); SELF_CHECK (arm_record.arm_regs[0] == 7); } + + /* 32-bit instructions. */ + { + arm_insn_decode_record arm_record; + + memset (&arm_record, 0, sizeof (arm_insn_decode_record)); + arm_record.gdbarch = gdbarch; + + /* Use the endian-free representation of the instruction here. The test + will handle endianness conversions. */ + static const uint32_t insns[] = { + /* mov r5, r0 */ + 0xe1a05000, + }; + + instruction_reader_selftest reader (insns); + int ret = decode_insn (reader, &arm_record, ARM_RECORD, + ARM_INSN_SIZE_BYTES); + + SELF_CHECK (ret == 0); + } } /* Instruction reader from manually cooked instruction sequences. */ @@ -14609,18 +14603,10 @@ arm_process_record (struct gdbarch *gdbarch, struct regcache *regcache, } instruction_reader reader; - if (extract_arm_insn (reader, &arm_record, 2)) - { - if (record_debug) - { - gdb_printf (gdb_stdlog, - _("Process record: error reading memory at " - "addr %s len = %d.\n"), - paddress (arm_record.gdbarch, - arm_record.this_addr), 2); - } - return -1; - } + enum bfd_endian code_endian + = gdbarch_byte_order_for_code (arm_record.gdbarch); + arm_record.arm_insn + = reader.read (arm_record.this_addr, 2, code_endian); /* Check the insn, whether it is thumb or arm one. */ -- 2.25.1