From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20059.outbound.protection.outlook.com [40.107.2.59]) by sourceware.org (Postfix) with ESMTPS id 8C55F3858D28 for ; Tue, 20 Sep 2022 08:59:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8C55F3858D28 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=oMTMkIppAA76g1V+ASC/J/4mMZxkSGCvo+ufz2HtabiOgplk+kkt01FVnv0hcETeB2ZTVzkBPPO0s0OTd+LYYEOTkwra533n5+ky3TZtMUMJUkbkQLhfsSE8FA8c6mKhoOmh9Roa5g7NddjIVrbLOWZNkCJWJWa6qyBBbprkKeBA6yJpvte7901sIQnWuoogTusUQdur2m9d1RWnLiFjma5ufZFEu3XR87nTZSyVox7/+KHilMEklGFyhDEkmIbrlht7Op7fGYT0f5ZOZ1Azpm7YumYqwDizhYslS3JZyTHyI43qKe3/CutCCTuOzR2acopdw4j7fEb84uzFE0jl6A== 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=6EZvybipaUraCcQZU5BkcGBAYqrCQUbtJ8z7t8KcttM=; b=bNgTRpJk/5llQ/PvguVoLO1KR4eJXT6o9Oe05AFFZF7Oeo1I0TUxy4yULGTTgAJqC+4kZNqiHUGSE/clIcwrh58KPxc9wQyKtiW8sETbQzuLq9sZ3SrE4yNc1UGv+Deq7yinIE5seg+7bYe6RDgQOimZcF3lUnzLu3h3C+cBHROsFCEFgr3J/UUYK2oc5nZmuq1GbwnYVG+WnHj5v/7LjlM/md1XN/EzMz1QmpjvSnX2kk8WJHRyb8TJ7nUtwmgIbSZsmD63xPfd6GKGYWOn6VymPIF0S79/1NDmv5iijYpd/u1avdgwxiZd2IT3uA9GrjsAfriaO/UVinal7/DlaQ== 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] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM6PR10CA0092.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::33) by AM0PR08MB5492.eurprd08.prod.outlook.com (2603:10a6:208:185::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.21; Tue, 20 Sep 2022 08:59:23 +0000 Received: from AM7EUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::b0) by AM6PR10CA0092.outlook.office365.com (2603:10a6:209:8c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.21 via Frontend Transport; Tue, 20 Sep 2022 08:59: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 AM7EUR03FT062.mail.protection.outlook.com (100.127.140.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.12 via Frontend Transport; Tue, 20 Sep 2022 08:59:23 +0000 Received: ("Tessian outbound 3c27ae03f5ec:v124"); Tue, 20 Sep 2022 08:59:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 57fc547e1e6a6673 X-CR-MTA-TID: 64aa7808 Received: from 5cc302a4d852.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id FF67DE5E-842D-4D9F-B39B-77A7B54504A8.1; Tue, 20 Sep 2022 08:59:16 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5cc302a4d852.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 20 Sep 2022 08:59:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=agpiOcrsGV1UYhJsMevRRPMz2HrmlVSr9zn9xoXDoHlWdsMkBxPw0IIkmA1xz7HkD4MhYSmmxDlew+laeuy/WaJMLxaJuL6MS7yVF8kbqAMCDnwwYmFSKquhKDNa6lIquvThZ5z4A9rJsmPasoiHstKcJmxk5ftFZJpemt+HV7kmZyk6qgqwh8A3dkVeoIUeczKJRsMxdOCW6p6nMtr2QAfbZ6HKil/aNPOkAbtcTFyIc00tKIiX/KdSevA4L7e5Lf3DHg4R3LN8vXBoHajiHE0YeJib5J4b2Rrb/iOHFXEd5mwL8TVvfQ2UrwAw+JII1djEuMBWBBJRTkF4k9Uj4g== 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=6EZvybipaUraCcQZU5BkcGBAYqrCQUbtJ8z7t8KcttM=; b=IGIbisOKT/h759aqPbeIQ1D8KqKWO8FErmxG0+mE6jfyYj1thng8n2TIOyqC6S54B+l+2qOsWnruS1q0oL/JBYb/RWK1o10yRmC4hJOpNKxrVPo7B0FhH5eaRKVa5daZzmdYfFYChhd42NURun+S4aX8V5d1xUksdhLwx7tvkPvU+F8fJWwgDGMmKz3L9yd48MWULdAJcF+dUNukifETxX+wRlpWXSDNa+OqMUebfaDP83L5paofmudg+Q9WFhDB7gxFxtJw5ygoxWorCwyk1KvNtCW09GFmRXGrB230B456zs80bsWzE51wkGA5/TQL28FPKM/Fe1g07BZnT8YycA== 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 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 PAXPR08MB6751.eurprd08.prod.outlook.com (2603:10a6:102:136::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.21; Tue, 20 Sep 2022 08:59:13 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::c5f9:a25b:a5f2:6094]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::c5f9:a25b:a5f2:6094%5]) with mapi id 15.20.5632.021; Tue, 20 Sep 2022 08:59:13 +0000 Message-ID: <36d5d17b-de17-71f9-06b8-46a31c450b4c@arm.com> Date: Tue, 20 Sep 2022 09:59:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 8/8] gdb/aarch64: When remote debugging detect changes in the target description Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20220908064151.3959930-1-thiago.bauermann@linaro.org> <20220908064151.3959930-9-thiago.bauermann@linaro.org> From: Luis Machado In-Reply-To: <20220908064151.3959930-9-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0290.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::7) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|PAXPR08MB6751:EE_|AM7EUR03FT062:EE_|AM0PR08MB5492:EE_ X-MS-Office365-Filtering-Correlation-Id: db28fa05-c376-4519-c7d8-08da9ae669cf 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: PhOUAXfnHSWfmDdkEh+elqLmNWPN4d6gsY0DHbSJEU1OOYS/vAeacogqwSIWzbK/AYo51NMklh5X1VrbQO/T33gpDtMIXvB9KsxbA3NgkhYIIneQWubZAwx8YL8SlSxtSWpoxwM78fy331nLJyPzCZWgjeP09EgwigBBBD4Nk0rSlWOlmcKSljl67UeE599fBpjUfMiP7iE2YrkSycq8qDya6fG1EC3TBKPRujJIWwuhSW3yi1FgWRVo/sbdqPmSm6QjIWvd6aB/MhqdABBH+07Ivi9CnSo7a0GJcmvquijm5P3G7bJSbbF71Jav614w8/swXRLEiDWV1T7C0714AwVwe4xlYEdegDHE3Da+1KrneB/yI6MQBpeWFDqLUxtYeK+7hHTGrQKVswmr4wQfUqGTxtIIKX00MtVx7diPRFma3EhgT7m6dV0nURDsFLdcNHLq7EBvc5J936+0tQ7qiy6hdaImOw61TQrrMXecj/6FGufNnw7JAY9a4W+ku1hZPZiok7DKZ2gqcKj8yGx0jRauLHxKfiG7kjBydGs9vqCS3HGgD8q1vDvuVTbsniLr7RiDgTaGXubT6TnIbbW1hyiDe/g8Ta3qExxPT3VdWm6WBTFe/3vQi/q8LHO42e7rOnoAslbDpG9r2QafUiou5L40bbLcC0fewC9AX7q6/m3SIQ7nHWFl8BLeROPZygQfWG0y3kx+Klsc76vctBtkBWFPEme7O54cAr8h/qOXCb+MplIFrtaf8A2su+ehpnsptN1vZUdWGlRxYylpOBnNDwrw16eynsL+Xuc/pw1kcBc= 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:(13230022)(4636009)(376002)(366004)(396003)(136003)(346002)(39860400002)(451199015)(31686004)(44832011)(36756003)(2906002)(30864003)(316002)(38100700002)(8676002)(5660300002)(66476007)(66946007)(66556008)(31696002)(8936002)(86362001)(186003)(478600001)(26005)(2616005)(6512007)(53546011)(83380400001)(41300700001)(6486002)(6666004)(6506007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6751 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: AM7EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b9d3bab0-6441-47b4-b152-08da9ae663e7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SJBpdxOSS2pLNXAlCTyuqwkpg0ZjhPGeAIoCnsITJQJ41PEfEFewh5kTWEr3eslbV55H2rqJGNlUwDdFDlPfjY04/1MLu4rFtfh12shwzjlt2oA37EJY02ov/5LSWqIyhzSVhVVCcnT+ZZmmgbCi/bKEf+MS5YLQkQmhxTNmvrkGg22rlCfOdGfPkhzixB43Lufoj7YAt9Ha8AKob95tKJm8o6bU1LEog1B0IpP3PumpKVyJLi1uEvBHK2eFFd+6QJ1dY2rGOJhyOCBROAunGiYVheyQO1o2mDbNx5X0OCbtNqGZK0rvP4fxql+of+BrnQlyAVu5w3IlXnqYD7K4RYCfnP40mZ4B7EG4o8l28R/Z3L4kiwTbFtnxNUe5owfnB4G2H/1oFjEDr7GlZ4P1QOZ526rcUxFrw88qrGwmG8U8Dk5Fcaw4EBex8P2i0oYmCmEYKADowAu1yUdft6k+c14J8vqZKLF9YZKExKY2O3E1ljT4eYLlOKs9UuhB7Gj4i1G9KPpryPgBOGaIwDVzXHgws42b/mnMyh3yoRrt4+KH1YTPQMgunKnVvufLAz9jGGwjlEbViMQEb8HV/faYquP3XDUWS4D0U/xPJpLKRndHdycY0ukeZXLPE5tPQN1O+k3suoEb8UjXg1vOw1PIUSQFHXUt9lAoW/I6uU2s2A3WqCoIVjj3pxuPeOXlxR1ViNVl5fXQkUr/wN1Xlzj41a7bZ74XKxDdEVy5q6J39dE2gLWUCDZXXUcoLs1spNeGiIwFgXo4MfXmT/PNRp/loO976DFuNEt5O7rCvCEHBcU= 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:(13230022)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199015)(36840700001)(40470700004)(46966006)(70586007)(2616005)(82740400003)(36756003)(186003)(8936002)(40460700003)(336012)(83380400001)(2906002)(316002)(82310400005)(41300700001)(86362001)(6666004)(8676002)(6486002)(40480700001)(31696002)(6506007)(6512007)(26005)(478600001)(356005)(81166007)(53546011)(36860700001)(70206006)(30864003)(47076005)(44832011)(31686004)(5660300002)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2022 08:59:23.3945 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db28fa05-c376-4519-c7d8-08da9ae669cf 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: AM7EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5492 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, 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 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: Tue, 20 Sep 2022 08:59:30 -0000 On 9/8/22 07:41, Thiago Jung Bauermann via Gdb-patches wrote: > If the remote target provides an expedited VG register, use it to update > its target description. This allows debugging programs that change their > SVE vector length during runtime. > > This is accomplished by implementing the thread_architecture method in > remote_target, which returns the gdbarch corresponding to the expedited > registers provided by the last stop reply. > > To allow changing the architecture based on the expedited registers, add a > new gdbarch method to allow arch-specific code to make the adjustment. > --- > gdb/aarch64-tdep.c | 28 +++++++++++++++++++++++++- > gdb/arch-utils.c | 9 +++++++++ > gdb/arch-utils.h | 5 +++++ > gdb/gdbarch-components.py | 16 +++++++++++++++ > gdb/gdbarch-gen.h | 11 ++++++++++ > gdb/gdbarch.c | 23 +++++++++++++++++++++ > gdb/remote.c | 42 +++++++++++++++++++++++++++++++++++++++ > 7 files changed, 133 insertions(+), 1 deletion(-) > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > index 18c2b1ec1523..acfd84ea3f33 100644 > --- a/gdb/aarch64-tdep.c > +++ b/gdb/aarch64-tdep.c > @@ -3420,7 +3420,8 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum) > || regnum == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base)); > } > > -/* Helper function for the "thread_architecture" target_ops method. > +/* Helper function for both the "update_architecture" gdbarch method and the > + "thread_architecture" target_ops method. > > Returns a new gdbarch that is equivalent to the given gdbarch, but with SVE > registers reflecting the given vq value. */ > @@ -3454,6 +3455,30 @@ aarch64_update_gdbarch (struct gdbarch *gdbarch, uint64_t vq) > return gdbarch_find_by_info (info); > } > > +/* Implement the "update_architecture" gdbarch method. */ > + > +static struct gdbarch * > +aarch64_update_architecture (struct gdbarch *gdbarch, > + const std::vector ®cache) > +{ > + gdb_assert (gdbarch != NULL); > + > + /* Look for the VG register. */ > + auto it = find_if (regcache.cbegin (), regcache.cend (), > + [] (const cached_reg_t ®) { > + return reg.num == AARCH64_SVE_VG_REGNUM; > + }); > + > + /* No VG register was provided. Don't change gdbarch. */ > + if (it == regcache.cend ()) > + return gdbarch; > + > + ULONGEST vg = extract_unsigned_integer (it->data, 8, > + gdbarch_byte_order (gdbarch)); > + > + return aarch64_update_gdbarch (gdbarch, sve_vq_from_vg (vg)); > +} > + > /* Implement the stack_frame_destroyed_p gdbarch method. */ > > static int > @@ -3667,6 +3692,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) > set_tdesc_pseudo_register_reggroup_p (gdbarch, > aarch64_pseudo_register_reggroup_p); > set_gdbarch_cannot_store_register (gdbarch, aarch64_cannot_store_register); > + set_gdbarch_update_architecture (gdbarch, aarch64_update_architecture); > > /* ABI */ > set_gdbarch_short_bit (gdbarch, 16); > diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c > index 9bd4f0ddae66..1c75d100b55b 100644 > --- a/gdb/arch-utils.c > +++ b/gdb/arch-utils.c > @@ -1092,6 +1092,15 @@ default_read_core_file_mappings > { > } > > +/* See arch-utils.h. */ > + > +struct gdbarch * > +default_update_architecture (struct gdbarch *gdbarch, > + const std::vector ®cache) > +{ > + return gdbarch; > +} > + > /* Non-zero if we want to trace architecture code. */ > > #ifndef GDBARCH_DEBUG > diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h > index f850e5fd6e78..f81e0ad78fa3 100644 > --- a/gdb/arch-utils.h > +++ b/gdb/arch-utils.h > @@ -300,4 +300,9 @@ extern void default_read_core_file_mappings > struct bfd *cbfd, > read_core_file_mappings_pre_loop_ftype pre_loop_cb, > read_core_file_mappings_loop_ftype loop_cb); > + > +/* Default implementation of gdbarch update_architecture method. */ > +extern struct gdbarch * > +default_update_architecture (struct gdbarch *gdbarch, > + const std::vector ®cache); > #endif /* ARCH_UTILS_H */ > diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py > index 71aa5991fbe0..5a23b2ac48b7 100644 > --- a/gdb/gdbarch-components.py > +++ b/gdb/gdbarch-components.py > @@ -2652,3 +2652,19 @@ Read core file mappings > predefault="default_read_core_file_mappings", > invalid=False, > ) > + > +Method( > + comment=""" > +An architecture may change based on the current contents of its registers. > +For instance, the length of the vector registers in AArch64's Scalable Vector > +Extension is given by the contents of the VL pseudo-register. > + > +This method allows an architecture to provide a new gdbarch corresponding to > +the registers in the given regcache. > +""", > + type="struct gdbarch *", > + name="update_architecture", > + params=[("const std::vector &", "regcache")], > + predefault="default_update_architecture", > + invalid=False, > +) > diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h > index 0504962e50d2..b543a9878930 100644 > --- a/gdb/gdbarch-gen.h > +++ b/gdb/gdbarch-gen.h > @@ -1627,3 +1627,14 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g > typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); > extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); > extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings); > + > +/* An architecture may change based on the current contents of its registers. > + For instance, the length of the vector registers in AArch64's Scalable Vector > + Extension is given by the contents of the VL pseudo-register. > + > + This method allows an architecture to provide a new gdbarch corresponding to > + the registers in the given regcache. */ > + > +typedef struct gdbarch * (gdbarch_update_architecture_ftype) (struct gdbarch *gdbarch, const std::vector ®cache); > +extern struct gdbarch * gdbarch_update_architecture (struct gdbarch *gdbarch, const std::vector ®cache); > +extern void set_gdbarch_update_architecture (struct gdbarch *gdbarch, gdbarch_update_architecture_ftype *update_architecture); > diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c > index 0edae7f6f0a2..4c9482f8fbf7 100644 > --- a/gdb/gdbarch.c > +++ b/gdb/gdbarch.c > @@ -253,6 +253,7 @@ struct gdbarch > gdbarch_type_align_ftype *type_align = nullptr; > gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = nullptr; > gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = nullptr; > + gdbarch_update_architecture_ftype *update_architecture = nullptr; > }; > > /* Create a new ``struct gdbarch'' based on information provided by > @@ -368,6 +369,7 @@ gdbarch_alloc (const struct gdbarch_info *info, > gdbarch->type_align = default_type_align; > gdbarch->get_pc_address_flags = default_get_pc_address_flags; > gdbarch->read_core_file_mappings = default_read_core_file_mappings; > + gdbarch->update_architecture = default_update_architecture; > /* gdbarch_alloc() */ > > return gdbarch; > @@ -605,6 +607,7 @@ verify_gdbarch (struct gdbarch *gdbarch) > /* Skip verify of type_align, invalid_p == 0 */ > /* Skip verify of get_pc_address_flags, invalid_p == 0 */ > /* Skip verify of read_core_file_mappings, invalid_p == 0 */ > + /* Skip verify of update_architecture, invalid_p == 0 */ > if (!log.empty ()) > internal_error (__FILE__, __LINE__, > _("verify_gdbarch: the following are invalid ...%s"), > @@ -1438,6 +1441,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) > gdb_printf (file, > "gdbarch_dump: read_core_file_mappings = <%s>\n", > host_address_to_string (gdbarch->read_core_file_mappings)); > + gdb_printf (file, > + "gdbarch_dump: update_architecture = <%s>\n", > + host_address_to_string (gdbarch->update_architecture)); > if (gdbarch->dump_tdep != NULL) > gdbarch->dump_tdep (gdbarch, file); > } > @@ -5363,3 +5369,20 @@ set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, > { > gdbarch->read_core_file_mappings = read_core_file_mappings; > } > + > +struct gdbarch * > +gdbarch_update_architecture (struct gdbarch *gdbarch, const std::vector ®cache) > +{ > + gdb_assert (gdbarch != NULL); > + gdb_assert (gdbarch->update_architecture != NULL); > + if (gdbarch_debug >= 2) > + gdb_printf (gdb_stdlog, "gdbarch_update_architecture called\n"); > + return gdbarch->update_architecture (gdbarch, regcache); > +} > + > +void > +set_gdbarch_update_architecture (struct gdbarch *gdbarch, > + gdbarch_update_architecture_ftype update_architecture) > +{ > + gdbarch->update_architecture = update_architecture; > +} > diff --git a/gdb/remote.c b/gdb/remote.c > index 70f918a7362c..4e6a33dfb686 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -491,6 +491,8 @@ class remote_target : public process_stratum_target > gdb::byte_vector thread_info_to_thread_handle (struct thread_info *tp) > override; > > + struct gdbarch *thread_architecture (ptid_t ptid) override; > + > void stop (ptid_t) override; > > void interrupt () override; > @@ -1150,6 +1152,10 @@ struct remote_thread_info : public private_thread_info > to stop for a watchpoint. */ > CORE_ADDR watch_data_address = 0; > > + /* The architecture corresponding to the expedited registers returned > + in the last stop reply. */ > + struct gdbarch *expedited_arch = nullptr; > + > /* Get the thread's resume state. */ > enum resume_state get_resume_state () const > { > @@ -1168,6 +1174,8 @@ struct remote_thread_info : public private_thread_info > m_resume_state = resume_state::RESUMED_PENDING_VCONT; > m_resumed_pending_vcont_info.step = step; > m_resumed_pending_vcont_info.sig = sig; > + > + expedited_arch = nullptr; > } > > /* Get the information this thread's pending vCont-resumption. > @@ -1185,6 +1193,8 @@ struct remote_thread_info : public private_thread_info > void set_resumed () > { > m_resume_state = resume_state::RESUMED; > + > + expedited_arch = nullptr; > } > > private: > @@ -8072,6 +8082,21 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, > /* Expedited registers. */ > if (!stop_reply->regcache.empty ()) > { > + /* If GDB already knows about this thread, we can give the > + architecture-specific code a chance to update the gdbarch based on > + the expedited registers. */ > + if (find_thread_ptid (this, ptid) != nullptr) > + { > + stop_reply->arch = gdbarch_update_architecture (stop_reply->arch, > + stop_reply->regcache); > + > + /* Save stop_reply->arch so that it can be returned by the > + thread_architecture method. */ > + remote_thread_info *remote_thr = get_remote_thread_info (this, > + ptid); > + remote_thr->expedited_arch = stop_reply->arch; > + } > + > struct regcache *regcache > = get_thread_arch_regcache (this, ptid, stop_reply->arch); > > @@ -14448,6 +14473,23 @@ remote_target::thread_info_to_thread_handle (struct thread_info *tp) > return priv->thread_handle; > } > > +struct gdbarch * > +remote_target::thread_architecture (ptid_t ptid) > +{ > + thread_info *thr = find_thread_ptid (this, ptid); > + remote_thread_info *remote_thr = nullptr; > + > + if (thr != nullptr) > + remote_thr = get_remote_thread_info (thr); > + > + if (remote_thr == nullptr || remote_thr->expedited_arch == nullptr) > + /* The default thread_architecture implementation is the one from > + process_stratum_target. */ > + return process_stratum_target::thread_architecture(ptid); > + > + return remote_thr->expedited_arch; > +} > + > bool > remote_target::can_async_p () > { LGTM for the aarch64 code. Someone else must approve the generic parts.