From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2040.outbound.protection.outlook.com [40.107.8.40]) by sourceware.org (Postfix) with ESMTPS id 6D9983858D38 for ; Wed, 1 Feb 2023 09:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D9983858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com 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=Kba4KwV2AOIxsURjhUboEWNUqxw2HJ4aCKErRKmVy1s=; b=qW32k8A3S6xwrCuVkiyr8SXYyn8HNeoUG9JXFwY3IlvUhjYVWCX0h5ZhsPWReM7ivMAvOYZp9a4V7wNjt04g68L5CN5SGnGMnPhTBgi36ISAkmZlWfePwbAbZYZdLBL4Bgs5YD8uwrEpALYZxjSq7l5S3J9xfyfqa4o/Czd6zek= Received: from DUZPR01CA0002.eurprd01.prod.exchangelabs.com (2603:10a6:10:3c3::8) by PA4PR08MB6285.eurprd08.prod.outlook.com (2603:10a6:102:e0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Wed, 1 Feb 2023 09:58:32 +0000 Received: from DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:3c3:cafe::1d) by DUZPR01CA0002.outlook.office365.com (2603:10a6:10:3c3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.22 via Frontend Transport; Wed, 1 Feb 2023 09:58:32 +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 DBAEUR03FT016.mail.protection.outlook.com (100.127.142.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24 via Frontend Transport; Wed, 1 Feb 2023 09:58:31 +0000 Received: ("Tessian outbound b1d3ffe56e73:v132"); Wed, 01 Feb 2023 09:58:31 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c00889bdd40ccc66 X-CR-MTA-TID: 64aa7808 Received: from 5c22e32a613c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 046AFB31-DC96-4805-929E-4969DBDC8F82.1; Wed, 01 Feb 2023 09:58:25 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5c22e32a613c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 01 Feb 2023 09:58:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NE/fsiM0Q5yILQFCQ2Tvp/lEYvTyzfc41Eq/25XndX5j0Zp6SildQaHaLEugZNwBRK9C47zoxjSEtmZQL+KtaUe+ItnSdXokPP2E+sxA43hYZkr3iB8tamqX0UqE3JNecbx8dNyvMFIb6Clt8Bo5epM4IfFpMqsmlfy6Pe7I+wvtrAuTRzCIXafz2+DWQBw6XYF8i5qdqZIjT8xz9gKNUrYD7uNtrKelys/PNb11+/2O52tGPZLkMAKZhrd168uViRlLQG+SUfP9iXrlXkgPO031p9s3wpvy5ke9Z8Hc0Ste6qBcz+VsTd8M/2vIdE5kASy+SrvzjBmumnTN28Kr2w== 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=Kba4KwV2AOIxsURjhUboEWNUqxw2HJ4aCKErRKmVy1s=; b=KvTUZzuo+HJCJ2SPOU/5I0z1PkIamqUTXf+In+yOMW4vDVapzfXvOJzeyGUejqfSJLfPHPFjYIM+FL4mAquLxY4SxDTu40JsYFywQos5ScrtrC7YDs+/BXnA7XFEOLHVbRmpLpiHP+V9zQqYTxQ4m5l2CSW/TTxXcdSVOhGf9IejA7QJzFcTa6P/LryZrmHuuCltJ6uJZYogaZtgJQFGUEKftqLmy1n/g4FtSAWvkAO3w2dfbh9wGzA5j0aM1VKne0hxKFLnVe14sqpdYJ3bjSfLwOlkBHWHT1GK8UzL1Mo7ZQtugnOCn8bIxI75yKrURDQlf+sBVJFcMLJ85YVAVg== 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=Kba4KwV2AOIxsURjhUboEWNUqxw2HJ4aCKErRKmVy1s=; b=qW32k8A3S6xwrCuVkiyr8SXYyn8HNeoUG9JXFwY3IlvUhjYVWCX0h5ZhsPWReM7ivMAvOYZp9a4V7wNjt04g68L5CN5SGnGMnPhTBgi36ISAkmZlWfePwbAbZYZdLBL4Bgs5YD8uwrEpALYZxjSq7l5S3J9xfyfqa4o/Czd6zek= 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 AS8PR08MB9410.eurprd08.prod.outlook.com (2603:10a6:20b:5a9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Wed, 1 Feb 2023 09:58:21 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::bced:32a3:b77e:90a6]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::bced:32a3:b77e:90a6%3]) with mapi id 15.20.6043.036; Wed, 1 Feb 2023 09:58:21 +0000 Message-ID: <7584f910-9dfe-81a7-83de-1236b92a1ad4@arm.com> Date: Wed, 1 Feb 2023 09:58:18 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v3 7/8] gdb/aarch64: Detect vector length changes when debugging remotely Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> <20230130044518.3322695-8-thiago.bauermann@linaro.org> From: Luis Machado In-Reply-To: <20230130044518.3322695-8-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0556.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:33b::6) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB9410:EE_|DBAEUR03FT016:EE_|PA4PR08MB6285:EE_ X-MS-Office365-Filtering-Correlation-Id: afd6417c-571f-4009-8aa7-08db043ae041 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: Flx3lqc+U8FNw2NyrPzwwQWyo+CnBrqqxBNAxd3osUL6RrmNmLxMEkkzaQ9h1vI6x1KOxlHTy09Y4T5U15rSY8RAL+HlkEvMJBffLR63tlxW0OVNICViA5zzLKW6WgNpa8Teh/rHJFusSQqDaTcklVgkdgD5/Jwwo7LQOsxDDs6OJCPfjRJEthOcm8JosPkTGHDCRCLvdirhxvUDL5zsyHetLnTgUqHFFz4SXe/rZq9CZT4HgiX2nsaQtColAJNQhTP3Yp3AJqUyvMTp3DeaWd/LWkdogsDUbDUlIaEFlWstm0xCM6pywyu+khy9HMni8iCx6PPyl4MunUffgl1+JScY7kZ7QZN86UWRyJywW7WkHXcCM+6BebAhmtxjqVygSeAeEhnq14NgX28YnnzqP7TsGheJWGofg9ANY4+AnGf04utzYbaiiFjvf/66xHdoQ8M51PF36XNjpPvUkoFwwbvKnZhE5T1JsuPiLSIJG08hgijSvjaB4kwvxmJO6/N8CVlI0Kgf5TDcCN2+IdRH6jXgf5W60+3OG7ZgzGxbESSBqT+OqHKux5SbJ0RSJqEY643W0oEEkFHJzXl4fPH3tISp7syPwhd92wXq2qj+AGFLd2Do/E4VsDpt61xWP2G6l0AUOjFPTkbRBHT4vnpf/Wp1bfAglLfu3urnkGdT4NKPSnGxxoySPfQOGa1vFuPwYcJGpeheLIs5BzYe9fIJ+RvOTCsks7bZrcqfk+8NUog= 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:(13230025)(4636009)(376002)(39860400002)(346002)(136003)(396003)(366004)(451199018)(31686004)(36756003)(31696002)(86362001)(38100700002)(6512007)(83380400001)(186003)(6486002)(26005)(6506007)(2616005)(53546011)(6666004)(478600001)(41300700001)(66476007)(66556008)(30864003)(44832011)(8936002)(2906002)(5660300002)(316002)(66946007)(8676002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9410 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: DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2c281f75-1a46-430b-b0e5-08db043ad9b6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +Roxpts8IKCJ6JmDQggvpRz3bumS0EmbSJw4hcu9ONEKAUsw811MRZgttzGN7VIonzjjfQmN2UGNCvqaEeTAODh0OTAf6bc0NfyDo574ZAxiT76qoSiHLft8D0Hflz4Z4oSvJCXbNfnoAg14OR80oYnmh+PdWGtPXyxDXGwuXJ4Iipyw1ayk5Bm6azcn5aYMt0CNb9Ti1HVBbziglVMqy9qNjUggpZcFrvTjORgVZ+i1NZIEuGvtDew3SIbHSdZh2sXN1I568o7DAU6pEtIgTuwi4/bn1lwmafwHMQURpsULRnMKCDQ1InlOofuo1hKnEyYEA6/0vNwLGI5VFbmZQDuj8zaIbmAXmZ1zz40sV4c47GMQRzxz0ewl6beRgRgCknBnuqGzZoSueko6tD8G6UwgoEYZq7npYiUFdv2pOA9wmhwFCOgjsu95dzThApdNoUKnSRBcTCnCT9kgNpa9QM28oUuKHHKhHxPWfPKg/FIFoULKXmiauzbxyrOJRFGefdVorl4GVo/BqgOJhOwBiZmGUyzSBW4WExKE63Xn8Oun6BpB8fizj+OIOSRcVcfjeXjjY/EcdFGelyzmEppYy2VV4q0XbzXbbyXivxOZ9Ach+0tEOh6/tqk+ALm/L4e+S4q/V4IrwJtduukD/CipUW1xiieLhaFZUR5RkyQzPgekuz4HUlD3cUFk5JnjbahvWpgVBzEqnTXfV4eDsaPvKXALDjvpyihit24hZu33p5s= 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:(13230025)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199018)(46966006)(40470700004)(36840700001)(6506007)(31696002)(31686004)(86362001)(6512007)(186003)(26005)(82310400005)(6666004)(356005)(478600001)(2616005)(6486002)(53546011)(81166007)(336012)(82740400003)(2906002)(30864003)(70206006)(47076005)(36756003)(36860700001)(44832011)(8676002)(316002)(8936002)(5660300002)(40480700001)(70586007)(83380400001)(41300700001)(40460700003)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2023 09:58:31.9906 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afd6417c-571f-4009-8aa7-08db043ae041 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: DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6285 X-Spam-Status: No, score=-12.1 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 List-Id: On 1/30/23 04:45, Thiago Jung Bauermann via Gdb-patches wrote: > If the remote target provides target description IDs in their threads > list and stop reply packets, use them to update the thread's gdbarch. > This allows debugging programs remotely that change their SVE vector > length during runtime. > > GDB already supports different vector lengths in native debugging by > calling target_ops::thread_architecture, and aarch64_linux_nat_target > provides an implementation of that method. > > So to provide the same feature in remote debugging, implement the > thread_architecture method in remote_target, so that the same > mechanism can be used for both the native and remote cases. This > method returns the gdbarch corresponding to the target description > provided by the last threads list or stop reply packet. > > To allow changing the architecture based on the target description, > add a new gdbarch method to allow arch-specific code to make the > adjustment. > --- > gdb/aarch64-tdep.c | 20 ++++++++++ > gdb/arch-utils.c | 8 ++++ > gdb/arch-utils.h | 4 ++ > gdb/gdbarch-components.py | 15 +++++++ > gdb/gdbarch-gen.h | 10 +++++ > gdb/gdbarch.c | 22 ++++++++++ > gdb/remote.c | 84 +++++++++++++++++++++++++++++++++++++++ > 7 files changed, 163 insertions(+) > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > index b576d3b9d99f..1e6e7116ed8a 100644 > --- a/gdb/aarch64-tdep.c > +++ b/gdb/aarch64-tdep.c > @@ -3502,6 +3502,25 @@ aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum) > || regnum == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base)); > } > > +/* Implement the "update_architecture" gdbarch method. */ > + > +static struct gdbarch * > +aarch64_update_architecture (struct gdbarch *gdbarch, const target_desc *tdesc) > +{ > + /* If this is a 32-bit architecture, then this is ARM, not AArch64. > + There are no SVE registers here, so just return the inferior > + architecture. */ > + if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) > + return gdbarch; > + > + struct gdbarch_info info; > + > + info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64); > + info.target_desc = tdesc; > + > + return gdbarch_find_by_info (info); > +} > + > /* Implement the stack_frame_destroyed_p gdbarch method. */ > > static int > @@ -3748,6 +3767,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 67968126488e..e8ad0aed6eb4 100644 > --- a/gdb/arch-utils.c > +++ b/gdb/arch-utils.c > @@ -1098,6 +1098,14 @@ 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 target_desc *tdesc) > +{ > + 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 56690f0fd435..aeee7f51ad49 100644 > --- a/gdb/arch-utils.h > +++ b/gdb/arch-utils.h > @@ -314,4 +314,8 @@ extern enum return_value_convention default_gdbarch_return_value > struct regcache *regcache, struct value **read_value, > const gdb_byte *writebuf); > > +/* Default implementation of gdbarch update_architecture method. */ > +extern struct gdbarch * > +default_update_architecture (struct gdbarch *gdbarch, const target_desc *tdesc); > + > #endif /* ARCH_UTILS_H */ > diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py > index 76ad2832d8a2..68b7521c9966 100644 > --- a/gdb/gdbarch-components.py > +++ b/gdb/gdbarch-components.py > @@ -2744,3 +2744,18 @@ Read core file mappings > predefault="default_read_core_file_mappings", > invalid=False, > ) > + > +Method( > + comment=""" > +An architecture may change while the inferior is running. For instance, the > +length of the vector registers in AArch64's Scalable Vector Extension is given > +by the contents of the VG pseudo-register. > + > +Return a gdbarch corresponding to the given target description. > +""", > + type="struct gdbarch *", > + name="update_architecture", > + params=[("const target_desc *", "tdesc")], > + predefault="default_update_architecture", > + invalid=False, > +) > diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h > index 32b2d96fbe01..d6068c2bc24f 100644 > --- a/gdb/gdbarch-gen.h > +++ b/gdb/gdbarch-gen.h > @@ -1672,3 +1672,13 @@ 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 while the inferior is running. For instance, the > + length of the vector registers in AArch64's Scalable Vector Extension is given > + by the contents of the VG pseudo-register. > + > + Return a gdbarch corresponding to the given target description. */ > + > +typedef struct gdbarch * (gdbarch_update_architecture_ftype) (struct gdbarch *gdbarch, const target_desc *tdesc); > +extern struct gdbarch * gdbarch_update_architecture (struct gdbarch *gdbarch, const target_desc *tdesc); > +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 46baca9c4793..07d3e060fe1f 100644 > --- a/gdb/gdbarch.c > +++ b/gdb/gdbarch.c > @@ -256,6 +256,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 > @@ -517,6 +518,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 ()); > @@ -1355,6 +1357,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); > } > @@ -5317,3 +5322,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 target_desc *tdesc) > +{ > + 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, tdesc); > +} > + > +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 f1d1944414c3..a17d65220408 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -506,6 +506,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; > @@ -1168,6 +1170,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 target description returned > + in the last stop reply or threads list. */ > + struct gdbarch *arch = nullptr; > + > /* Get the thread's resume state. */ > enum resume_state get_resume_state () const > { > @@ -1186,6 +1192,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; > + > + arch = nullptr; > } > > /* Get the information this thread's pending vCont-resumption. > @@ -1203,6 +1211,8 @@ struct remote_thread_info : public private_thread_info > void set_resumed () > { > m_resume_state = resume_state::RESUMED; > + > + arch = nullptr; > } > > private: > @@ -4046,6 +4056,29 @@ remote_target::update_thread_list () > info->extra = std::move (item.extra); > info->name = std::move (item.name); > info->thread_handle = std::move (item.thread_handle); > + > + /* If the threads list indicated a target description for this > + thread, add it to the thread information. */ > + if (item.tdesc_id) > + { > + const target_desc *tdesc > + = get_remote_state ()->get_tdesc (*item.tdesc_id); > + > + gdb_assert (tdesc != nullptr); > + > + /* If there's no thread-specific gdbarch, use the one from the > + whole inferior. */ > + if (info->arch == nullptr) > + info->arch = tp->inf->gdbarch; > + > + gdbarch *new_arch = gdbarch_update_architecture (info->arch, > + tdesc); > + if (new_arch != info->arch) > + { > + registers_changed_thread (tp); > + info->arch = new_arch; > + } > + } > } > } > } > @@ -8152,6 +8185,36 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, > && status->kind () != TARGET_WAITKIND_SIGNALLED > && status->kind () != TARGET_WAITKIND_NO_RESUMED) > { > + thread_info *thr = find_thread_ptid (this, ptid); > + > + /* If GDB already knows about this thread, we can give the > + architecture-specific code a chance to update the gdbarch based on the > + provided target description. */ > + if (stop_reply->tdesc_id && thr != nullptr) > + { > + const target_desc *tdesc > + = stop_reply->rs->get_tdesc (*stop_reply->tdesc_id); > + > + gdb_assert (tdesc != nullptr); > + > + /* If there's no gdbarch associated with the stop reply, use the one > + from the whole inferior. */ > + if (stop_reply->arch == nullptr) > + stop_reply->arch = thr->inf->gdbarch; > + > + stop_reply->arch = gdbarch_update_architecture (stop_reply->arch, > + tdesc); > + > + /* Save stop_reply->arch so that it can be returned by the > + thread_architecture method. */ > + remote_thread_info *remote_thr = get_remote_thread_info (thr); > + if (remote_thr->arch != stop_reply->arch) > + { > + registers_changed_thread (thr); > + remote_thr->arch = stop_reply->arch; > + } > + } > + > /* Expedited registers. */ > if (!stop_reply->regcache.empty ()) > { > @@ -14469,6 +14532,27 @@ remote_target::thread_info_to_thread_handle (struct thread_info *tp) > return priv->thread_handle; > } > > +/* Implementation of the thread_architecture method for the remote target. */ > + > +struct gdbarch * > +remote_target::thread_architecture (ptid_t ptid) > +{ > + thread_info *thr = find_thread_ptid (this, ptid); > + remote_thread_info *remote_thr; > + > + if (thr == nullptr) > + remote_thr = nullptr; > + else > + remote_thr = get_remote_thread_info (thr); > + > + if (remote_thr == nullptr || remote_thr->arch == nullptr) > + /* The default thread_architecture implementation is the one from > + process_stratum_target. */ > + return process_stratum_target::thread_architecture (ptid); > + > + return remote_thr->arch; > +} > + > bool > remote_target::can_async_p () > { I have no comments on this patch. It looks sane to me. Reviewed-by: Luis Machado