From patchwork Fri Jun 30 13:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 71909 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C32E3870C34 for ; Fri, 30 Jun 2023 13:49:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C32E3870C34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688132942; bh=1BVMpzu9u92Ka7GRyrQIXznALMHz0LmukjpxeZ7n2OA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HClzb+t8Qfd4ZF4HlBtYdX3QFcvRTkVSXxyHiQ9rpwVlEV664jo9lickeBr2xCj7G jUqbqG3p4vXwtA/W7eb2dF6GTugU6v5JbxKN3y4sblekNIVeU9XNSwMwzWm7EClbus EEW5XJt1oYB6+OdOSiaxIjRz9yntJz1sZs4rrOMc= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2079.outbound.protection.outlook.com [40.107.22.79]) by sourceware.org (Postfix) with ESMTPS id 9F4A03870C3C for ; Fri, 30 Jun 2023 13:46:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F4A03870C3C Received: from AM0PR02CA0124.eurprd02.prod.outlook.com (2603:10a6:20b:28c::21) by AS2PR08MB9500.eurprd08.prod.outlook.com (2603:10a6:20b:60c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Fri, 30 Jun 2023 13:46:45 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:28c:cafe::c8) by AM0PR02CA0124.outlook.office365.com (2603:10a6:20b:28c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:46:44 +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 AM7EUR03FT009.mail.protection.outlook.com (100.127.140.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.13 via Frontend Transport; Fri, 30 Jun 2023 13:46:44 +0000 Received: ("Tessian outbound d6c4ee3ba1eb:v142"); Fri, 30 Jun 2023 13:46:44 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 66937580626a4d72 X-CR-MTA-TID: 64aa7808 Received: from 1b8d920ed38e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 19B60820-ECF9-4A53-8E71-FCE6FC2113CE.1; Fri, 30 Jun 2023 13:46:37 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1b8d920ed38e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 30 Jun 2023 13:46:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DRnU3/oo0RxMly42dxPm4DnoDTVJLe81jxrATA1LO/GfM2jGoiU4bf/ph6vo0IeCcoIMIOQNnc5jO0jcZ3EK53JJOIlPg03cBnd11Rm//0PUHRpuky5w5Ya6l3fyyi42LjfZzL5u+RODAkfOyNV35xESOxUJKzix6BkFny5z9TvsyCotdkWiZ9+s66kVp+PwJsAaTeI4qb6O1VNLFE6fxY27o1YCYVYJxdVT96T9m4a6o4QncpljnF7vmVPs98BK0DlFKCwZWQGDjKezm4VDUIm4p9+toVgSUQS2jkC8dJ9JOj2QehkKqHlxSzg5FuQBHCzxN+Hos7F9Ca+iShXqKw== 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=1BVMpzu9u92Ka7GRyrQIXznALMHz0LmukjpxeZ7n2OA=; b=Pk8PSBfqhDenfVTzQ0IdWSWUbiiehHzKyG7VMLi7+H4xIz7ReoVleLeFQcw2Fx7WCk53V/4ZanFccY3KXqo3RQ27ZpaJlEUouoxMoqVazh3e9/vbeptjlmsbrL/v8DIsO8v0CJmDFwfeccjI7Y+C8HujPGGz0cyZiMklBSZ+YlLRxpqcqS8PklXcJTxsTQU3KqDJPl7rK82USBLchkc7lsntIer7qmFkp59TgK9TQewpGsfsw8vwxi97XvJWDSf+A+iGUBevHUMb9dGqoUXGNd6GwZgP4HMeq7GglB8pbbiD37a8dOmwWXX4l0sjp8M8CqmrSaGiUrh7q0Wo/epNIQ== 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 AS9PR04CA0132.eurprd04.prod.outlook.com (2603:10a6:20b:531::27) by DB9PR08MB9537.eurprd08.prod.outlook.com (2603:10a6:10:459::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.19; Fri, 30 Jun 2023 13:46:35 +0000 Received: from AM7EUR03FT014.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:531:cafe::ba) by AS9PR04CA0132.outlook.office365.com (2603:10a6:20b:531::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:46:35 +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 AM7EUR03FT014.mail.protection.outlook.com (100.127.140.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6544.22 via Frontend Transport; Fri, 30 Jun 2023 13:46:35 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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.27; Fri, 30 Jun 2023 13:46:34 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 30 Jun 2023 13:46:33 +0000 Received: from e129171.arm.com (10.57.27.17) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 30 Jun 2023 13:46:33 +0000 To: Subject: [PATCH v3 10/16] [gdb/aarch64] sme: Fixup sigframe gdbarch when vg/svg changes Date: Fri, 30 Jun 2023 14:46:10 +0100 Message-ID: <20230630134616.1238105-11-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230630134616.1238105-1-luis.machado@arm.com> References: <20230630134616.1238105-1-luis.machado@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT014:EE_|DB9PR08MB9537:EE_|AM7EUR03FT009:EE_|AS2PR08MB9500:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e5f3018-97c8-44b5-b00f-08db79707159 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: bqDwGEKRTTMUAHzKr3xMYPMXcr/ZppRNuTn1kudiYf2xzoODCQpARlXEz4m20Nf/nMXlEnN6kScn9xHrSqYPFJFocNeujOH4+SKaPhhzvD3aqCdSLqbsqh7NnJOVliZ2jOilSdwnvnuQrYEFBbhCE4QmRbH3qBMgKmxmVM6EbNJnNCUfEd6vHew0YOr+UUMc2d/VOWS5CHKLwSIB+2mW+oaT0/3lk7A+6mobZUuwDjEsX7r8yX1fzsv9/rWQAL0WbCGNBdkBdQ23gQldejDe3PLgVbpVaw6+Fh9P/TzVUlXPdH5TrCMols25unkfxmfqIZp4rp1dlqVY1nADIjxTrNcnpVC6KxVekl2g2XIJWmVaoxc+PqhVWULtWeKnuPLX75y8qjbBzH/Gy2KplDgBpFIFTcrSvP9yTUzWNDWus0lvv8D0ol2RdSA1I5oZMtOOca6DxNwVSXQe55uhMe+dR1l1fyqPFvk2pqRhKBPANLuVU2jg9SzmSbIkkHP0I/lKuF3PLlMYVBUsg63GwUo7eF/y8IUYvG5xs/GgWkEoOU8Hd3pyXdMZH72xXxXcFVEcb42I2IWt6J5yH6JhkMfykx8J/ZlrgGmHaSRFUjt0OaJnWtWC75AyXTPnmpqy3RDWlF2JcEDlVG4R+3pLvsIF92Lxh3BpOxLjTvHHLuELlpJ3p3dUUjqZ6H2KbIF6GQkgEVHTZtRxgehq+sjCK8CJxVhA6YTDD/fBCT6nC1XdBO1fZA/Z1UWEhCnjjfDlylpP7E5jXR3snsCsLhgZbWEp6g== 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:(13230028)(4636009)(136003)(346002)(39860400002)(396003)(376002)(451199021)(36840700001)(46966006)(40470700004)(82310400005)(82740400003)(81166007)(6666004)(356005)(7696005)(426003)(336012)(83380400001)(47076005)(2616005)(186003)(26005)(1076003)(40480700001)(36860700001)(5660300002)(86362001)(40460700003)(8676002)(44832011)(36756003)(30864003)(2906002)(70206006)(70586007)(8936002)(316002)(6916009)(41300700001)(478600001)(66899021)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9537 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f5f48a4f-04c4-4e0e-6675-08db79706ba1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: taJCpvgPOn/yCIY59lv3zEht5fVrVWyoY2nBuNAtp3YZ4usP7+SLdH/R0Um6Cgqys/WodzGrSwAxVn9Oy/xES2lFIlRR+oQ9U22znDFVLT+/HdCT2XDZpHGnHXp9oHP9nzDWDPqn+SeUnOwYxAnlEu81lMynFIxAv55XcgDAkWWMZ/Le3AT4rkpiGlNdpz+83ipf4A34dtdAKQVMMs/OKzuVWCqtYLlHa738Qu3IxscysiZT95oDBOIKp3K0Nv+qBP3f/YtlxQuS9o/jhMNSwYQ7BZqOTnlrHNVMznf+rutKPR60+yaJUzAp/YFGfhdGIAt6sVBXszrDkCXXpD8U2pq3bmD6ediM/eBFsD0Sx8sqd9RrLn1fZd9eWbuuMyxkgx4bRlseLlBFhNpdlHsC0ZbHMUmHSo0b7p1rO5r8H0sc9NjqaDKV0e/SEZ5oJU9VwEhzyVTSZG4czZiE17R/0Baj7L15cEpngtI2NimfPWoh9Ki/1YkuOJOqIWOYJAppJgNiPUpK6QKBhX6b7OdP47ZfCDRb7YYR+WVtJZEUE00BuNtTGVbB1XyPg94pjcD85lyH9e/4XqiNQE7YsWa4X+eVV+nNRCiulpU06bYMSGVa+F0TU/jesqMYQKvYGUHwk+TIMEm5dyaNf0QSBrR3oN6jxNm5SkpSk5HJnj0hTEXV/ravsRMeagYeP5w/zGjoQ8F8+6zlca+yKk1Q//Y2omdmkkiNQmtvXoi5S6c968jPHYTvwW3nyCOcRfpfb/vK 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:(13230028)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199021)(36840700001)(40470700004)(46966006)(66899021)(82310400005)(36860700001)(36756003)(30864003)(5660300002)(86362001)(44832011)(41300700001)(70206006)(6916009)(8936002)(8676002)(316002)(40480700001)(82740400003)(40460700003)(81166007)(70586007)(1076003)(478600001)(47076005)(186003)(2906002)(426003)(2616005)(336012)(7696005)(83380400001)(26005)(6666004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2023 13:46:44.7277 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e5f3018-97c8-44b5-b00f-08db79707159 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: AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9500 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, 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 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-Patchwork-Original-From: Luis Machado via Gdb-patches From: Luis Machado Reply-To: Luis Machado Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" With SME, where you have two different vector lengths (vl and svl), it may be the case that the current frame has a set of vector lengths (A) but the signal context has a distinct set of vector lengths (B). In this case, we may run into a situation where GDB attempts to use a gdbarch created for set A, but it is really dealing with a frame that was using set B. This is problematic, specially with SME, because now we have a different number of pseudo-registers and types that gets cached on creation of each gdbarch variation. For AArch64 we really need to be able to use the correct gdbarch for each frame, and I noticed the signal frame (tramp-frame) doesn't have a settable prev_arch field. So it ends up using the default frame_unwind_arch function and eventually calling get_frame_arch (next_frame). That means the previous frame will always have the same gdbarch as the current frame. This patch first refactors the AArch64/Linux signal context code, simplifying it and making it reusable for our purposes of calculating the previous frame's gdbarch. I introduced a struct that holds information that we have found in the signal context, and with which we can make various decisions. Finally, a small change to tramp-frame.c and tramp-frame.h to expose a prev_arch hook that the architecture can set. With this new field, AArch64/Linux can implement a hook that looks at the signal context and infers the gdbarch for the previous frame. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. --- gdb/aarch64-linux-tdep.c | 279 +++++++++++++++++++++++++++------------ gdb/tramp-frame.c | 1 + gdb/tramp-frame.h | 12 ++ 3 files changed, 206 insertions(+), 86 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 1e12a8f0279..c973a790f62 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -184,6 +184,39 @@ #define AARCH64_SME_CONTEXT_SIZE(svq) \ (AARCH64_SME_CONTEXT_REGS_OFFSET + AARCH64_SME_CONTEXT_ZA_SIZE (svq)) +/* Holds information about the signal frame. */ +struct aarch64_linux_sigframe +{ + /* The stack pointer value. */ + CORE_ADDR sp = 0; + /* The sigcontext address. */ + CORE_ADDR sigcontext_address = 0; + /* The start/end signal frame section addresses. */ + CORE_ADDR section = 0; + CORE_ADDR section_end = 0; + + /* Starting address of the section containing the general purpose + registers. */ + CORE_ADDR gpr_section = 0; + /* Starting address of the section containing the FPSIMD registers. */ + CORE_ADDR fpsimd_section = 0; + /* Starting address of the section containing the SVE registers. */ + CORE_ADDR sve_section = 0; + /* Starting address of the section containing the ZA register. */ + CORE_ADDR za_section = 0; + /* Starting address of the section containing extra information. */ + CORE_ADDR extra_section = 0; + + /* The vector length (SVE or SSVE). */ + ULONGEST vl = 0; + /* The streaming vector length (SSVE/ZA). */ + ULONGEST svl = 0; + /* True if we are in streaming mode, false otherwise. */ + bool streaming_mode = false; + /* True if we have a ZA payload, false otherwise. */ + bool za_payload = false; +}; + /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the size, or return 0 on error. */ @@ -319,129 +352,115 @@ aarch64_linux_restore_vregs (struct gdbarch *gdbarch, } } -/* Implement the "init" method of struct tramp_frame. */ +/* Given a signal frame THIS_FRAME, read the signal frame information into + SIGNAL_FRAME. */ static void -aarch64_linux_sigframe_init (const struct tramp_frame *self, - frame_info_ptr this_frame, - struct trad_frame_cache *this_cache, - CORE_ADDR func) +aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame, + struct aarch64_linux_sigframe &signal_frame) { - struct gdbarch *gdbarch = get_frame_arch (this_frame); - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); - CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET - + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET ); - CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET; - CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE; - CORE_ADDR fpsimd = 0; - CORE_ADDR sve_regs = 0; - CORE_ADDR za_state = 0; - uint64_t svcr = 0; + signal_frame.sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); + signal_frame.sigcontext_address + = signal_frame.sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET + + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET; + signal_frame.section + = signal_frame.sigcontext_address + AARCH64_SIGCONTEXT_RESERVED_OFFSET; + signal_frame.section_end + = signal_frame.section + AARCH64_SIGCONTEXT_RESERVED_SIZE; + + signal_frame.gpr_section + = signal_frame.sigcontext_address + AARCH64_SIGCONTEXT_XO_OFFSET; + + /* Search for all the other sections, stopping at null. */ + CORE_ADDR section = signal_frame.section; + CORE_ADDR section_end = signal_frame.section_end; uint32_t size, magic; - size_t vq = 0, svq = 0; bool extra_found = false; - int num_regs = gdbarch_num_regs (gdbarch); - - /* Read in the integer registers. */ + enum bfd_endian byte_order + = gdbarch_byte_order (get_frame_arch (this_frame)); - for (int i = 0; i < 31; i++) - { - trad_frame_set_reg_addr (this_cache, - AARCH64_X0_REGNUM + i, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + i * AARCH64_SIGCONTEXT_REG_SIZE); - } - trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + 31 * AARCH64_SIGCONTEXT_REG_SIZE); - trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + 32 * AARCH64_SIGCONTEXT_REG_SIZE); - - /* Search for the FP and SVE sections, stopping at null. */ while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0 && size != 0) { switch (magic) { case AARCH64_FPSIMD_MAGIC: - fpsimd = section; - section += size; - break; + { + signal_frame.fpsimd_section = section; + section += size; + break; + } case AARCH64_SVE_MAGIC: { /* Check if the section is followed by a full SVE dump, and set sve_regs if it is. */ gdb_byte buf[4]; - uint16_t flags; - - if (!tdep->has_sve ()) - break; + /* Extract the vector length. */ if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET, buf, 2) != 0) { + warning (_("Failed to read the vector length from the SVE " + " signal frame context.")); section += size; break; } - vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order)); - /* If SME is supported, also read the flags field. It may - indicate if this SVE context is for streaming mode (SSVE). */ - if (tdep->has_sme ()) + signal_frame.vl = extract_unsigned_integer (buf, 2, byte_order); + + /* Extract the flags to check if we are in streaming mode. */ + if (target_read_memory (section + + AARCH64_SVE_CONTEXT_FLAGS_OFFSET, + buf, 2) != 0) { - if (target_read_memory (section - + AARCH64_SVE_CONTEXT_FLAGS_OFFSET, - buf, 2) != 0) - { - section += size; - break; - } - flags = extract_unsigned_integer (buf, 2, byte_order); - - /* Is this SSVE data? If so, enable the SM bit in SVCR. */ - if (flags & SVE_SIG_FLAG_SM) - svcr |= SVCR_SM_BIT; + warning (_("Failed to read the flags from the SVE signal frame" + " context.")); + section += size; + break; } - if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) - sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; + uint16_t flags = extract_unsigned_integer (buf, 2, byte_order); + /* Is this SSVE data? If so, we are in streaming mode. */ + signal_frame.streaming_mode + = (flags & SVE_SIG_FLAG_SM) ? true : false; + + ULONGEST vq = sve_vq_from_vl (signal_frame.vl); + if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) + { + signal_frame.sve_section + = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; + } section += size; break; } case AARCH64_ZA_MAGIC: { - if (!tdep->has_sme ()) - { - section += size; - break; - } - /* Check if the section is followed by a full ZA dump, and set za_state if it is. */ gdb_byte buf[2]; + /* Extract the streaming vector length. */ if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET, buf, 2) != 0) { + warning (_("Failed to read the streaming vector length from " + " ZA signal frame context.")); section += size; break; } - svq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, - byte_order)); + + signal_frame.svl = extract_unsigned_integer (buf, 2, byte_order); + ULONGEST svq = sve_vq_from_vl (signal_frame.svl); if (size >= AARCH64_SME_CONTEXT_SIZE (svq)) { - za_state = section + AARCH64_SME_CONTEXT_REGS_OFFSET; - /* We have ZA data. Enable the ZA bit in SVCR. */ - svcr |= SVCR_ZA_BIT; + signal_frame.za_section + = section + AARCH64_SME_CONTEXT_REGS_OFFSET; + signal_frame.za_payload = true; } - section += size; break; } @@ -457,11 +476,14 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET, buf, 8) != 0) { + warning (_("Failed to read the extra section address from the" + " signal frame context.")); section += size; break; } section = extract_unsigned_integer (buf, 8, byte_order); + signal_frame.extra_section = section; extra_found = true; break; } @@ -477,11 +499,49 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, if (!extra_found && section > section_end) break; } +} + +/* Implement the "init" method of struct tramp_frame. */ + +static void +aarch64_linux_sigframe_init (const struct tramp_frame *self, + frame_info_ptr this_frame, + struct trad_frame_cache *this_cache, + CORE_ADDR func) +{ + /* Read the signal context information. */ + struct aarch64_linux_sigframe signal_frame; + aarch64_linux_read_signal_frame_info (this_frame, signal_frame); + + /* Now we have all the data required to restore the registers from the + signal frame. */ + + /* Restore the general purpose registers. */ + CORE_ADDR offset + = signal_frame.sigcontext_address + AARCH64_SIGCONTEXT_XO_OFFSET; + for (int i = 0; i < 31; i++) + { + trad_frame_set_reg_addr (this_cache, AARCH64_X0_REGNUM + i, offset); + offset += AARCH64_SIGCONTEXT_REG_SIZE; + } + trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, offset); + offset += AARCH64_SIGCONTEXT_REG_SIZE; + trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, offset); - if (sve_regs != 0) + struct gdbarch *gdbarch = get_frame_arch (this_frame); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + /* Restore the SVE / FPSIMD registers. */ + if (tdep->has_sve () && signal_frame.sve_section != 0) { - CORE_ADDR offset; + ULONGEST vq = sve_vq_from_vl (signal_frame.vl); + CORE_ADDR sve_regs = signal_frame.sve_section; + + /* Restore VG. */ + trad_frame_set_reg_value (this_cache, AARCH64_SVE_VG_REGNUM, + sve_vg_from_vl (signal_frame.vl)); + int num_regs = gdbarch_num_regs (gdbarch); for (int i = 0; i < 32; i++) { offset = sve_regs + (i * vq * 16); @@ -511,30 +571,75 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset); } - if (fpsimd != 0) + /* Restore the FPSIMD registers. */ + if (signal_frame.fpsimd_section != 0) { + CORE_ADDR fpsimd = signal_frame.fpsimd_section; + trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM, fpsimd + AARCH64_FPSIMD_FPSR_OFFSET); trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM, fpsimd + AARCH64_FPSIMD_FPCR_OFFSET); /* If there was no SVE section then set up the V registers. */ - if (sve_regs == 0) + if (!tdep->has_sve () || signal_frame.sve_section == 0) aarch64_linux_restore_vregs (gdbarch, this_cache, fpsimd); } - if (za_state != 0) + /* Restore the SME registers. */ + if (tdep->has_sme ()) { - /* Restore the ZA state. */ - trad_frame_set_reg_addr (this_cache, tdep->sme_za_regnum, - za_state); + if (signal_frame.za_section != 0) + { + /* Restore the ZA state. */ + trad_frame_set_reg_addr (this_cache, tdep->sme_za_regnum, + signal_frame.za_section); + } + + /* Restore/Reconstruct SVCR. */ + ULONGEST svcr = 0; + svcr |= signal_frame.za_payload ? SVCR_ZA_BIT : 0; + svcr |= signal_frame.streaming_mode ? SVCR_SM_BIT : 0; + trad_frame_set_reg_value (this_cache, tdep->sme_svcr_regnum, svcr); + + /* Restore SVG. */ + trad_frame_set_reg_value (this_cache, tdep->sme_svg_regnum, + sve_vg_from_vl (signal_frame.svl)); } - /* If SME is supported, set SVCR as well. */ - if (tdep->has_sme ()) - trad_frame_set_reg_value (this_cache, tdep->sme_svcr_regnum, svcr); + trad_frame_set_id (this_cache, frame_id_build (signal_frame.sp, func)); +} - trad_frame_set_id (this_cache, frame_id_build (sp, func)); +/* Implements the "prev_arch" method of struct tramp_frame. */ + +static struct gdbarch * +aarch64_linux_sigframe_prev_arch (frame_info_ptr this_frame, + void **frame_cache) +{ + struct trad_frame_cache *cache + = (struct trad_frame_cache *) *frame_cache; + + gdb_assert (cache != nullptr); + + struct aarch64_linux_sigframe signal_frame; + aarch64_linux_read_signal_frame_info (this_frame, signal_frame); + + /* The SVE vector length and the SME vector length may change from frame to + frame. Make sure we report the correct architecture to the previous + frame. + + We can reuse the next frame's architecture here, as it should be mostly + the same, except for potential different vg and svg values. */ + const struct target_desc *tdesc + = gdbarch_target_desc (get_frame_arch (this_frame)); + aarch64_features features = aarch64_features_from_target_desc (tdesc); + features.vq = sve_vq_from_vl (signal_frame.vl); + features.svq = (uint8_t) sve_vq_from_vl (signal_frame.svl); + + struct gdbarch_info info; + info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64); + info.target_desc = aarch64_read_description (features); + return gdbarch_find_by_info (info); } static const struct tramp_frame aarch64_linux_rt_sigframe = @@ -551,7 +656,9 @@ static const struct tramp_frame aarch64_linux_rt_sigframe = {0xd4000001, ULONGEST_MAX}, {TRAMP_SENTINEL_INSN, ULONGEST_MAX} }, - aarch64_linux_sigframe_init + aarch64_linux_sigframe_init, + nullptr, /* validate */ + aarch64_linux_sigframe_prev_arch, /* prev_arch */ }; /* Register maps. */ diff --git a/gdb/tramp-frame.c b/gdb/tramp-frame.c index c69ee6efc2c..94e42e9fec1 100644 --- a/gdb/tramp-frame.c +++ b/gdb/tramp-frame.c @@ -170,5 +170,6 @@ tramp_frame_prepend_unwinder (struct gdbarch *gdbarch, unwinder->stop_reason = default_frame_unwind_stop_reason; unwinder->this_id = tramp_frame_this_id; unwinder->prev_register = tramp_frame_prev_register; + unwinder->prev_arch = tramp_frame->prev_arch; frame_unwind_prepend_unwinder (gdbarch, unwinder); } diff --git a/gdb/tramp-frame.h b/gdb/tramp-frame.h index fa0241acb2d..563c34ae595 100644 --- a/gdb/tramp-frame.h +++ b/gdb/tramp-frame.h @@ -42,6 +42,13 @@ struct trad_frame_cache; instruction sequence. */ #define TRAMP_SENTINEL_INSN ULONGEST_MAX +/* Assuming the frame chain: (outer) prev <-> this <-> next (inner); + use THIS frame, and implicitly the NEXT frame's register unwind + method, return PREV frame's architecture. */ + +typedef struct gdbarch *(frame_prev_arch_ftype) (frame_info_ptr this_frame, + void **this_prologue_cache); + struct tramp_frame { /* The trampoline's type, some a signal trampolines, some are normal @@ -75,6 +82,11 @@ struct tramp_frame int (*validate) (const struct tramp_frame *self, frame_info_ptr this_frame, CORE_ADDR *pc); + + /* Given the current frame in THIS_FRAME and a frame cache in FRAME_CACHE, + return the architecture of the previous frame. */ + struct gdbarch *(*prev_arch) (frame_info_ptr this_frame, + void **frame_cache); }; void tramp_frame_prepend_unwinder (struct gdbarch *gdbarch,