From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2088.outbound.protection.outlook.com [40.107.105.88]) by sourceware.org (Postfix) with ESMTPS id AF9063858C62 for ; Mon, 28 Nov 2022 13:28:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF9063858C62 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=awQqI1kh07DVSxHIu8ikG4pH0/YXXU7zxuc68UgvkBsR7vxz+SKJe0T7otIGNe5QCB7BfQ3DjqrRDowgoTxeu4lG3QgX2b/uUTpusCffrTJEOfUOOVodQLpIllk2ofRD54Zfc37Q4MdX4dvgJlHhnjoDtL01uloxyhH+2/9pjwmaP+w1IamiuZqav5yHkCLjRntHRnqvOwyF8MPPYY7lGE/rkhy0IsJApvtnGcPEy4SpsGIkNszgpUWWTorSW3G3KYsAUq+My5H87pYWAb0LYFVu2w+m65iCFWq7APnDGy3iaKkTZAkPyJjc89HLJyu4ly92AD8utmkq8GN3yui1gg== 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=YImVpY89SPVPDIvjbjKNlJgC82QySTbzy1ZBlCkH49s=; b=QaijpiSq6EuLKiEPFpm9r7Qogh6w4AA5m7M2aTVfW4RjAy1SCST4s9y8zVW775Nav4+2IJGBL14N2pr8LdbpeO1jW7Q8++yjw0lK7MOHGM6YekNDCjsSsUhx0Cji9fiU8StutW1hwCZqru0OMHgBiDz+E37BNbH0kGOOKaTfvOeY4xUjWg5BQoi7AkAyHIw2k2zY/mN+ImLaWhyQ0h2aBosYMxBtq6vOwT3fwY6VzCKRSImmzd7vpW5A4ACK+TthjS/+PSXDJTPVXn5Ug5O0C3lrMeg+y4PuToMIzb73x6juFBsaCCcuZJPulxbEKrMIlWTV4Tgh4Dgs4FaR5nRIEQ== 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=YImVpY89SPVPDIvjbjKNlJgC82QySTbzy1ZBlCkH49s=; b=06CvBUVu20GG40YlSiGbBaz12lAVIOIc8huxPL+H3w+NGymDd2gwFWC1oHs4On/wbDJnwScSI0sL0fkX+QelInMxAb7LnnbbHRplxw7sqgMBcCh3DSnFlQ1780p5vk3IvN/9S4AEypWLulsl9ORsleW7vOD0FM18C/BxF7hvAYE= 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 PAWPR08MB8887.eurprd08.prod.outlook.com (2603:10a6:102:33b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.6; Mon, 28 Nov 2022 13:28:01 +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; Mon, 28 Nov 2022 13:28:00 +0000 Message-ID: <034a34c3-4c4b-2c90-9703-52c439c70164@arm.com> Date: Mon, 28 Nov 2022 13:27:58 +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: LO2P265CA0118.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::34) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|PAWPR08MB8887:EE_ X-MS-Office365-Filtering-Correlation-Id: 176543d3-0757-4021-2895-08dad1445e5e NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: afnoo+6T/WccjpYFIX3bznSSqbCY3SfllOTshEXIBMX5plO5uGMkruFyH2qtLkAbrckE+IJuguk0HR+cQ1HlvDxaX2wB5jzckyuHZbJUHTLw4YopFMaozmMpgsRe9ne5Tx/lcp8I/kLp3qrQ3wWu0qdqeMdAVS1cHmGKaQu4LMKRmmq4sE/fCu0pquFGSsUmdF/Skj1SaHdIzNMw9jq0uLhOnK4SeXDD9ZpS5CmRDMOcXhg/AJUmCYLSuEsdi2RxXDr9lLbp4YOTP+rm8K0Kn1gfs1WQcv1iNKHaUFfuSUZgOC9E4+O5g0tspBp8TWo9nydo9CD+8WBYNygTW04vihDDNSzPlI84ssrUstDVIJt/Ym6C1VNaf2/E8GoLnW9xJrO8e/uM+rGpbnS2n6kPo8hzKTMflsZRtQynme9r+1pbHEJtzDCVKFmsTWWlKMjMeXjA7RuHRB6E+Ze1PUHC/zU3o8UeMeKjeeIbsIgtbvPnDLDoMPLOJlaf11c0RYR7uQLfz7T3KeDQvFD2XuQq++apBL85quSd8WjYHd9yptcwXPALOdj60uJMT+koLjQqOhC8H67Az1SdUJSJaDtGiWhHtfF+hPjOpb4OfoT37HIGAiN78612Dzv0Oqv1rAiz8rgp/hWCSM325w9dz3X8/DdYHMtdTXv9DRR+RS3ouhuODd/cb5zdALUO7/vV6lOv2W2J4hCruMbtqCWnfxkbAbG+eL7KtWctuKnG1Uf8i5s= 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)(376002)(346002)(39860400002)(396003)(136003)(366004)(451199015)(36756003)(53546011)(6486002)(478600001)(38100700002)(26005)(6512007)(6506007)(66946007)(66476007)(8676002)(41300700001)(66556008)(86362001)(8936002)(30864003)(316002)(44832011)(5660300002)(186003)(31696002)(31686004)(83380400001)(2616005)(2906002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VzJXbWJtUGVwa0xmZ1pKOTRpVnpLUmdrUmFhaER2WkRXM1ZSUGorNDBoSnJl?= =?utf-8?B?V1Y4ekJ6ODhCNW5kUW40T0UvOXBYM201T1NEMjVhSnVaajJGc3RqdUhKaFI0?= =?utf-8?B?cGtiM0JmY2U2dW82RGZxM3NrQjZqdlJLcWNOT0FEa3NEeW5IeW5zWUE4bmxv?= =?utf-8?B?K29zV0ZyL2pEWGlDbEcxUG1VRUFKYmZ4VFVlR1BtTDdKeWtCWE4vNEV5SEky?= =?utf-8?B?c2RDTFc0cXRMTlpIbEZrZkRURk50MmViWXlGeVkvaHllbFBrMWlYKzBvRVJI?= =?utf-8?B?UndNYkJNb2Y5QlRJamI2MFRXdDhpMFd6eGdXOEF0a3R6WHhaZXBwb1lEU0V1?=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riginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 176543d3-0757-4021-2895-08dad1445e5e X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB3919.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2022 13:28:00.0681 (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: R8E5aL8cs1OQ2Sq0KKPkK/TpkXkqx5X2Fe8qebw58OPkmjKFGjGPmzibvMbjJQFTn/tHyg4B1Npq1xKLTK66Xg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB8887 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. debugging programs -> debugging programs remotely > > 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. VL -> VG > + > +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 to confirm, as I don't exactly remember how this went. Is the case where we switch threads during remote debugging covered in case we have threads with different vector lengths? I seem to recall we'd call thread_architecture in those cases, but I don't know how the expedited register comes into play for this case. Do we get expedited registers for each thread that has stopped? Otherwise LGTM. Reviewed-by: Luis Machado