From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2063.outbound.protection.outlook.com [40.107.241.63]) by sourceware.org (Postfix) with ESMTPS id 7DFF23858D37 for ; Wed, 30 Nov 2022 08:43:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DFF23858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R/jjgCaqLLb905mIsbgUk0tFcWEdq+Q1C0aC+4kwhTn5GxPrrvrCayJTvruGOBMGdOI5BJ3nIKJLAy0QmpMnvb+zWu3i1FyRyfm1fCS2wF67NrY5+TbYz2255pyo82gD3Uo6cGYDQ7y+Ods1YXW+unKWWxmoCT9d4ITN/guDU+kqdfzpkuyNrRXqYxChSJRx3urMY+wbpgYnM1aC1aCkjUDME+Z0kISgdXWqaJpAu9oPKXHS2/63YXsF3+zpuo9rAjflL6XrDfyQi8PzwDqyVGIYYUmGz4+bhUyb7ClIKX2APhEyYgJw8lPYZMJSzy+xQjf66uKm3suHxLPgvby1Sg== 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=fJ4W9EG1KQIrv604H6FzDdwt3/Ywt3jieSVPFW1Dbqo=; b=ZMD/ldCe6Xv0meiakE6ZKj5U3s+ieVnP61ARcZ+JOtz/EQppBeAhSpB7QTRacgj9lFyjxwS0TAQBuS/Tt91xux1gGtfpZ2TapTS8zXFzC0tIATao8bydC6vgq+CdOOKrx+4/ynl0C2IFfXYfFAN84kyRN4xo5ewgCm4wOAD4+3rY89o0lhlW9hRi3rpGf9NriOINhSksZrCQiyWG7dogY75ytbKQMfrDR9jVrDPn8ZXFTQR/68Zpr7NM1DBR73Q8+upDy5Uv15Hs38A3lT2ghTBZUF+aqrQTFZ5z57px3R9amQTX7JwtEhkOBd7O/lCtRAscqzAuIXYKE5cTKj1dxA== 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=fJ4W9EG1KQIrv604H6FzDdwt3/Ywt3jieSVPFW1Dbqo=; b=4z4OA2T4OLlF2l5HTqy7NCB7AxPtF5PQ73jLzAkYM1d05zKK1FwJvvEBC97g1ZkQsCGGNiggIZzzV1aqDWsVc8xawpeTJ/Xal8rz14d7cGNjYv9UHWrI1ng9MsXThrwJq7UoKzc/MJ+uGS9romQJcmI/XlnWUnmvc8eVvmX9tB8= Authentication-Results: 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 AS8PR08MB6424.eurprd08.prod.outlook.com (2603:10a6:20b:33e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Wed, 30 Nov 2022 08:43:46 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::fe5c:b195:a2ad:b19c]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::fe5c:b195:a2ad:b19c%4]) with mapi id 15.20.5880.008; Wed, 30 Nov 2022 08:43:46 +0000 Message-ID: Date: Wed, 30 Nov 2022 08:43:43 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 6/6] gdb/aarch64: Detect vector length changes when debugging remotely Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> <20221126020452.1686509-7-thiago.bauermann@linaro.org> From: Luis Machado In-Reply-To: <20221126020452.1686509-7-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0252.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::24) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB6424:EE_ X-MS-Office365-Filtering-Correlation-Id: 42942060-3942-49c4-8306-08dad2aefe7b NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sg/H04cpQxOQCRwPqxw06CZUP6LJIJmbEClwz9h0ipzmb4p7tcHUdKYX/2Y5uMZcRSsTB9Ci8PqmkB7fMPUKR3fPjiJ5b9fspX7VJgwxQLF1ghRF4XKP8rYe16TGqwBedIFELXHVG2nCVPrPDiLkQxdIc04fWnAXM/ss38qF3o2bPOthwrpLmS89UuYLl/FVAyJCw4O76o5zXDjSJJLFrR1svXgvq1Qw5/yLybd3zLF17zsBkxoYSgqqUiVpdmZMKedZGRS0DQqAoDPiU/we4Hx8lXf9aOO/NbNC/9dYDoLcNU3FThvYq9M2xHF/NPijdS4PBEEXFM8GGw/pJwxpSk2zoqyy0NCj1iC6Rc2n/LZ4gM5dZ1N8c/LE5l3wJrPjrtn+WwlWLbHLeER/B2ILABagotQ4uOGi1cyazgcRKPweBM52jc/t+YOGYwjau1tBu8bGfM47bJzqFhVoUWImvhSDldlCTMcX0PeX/bd+IMgnGT5735EVHTfLerL5uxPlvh0qDXMlrBmObGddK374dRQbtrYuYGJEzprBNLmR/IVLLgLjoc7w9WMk0xI5XtTsFcfULyUQ6NTK7XJXTWeG0JjG6+CLlgYW2fWWcwcyMQ6JjgvvaJXEctpeuAJoZscqWcb2o4hHHvGFPzBiSa9VgtoxQtp1N29+x/eN8w84TILdk9cmyD5w8iQunLRFSPPsxK0Q/vyP1yoUX45NQreHIVYt5pzBbXzRPEnc3Wycz0o= X-Forefront-Antispam-Report: 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)(346002)(366004)(376002)(39860400002)(136003)(396003)(451199015)(38100700002)(83380400001)(44832011)(30864003)(31696002)(86362001)(8936002)(478600001)(6486002)(66476007)(5660300002)(66556008)(26005)(2616005)(66946007)(316002)(6506007)(186003)(8676002)(6512007)(41300700001)(6666004)(2906002)(53546011)(31686004)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Z1FRcGIrV2FqMHdJN1ZUZzhoZEZMd0Q0T3lScHg3SDcxdTF0RmZKdjNQVE1K?= =?utf-8?B?S0kyeTMxLzFTYWxsLzdIQkFaTzIvNjQwMFhudlR0R0pLSGxsbE1aUzBCbHhu?= =?utf-8?B?WmV2UFFzTUN2Z0JYVTZEN1ZvS3RUaWUrTjFvSkRWa0c4dUhRWCsxYVlSWitJ?= =?utf-8?B?b3dJZ1c5eFhxSDdLQmN1NUlqR0lES3dndS8wSnBWcVplK1VPdzh3KytDOUZw?= =?utf-8?B?R3pnYkVJNmo4MVpBZmRjd0hLdGhwTlZDeUp5WTBhdlFDVGI2ZU9wbHE3T3A1?= =?utf-8?B?enlNY21DQkhJVGhjTmVBOGdhMGRFRWp6aWR0TWJFMVZjaTVyY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Rw?= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42942060-3942-49c4-8306-08dad2aefe7b X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB3919.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2022 08:43:46.4652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZPkbL9wO2oWuBTUTFWoQL6peMaNEffCqMS2IdpmvX2JdBbkLnXpI/9oFj/pq1TR5eurqN4pii0+Beu2mit6Tgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6424 X-Spam-Status: No, score=-11.6 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 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 11/26/22 02:04, Thiago Jung Bauermann wrote: > If the remote target provides an expedited VG register, use it to update > the thread's gdbarch. 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 | 26 +++++++++++++++++++++++- > gdb/arch-utils.c | 9 +++++++++ > gdb/arch-utils.h | 5 +++++ > gdb/gdbarch-components.py | 16 +++++++++++++++ > gdb/gdbarch-gen.h | 11 ++++++++++ > gdb/gdbarch.c | 22 ++++++++++++++++++++ > gdb/remote.c | 42 +++++++++++++++++++++++++++++++++++++++ > 7 files changed, 130 insertions(+), 1 deletion(-) > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > index ffc128d91f60..764f693aee8d 100644 > --- a/gdb/aarch64-tdep.c > +++ b/gdb/aarch64-tdep.c > @@ -3486,7 +3486,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. */ > @@ -3521,6 +3522,28 @@ 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) > +{ > + /* 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 > @@ -3742,6 +3765,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 7b84daf046e2..2315aacb4bbe 100644 > --- a/gdb/arch-utils.c > +++ b/gdb/arch-utils.c > @@ -1090,6 +1090,15 @@ default_get_return_buf_addr (struct type *val_type, frame_info_ptr cur_frame) > return 0; > } > > +/* 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 46018a6fbbb6..e68a91f6753d 100644 > --- a/gdb/arch-utils.h > +++ b/gdb/arch-utils.h > @@ -304,4 +304,9 @@ extern void default_read_core_file_mappings > /* Default implementation of gdbarch default_get_return_buf_addr method. */ > extern CORE_ADDR default_get_return_buf_addr (struct type *val_typegdbarch, > frame_info_ptr cur_frame); > + > +/* 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 9b688998a7bd..fbb32c5e5853 100644 > --- a/gdb/gdbarch-components.py > +++ b/gdb/gdbarch-components.py > @@ -2698,3 +2698,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 a663316df166..a65699e7241f 100644 > --- a/gdb/gdbarch-gen.h > +++ b/gdb/gdbarch-gen.h > @@ -1649,3 +1649,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 3227e9458801..1b0a2c70db4c 100644 > --- a/gdb/gdbarch.c > +++ b/gdb/gdbarch.c > @@ -255,6 +255,7 @@ struct gdbarch > gdbarch_type_align_ftype *type_align = default_type_align; > gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags; > gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings; > + gdbarch_update_architecture_ftype *update_architecture = default_update_architecture; > }; > > /* Create a new ``struct gdbarch'' based on information provided by > @@ -514,6 +515,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 (_("verify_gdbarch: the following are invalid ...%s"), > log.c_str ()); > @@ -1352,6 +1354,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); > } > @@ -5314,3 +5319,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 5118ecd0a312..eb60ed51585b 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: > @@ -8068,6 +8078,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); > > @@ -14382,6 +14407,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 () > { Just recalled this. One deficiency of the current SVE implementation is that it doesn't have a proper way to hide the Z register when they don't have any meaningful state (SVE not active, so we have fpsimd state). Given the VL will always be reported as > 0, even if there is no active SVE state, gdb will always attempt to show Z registers. And those are quite verbose. In this sense, the implementations of the the thread_architecture methods for both native aarch64 and remote differ. While native aarch64's implementation is capable of detecting the lack of active SVE state, the remote implementation can't. If gdbserver decided to drop the Z registers mid-execution (before the SVE state is not active), there wouldn't be vg for gdb to make a decision. For example, there isn't a way to return a value of 0 for vg, as vg == 0 would mean no SVE feature. If there isn't a SVE feature, vg wouldn't exist. Looking ahead, it would be the same for SME with its SVL. If we have to show both Z and ZA contexts, it will be quite a verbose exchange if we're listing all the possible registers. I wonder if there is a better way to handle this that would still allow us to hide these scalable registers when there is no active state.