From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2077.outbound.protection.outlook.com [40.107.21.77]) by sourceware.org (Postfix) with ESMTPS id 69DE23858280 for ; Tue, 20 Sep 2022 11:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69DE23858280 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=QpGgZB5YPCoGTDN1nsmCnctdhgOXHTiRJErx4gKsj5bTLY+cP9SSIwkFr+a/pxGhCOQezN39J431u/auFB8a/+F/+cQwnX0P1MYHHwGHjXngmSArO/6df4+D3OE9E8m2S9fwaLhDLaVDXVzKBq3qjfYqPME1h490rz4AMICsVUDn43K55Chv3Kw0Z7ye7KKR+BY/natMApU3jL+a/gyXL/GajTqLXt7fl3tazxAYJhIQUoR36Jacg02piErqS6J3B85p5hqtxHlhubLT8LG5ts9wFZLU/XvdqShhqn4vaj0IgP3KLIp/abutPBdrKVU6ponRYqszeTCXYwfbZkXeIg== 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=uVkv8BOaBysD4dWaBuoU2EXMqNs2ehR6T0NtwXnZBkY=; b=CrKjzF1ZS0NiOWR8ZQOQaey8HjaqhHWxlHajprgI5XoatGYgLNTxX66Kghw8+HmHJZTSAjWlbQvmacql6qu7cfajsrI3EajVHOTf0B1b1DTz41CtH9R31CE2HkvEwbiRVtQOS4ZF7PdgGtxFz1PmluOtZGnkfGSGSeQe8mJBG4mzzNSZStQ86+Sxlt7u1Dpfove6VWfI/+hDPY0HZZJX7VYiwVdq9I382HwG4J+aVJ4Bn8NguARJEBoc5NNFVQwwKy4XPrSiE0d1Yb/FpuABTvML56oAh8ITlRsj0jXElegN5PyGGXdXHW+Gc0rQ7VxVjNU3HDsx7lZ++31Mck0fzg== 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 AS9PR06CA0065.eurprd06.prod.outlook.com (2603:10a6:20b:464::30) by DU0PR08MB9419.eurprd08.prod.outlook.com (2603:10a6:10:422::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.18; Tue, 20 Sep 2022 11:21:59 +0000 Received: from VE1EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:464:cafe::3d) by AS9PR06CA0065.outlook.office365.com (2603:10a6:20b:464::30) 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 11:21:59 +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 VE1EUR03FT017.mail.protection.outlook.com (10.152.18.90) 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 11:21:59 +0000 Received: ("Tessian outbound e2c58cd9a6bb:v124"); Tue, 20 Sep 2022 11:21:58 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b087f427dcf8227e X-CR-MTA-TID: 64aa7808 Received: from 8dcd3ed1bb38.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 775233AA-F84E-4807-8FCD-7471E8EA433E.1; Tue, 20 Sep 2022 11:21:52 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8dcd3ed1bb38.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 20 Sep 2022 11:21:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GjiovstyosrPzWsBoDMm3nJhKyP9HoMKw0VA3YNWcmAdOWMLDmP1gJDYydeHGf/WYAudfKy1B3jgwHba+UMTx6y0YIp3KFG/SqxAGJV9g5eWDRHCS6pIUp01vsD3nvDxnd5uTKg4D6Ulm5KeQZFjJwrQXnt3hJvOY56w3UsfeBn3Lxz1D98Wi7DqWUgUsoHVi3blbFFtYJx7s2l13uql8ZNN6yf4VzjaWxFFUPCTPbfnKH5PsxZO7w/wAINhWx2quhDUP/OQD54vOxRp44EJPipmiuha5dhZV60c6KuQJUah2ios9JxLEXfLdiWYhZ2+Lx3YOze1UlhFOcX7CAvv6A== 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=uVkv8BOaBysD4dWaBuoU2EXMqNs2ehR6T0NtwXnZBkY=; b=RC/LxtrBeATlhtdIt3HHWwCWXJQQENbG3IakM2IneyIhVWI2sKGCXLN8TH5AFy+z+UMXypCZfh38IV9NRMFvSr8Jt3do5bGXLKfmQp4g1FWP4v88bc4c59WOCHJh97xMsv9ZWKk1YhyQDmZj76a0ANyykMCRC8/rEnt1HZX2rzSLKeJeI+6MGco+W03rAFXyc72n038WAxX7dxQVEOkCJ0a3kcoZkroH9Oq76VbQcXSiVexCw1LKGRrTi+6hKkSXl2GviwV5lcUH0wKS/BdLNR+jEN0lzjoYmP9rPa743vi2onK6jJOlIGu0C5XQ69+W7GjIRvA5McGtLIKdKXe5sQ== 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 PA4PR08MB7385.eurprd08.prod.outlook.com (2603:10a6:102:2a0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.15; Tue, 20 Sep 2022 11:21:41 +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 11:21:41 +0000 Message-ID: <1df73e50-a195-0db3-bf27-73e3550903c2@arm.com> Date: Tue, 20 Sep 2022 12:21:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 5/8] gdbserver: Move target description from being per-process to being per-thread Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20220908064151.3959930-1-thiago.bauermann@linaro.org> <20220908064151.3959930-6-thiago.bauermann@linaro.org> From: Luis Machado In-Reply-To: <20220908064151.3959930-6-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0161.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::8) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|PA4PR08MB7385:EE_|VE1EUR03FT017:EE_|DU0PR08MB9419:EE_ X-MS-Office365-Filtering-Correlation-Id: 106fc4fe-4b9a-450b-cb50-08da9afa5574 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: H0oJknC98CmsFPgHm2lLRGMcqyfnAvcwFAYn2dTK5dCiUyF1a+KxM7KWbinjff/Pf22m9Lt44J0Z7YkMhH1jprx5tG6Laus8+JDUaeYEJMSNm5KMBglcodSArhdDBMxm5TqcY/vXkDt2y52erp1iD08oyhxhe/0EqYfBS786qRFqVOxBm24vXqjMNBN6pekKQ4GG/pyPP+NvpeH0Hjv/BcMrMAXcbRxr9smG2S7OzEJadVPwHp/x4uRtc6bjc5hNc+ep5B+DfDFpTYxkmMlxixWq5qGKZhP7q+VrT+RqOG8JYR61gp+dHzeF8+W/Y9DztVrOU2qpDZOJa4NrI1DHTaLOTdMDi2luQp6fY9fKGqTO5a15kSjSasrfQ6i5x/prB0Gy0WYec46UvDb7ozHYMQzYhU24RXaRTifEYmqbc0BeDEkzzdsfZU5uPYPtkBJ5ISYl7NMqDUMGT4CTmZiaoBVwh1wT1EMgplrR8F/dB1QI+HaiEt7JIqhO9DcR7UrkRTYZ2EiChWn5qa5Af0DTCyN7K34nqXRbIrhcVbQY6Sf4SrkFFahx+ge+HguAzj6qdStXA3DYt7DFOS9VKPLlyIOEhNOr2fshwHFzK5niL7Hoxhi8f4fhI+qUYmrlHsyYYzI1J+LHlhdYzo2A7Zwf4NMtmTGkV0RGKNZFODTm0JhxAdmzeaUNk4MwR5GVDfqvVzpyFqBtQo4JIPsE/lEaKUMltdQW0+1hHe9u2kHD4K1tqxMro4OdJRRA9AAotX9daYTwqJ/4On0JG+fz5zn7dRKVvT9y9r1lo9+9KU9RSUs= 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)(366004)(136003)(346002)(39860400002)(376002)(396003)(451199015)(83380400001)(31686004)(36756003)(38100700002)(44832011)(5660300002)(41300700001)(86362001)(31696002)(26005)(66946007)(66476007)(478600001)(30864003)(6486002)(8676002)(8936002)(66556008)(6512007)(2616005)(2906002)(316002)(6506007)(186003)(53546011)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7385 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: VE1EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e1e1928e-f171-4be6-143f-08da9afa4a71 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RztL9rS71OTS0ujx0Y0EZjvbz6p6S9pDiwOLNoG5fzJo2ocQpOIVPhStTHyBW6rmGzIj86PeWV/07PY9Tt8QQk0xXwGVa17ug/26D9dMzjMWDTDOzWslIiMnQrofuy5jMVegqXZJ8qiYcQbN27rNYbCDlcAIwRfaoyZk7trVV60IKEirG05csTSoiq+PxCd0IFlWEEM+fE8hMNVPzWK6uiLARhzFM+IGW3yQRrg92sGFbLBci2x9txTOaaIZ6KeKct7AmfHwXfYsmAMWY9C9ZZIhkdAuFxk5E1sJRhcJGz3g5XOkAwSHpSR0pt16XFkG1ImEKVzsHIMxyTYIrzHh9QfoShbK/q39htiqmPS1yLRuHYc8xKCMjGhihAyFAsKvrmTEy9UVgwws1L3VnBqPKi4WGyJFfPwErbMvMquFf9zrW7KiXEUmxTE1tlJB8O8txXVRo2hJMrD4E1WwJEOgiruk8FB0tvEtg8UHzz/26/5qCWgzE3vsG5Vy7EZIBykg3lrzuSB35jFP67PVYCEB7MnvVLkw4GXQejyPaGs6WhCadJUZWUWtIfRsvZQOuVOhqIp3mLtLWU7u+Ou2wz7fY3hszo1FgXMNpbofhAZJG7h92r/pGaScPOJiB/+RholLQbbamIq1ZorEzl9TJfm1kKB3JKDlxTl6KmvDTO/ej5e2g3/79lALx+WK4DYRdnf5JqNDroLCwHQ4Pcj2TSNH6jh0srBXEhDFyvjejzwg5Ya4F1DtaiDStVJoIZbiihZMsze1Y/bXpRTiqHT+XJbCT773JouUrjAnVzyjaRQ6roQ= 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)(136003)(346002)(396003)(376002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(6506007)(36756003)(2906002)(36860700001)(31696002)(40480700001)(26005)(86362001)(6512007)(8676002)(53546011)(8936002)(6486002)(70586007)(356005)(82740400003)(70206006)(81166007)(41300700001)(478600001)(40460700003)(30864003)(31686004)(2616005)(5660300002)(83380400001)(82310400005)(336012)(47076005)(316002)(186003)(44832011)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2022 11:21:59.1083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 106fc4fe-4b9a-450b-cb50-08da9afa5574 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: VE1EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9419 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 11:22:08 -0000 On 9/8/22 07:41, Thiago Jung Bauermann via Gdb-patches wrote: > This change allows aarch64-linux to support debugging programs where > different threads have different SVE vector length. This requires gdbserver > to support different inferior threads having different target descriptions. > > After this change, all targets except aarch64-linux will still use one > target description for all threads in the inferior process (their tdesc > member in struct thread_info will point to the same target description). > This is done by linux_process_target::handle_extended_wait which copies the > target description from the original thread to the new thread if > low_new_thread doesn't provide one. > > In the case of aarch64-linux, the low_new_thread method probes the thread's > architecture features and assigns a description to it. > --- > gdbserver/gdbthread.h | 2 ++ > gdbserver/inferiors.h | 2 -- > gdbserver/linux-aarch64-low.cc | 48 ++++++++++++++++++++++++++++++-- > gdbserver/linux-arc-low.cc | 6 ++-- > gdbserver/linux-arm-low.cc | 4 +-- > gdbserver/linux-ia64-low.cc | 2 +- > gdbserver/linux-loongarch-low.cc | 2 +- > gdbserver/linux-low.cc | 24 ++++++++++------ > gdbserver/linux-m68k-low.cc | 2 +- > gdbserver/linux-mips-low.cc | 8 +++--- > gdbserver/linux-nios2-low.cc | 2 +- > gdbserver/linux-or1k-low.cc | 2 +- > gdbserver/linux-ppc-low.cc | 10 +++---- > gdbserver/linux-riscv-low.cc | 2 +- > gdbserver/linux-s390-low.cc | 4 +-- > gdbserver/linux-sh-low.cc | 2 +- > gdbserver/linux-sparc-low.cc | 2 +- > gdbserver/linux-tic6x-low.cc | 2 +- > gdbserver/linux-x86-low.cc | 2 +- > gdbserver/linux-xtensa-low.cc | 2 +- > gdbserver/netbsd-aarch64-low.cc | 2 +- > gdbserver/netbsd-amd64-low.cc | 2 +- > gdbserver/netbsd-i386-low.cc | 2 +- > gdbserver/regcache.cc | 6 ++-- > gdbserver/tdesc.cc | 2 +- > 25 files changed, 95 insertions(+), 49 deletions(-) > > diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h > index 8b897e73d33b..47b44d03b8e0 100644 > --- a/gdbserver/gdbthread.h > +++ b/gdbserver/gdbthread.h > @@ -80,6 +80,8 @@ struct thread_info > > /* Branch trace target information for this thread. */ > struct btrace_target_info *btrace = nullptr; > + > + const struct target_desc *tdesc = nullptr; Should we keep a process-wide target description in case we fail to detect the target description for a given thread? Also, it may simplify some of the changes in this patch. Features detected in the process will always be present in the thread for aarch64. It is just the vector length of SVE that might be different. > }; > > extern std::list all_threads; > diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h > index 6de746cb228f..cdb39dd90d54 100644 > --- a/gdbserver/inferiors.h > +++ b/gdbserver/inferiors.h > @@ -65,8 +65,6 @@ struct process_info > for unfiltered syscall reporting. */ > std::vector syscalls_to_catch; > > - const struct target_desc *tdesc = NULL; > - > /* Private target data. */ > struct process_info_private *priv = NULL; > > diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc > index 9b57be73818e..8c4306ab8794 100644 > --- a/gdbserver/linux-aarch64-low.cc > +++ b/gdbserver/linux-aarch64-low.cc > @@ -191,9 +191,26 @@ struct arch_process_info > static int > is_64bit_tdesc (void) > { > + const target_desc *tdesc; > + > + if (current_thread && current_thread->tdesc) > + tdesc = current_thread->tdesc; > + else > + { > + /* Find some thread that has a target description. */ > + const struct thread_info *thread > + = find_thread (current_process ()->pid, [] (thread_info *thr) { > + return thr->tdesc != nullptr; > + }); > + > + gdb_assert (thread != nullptr); > + > + tdesc = thread->tdesc; > + } > + > /* We may not have a current thread at this point, so go straight to > the process's target description. */ > - return register_size (current_process ()->tdesc, 0) == 8; > + return register_size (tdesc, 0) == 8; > } Keeping the process-wide target description would simplify this function in my opinion. We won't have 64-bit processes spawning 32-bit threads. > > static void > @@ -678,6 +695,31 @@ void > aarch64_target::low_new_thread (lwp_info *lwp) > { > aarch64_linux_new_thread (lwp); > + > + ptid_t ptid = ptid_of_lwp (lwp); > + process_info *proc = find_process_pid (ptid.pid ()); > + > + /* If the inferior is still going through the shell or the thread isn't > + stopped we can't read its registers in order to read the target > + description. */ > + if (proc->starting_up) > + return; > + > + thread_info *thread = get_lwp_thread (lwp); > + unsigned int machine; > + gdb_assert (ptid.lwp_p ()); > + bool is_elf64 = linux_pid_exe_is_elf_64_file (ptid.lwp (), &machine); > + > + if (is_elf64) > + { > + gdb::optional features > + = aarch64_get_arch_features (thread); > + > + if (features.has_value()) > + thread->tdesc = aarch64_linux_read_description (*features); > + } > + else > + thread->tdesc = aarch32_linux_read_description (); > } > > void > @@ -848,14 +890,14 @@ aarch64_target::low_arch_setup () > succeeds so all we can do here is assert that features is valid. */ > gdb_assert (features.has_value ()); > > - current_process ()->tdesc = aarch64_linux_read_description (*features); > + current_thread->tdesc = aarch64_linux_read_description (*features); > > /* Adjust the register sets we should use for this particular set of > features. */ > aarch64_adjust_register_sets (*features); > } > else > - current_process ()->tdesc = aarch32_linux_read_description (); > + current_thread->tdesc = aarch32_linux_read_description (); Given 32-bit Arm processes will have the same target description throughout their lives, would it make sense to have a single target description stored process-wide, and whenever we need the description we can find it there? Maybe code it as: return current_thread->tdesc == nullptr? current_process ()->tdesc : current_thread->tdesc; This would make the changes to all the other targets unnecessary, as those would be able to lookup their target descriptions from the process instead of the threads. > > aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread)); > } > diff --git a/gdbserver/linux-arc-low.cc b/gdbserver/linux-arc-low.cc > index fee1dd33eb20..1727bdede452 100644 > --- a/gdbserver/linux-arc-low.cc > +++ b/gdbserver/linux-arc-low.cc > @@ -123,19 +123,19 @@ arc_linux_read_description (void) > void > arc_target::low_arch_setup () > { > - current_process ()->tdesc = arc_linux_read_description (); > + current_thread->tdesc = arc_linux_read_description (); > } > > bool > arc_target::low_cannot_fetch_register (int regno) > { > - return (regno >= current_process ()->tdesc->reg_defs.size ()); > + return (regno >= current_thread->tdesc->reg_defs.size ()); > } > > bool > arc_target::low_cannot_store_register (int regno) > { > - return (regno >= current_process ()->tdesc->reg_defs.size ()); > + return (regno >= current_thread->tdesc->reg_defs.size ()); > } > > /* This works for both endianness. Below you see an illustration of how > diff --git a/gdbserver/linux-arm-low.cc b/gdbserver/linux-arm-low.cc > index d40ce412fe1c..5f52e061bcf6 100644 > --- a/gdbserver/linux-arm-low.cc > +++ b/gdbserver/linux-arm-low.cc > @@ -998,7 +998,7 @@ arm_target::low_arch_setup () > /* Query hardware watchpoint/breakpoint capabilities. */ > arm_linux_init_hwbp_cap (tid); > > - current_process ()->tdesc = arm_read_description (); > + current_thread->tdesc = arm_read_description (); > > iov.iov_base = gpregs; > iov.iov_len = sizeof (gpregs); > @@ -1118,7 +1118,7 @@ static struct regs_info regs_info_arm = > const regs_info * > arm_target::get_regs_info () > { > - const struct target_desc *tdesc = current_process ()->tdesc; > + const struct target_desc *tdesc = current_thread->tdesc; > > if (have_ptrace_getregset == 1 > && (is_aarch32_linux_description (tdesc) > diff --git a/gdbserver/linux-ia64-low.cc b/gdbserver/linux-ia64-low.cc > index 4530a283b376..3095038fc50e 100644 > --- a/gdbserver/linux-ia64-low.cc > +++ b/gdbserver/linux-ia64-low.cc > @@ -382,7 +382,7 @@ ia64_target::get_regs_info () > void > ia64_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_ia64; > + current_thread->tdesc = tdesc_ia64; > } > > /* The linux target ops object. */ > diff --git a/gdbserver/linux-loongarch-low.cc b/gdbserver/linux-loongarch-low.cc > index cccf1ba780b3..50cca5b2da10 100644 > --- a/gdbserver/linux-loongarch-low.cc > +++ b/gdbserver/linux-loongarch-low.cc > @@ -86,7 +86,7 @@ loongarch_target::low_arch_setup () > > if (!tdesc->expedite_regs) > init_target_desc (tdesc.get (), expedite_regs); > - current_process ()->tdesc = tdesc.release (); > + current_thread->tdesc = tdesc.release (); > } > > /* Collect GPRs from REGCACHE into BUF. */ > diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc > index 9034a1d8fabe..d37eb120e114 100644 > --- a/gdbserver/linux-low.cc > +++ b/gdbserver/linux-low.cc > @@ -585,8 +585,8 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, > clone_all_breakpoints (child_thr, event_thr); > > target_desc_up tdesc = allocate_target_description (); > - copy_target_description (tdesc.get (), parent_proc->tdesc); > - child_proc->tdesc = tdesc.release (); > + copy_target_description (tdesc.get (), event_thr->tdesc); > + child_thr->tdesc = tdesc.release (); > > /* Clone arch-specific process data. */ > low_new_fork (parent_proc, child_proc); > @@ -642,6 +642,11 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, > before calling resume_one_lwp. */ > new_lwp->stopped = 1; > > + /* If low_new_thread () wasn't able to set the target description, copy > + it from the original thread. */ > + if (new_lwp->thread->tdesc == nullptr) > + new_lwp->thread->tdesc = event_thr->tdesc; > + > /* If we're suspending all threads, leave this one suspended > too. If the fork/clone parent is stepping over a breakpoint, > all other threads have been suspended already. Leave the > @@ -1209,7 +1214,7 @@ linux_process_target::attach (unsigned long pid) > > async_file_mark (); > > - gdb_assert (proc->tdesc != NULL); > + gdb_assert (initial_thread->tdesc != NULL); > } > > return 0; > @@ -2330,7 +2335,7 @@ linux_process_target::filter_event (int lwpid, int wstat) > > /* Architecture-specific setup after inferior is running. */ > proc = find_process_pid (pid_of (thread)); > - if (proc->tdesc == NULL) > + if (thread->tdesc == NULL || proc->starting_up) > { > if (proc->attached) > { > @@ -3966,14 +3971,13 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step, > { > struct thread_info *thread = get_lwp_thread (lwp); > int ptrace_request; > - struct process_info *proc = get_thread_process (thread); > > /* Note that target description may not be initialised > - (proc->tdesc == NULL) at this point because the program hasn't > + (thread->tdesc == NULL) at this point because the program hasn't > stopped at the first instruction yet. It means GDBserver skips > the extra traps from the wrapper program (see option --wrapper). > Code in this function that requires register access should be > - guarded by proc->tdesc == NULL or something else. */ > + guarded by thread->tdesc == NULL or something else. */ > > if (lwp->stopped == 0) > return; > @@ -4090,7 +4094,9 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step, > step = single_step (lwp); > } > > - if (proc->tdesc != NULL && low_supports_breakpoints ()) > + process_info *proc = find_process_pid(thread->id.pid()); > + > + if (!proc->starting_up && low_supports_breakpoints ()) > { > struct regcache *regcache = get_thread_regcache (current_thread, 1); > > @@ -4349,7 +4355,7 @@ linux_process_target::thread_needs_step_over (thread_info *thread) > > /* GDBserver is skipping the extra traps from the wrapper program, > don't have to do step over. */ > - if (proc->tdesc == NULL) > + if (proc->starting_up) > return false; > > /* LWPs which will not be resumed are not interesting, because we > diff --git a/gdbserver/linux-m68k-low.cc b/gdbserver/linux-m68k-low.cc > index 7a433ffab5ef..5b17e21c5258 100644 > --- a/gdbserver/linux-m68k-low.cc > +++ b/gdbserver/linux-m68k-low.cc > @@ -253,7 +253,7 @@ m68k_target::get_regs_info () > void > m68k_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_m68k; > + current_thread->tdesc = tdesc_m68k; > } > > /* The linux target ops object. */ > diff --git a/gdbserver/linux-mips-low.cc b/gdbserver/linux-mips-low.cc > index e72403bd91cb..6d9d110e412c 100644 > --- a/gdbserver/linux-mips-low.cc > +++ b/gdbserver/linux-mips-low.cc > @@ -213,7 +213,7 @@ mips_read_description (void) > void > mips_target::low_arch_setup () > { > - current_process ()->tdesc = mips_read_description (); > + current_thread->tdesc = mips_read_description (); > } > > /* Per-process arch-specific data we want to keep. */ > @@ -264,7 +264,7 @@ mips_target::low_cannot_fetch_register (int regno) > if (get_regs_info ()->usrregs->regmap[regno] == -1) > return true; > > - tdesc = current_process ()->tdesc; > + tdesc = current_thread->tdesc; > > /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */ > if (register_size (tdesc, regno) > sizeof (PTRACE_XFER_TYPE)) > @@ -284,7 +284,7 @@ mips_target::low_cannot_store_register (int regno) > if (get_regs_info ()->usrregs->regmap[regno] == -1) > return true; > > - tdesc = current_process ()->tdesc; > + tdesc = current_thread->tdesc; > > /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */ > if (register_size (tdesc, regno) > sizeof (PTRACE_XFER_TYPE)) > @@ -308,7 +308,7 @@ mips_target::low_cannot_store_register (int regno) > bool > mips_target::low_fetch_register (regcache *regcache, int regno) > { > - const struct target_desc *tdesc = current_process ()->tdesc; > + const struct target_desc *tdesc = current_thread->tdesc; > > if (find_regno (tdesc, "r0") == regno) > { > diff --git a/gdbserver/linux-nios2-low.cc b/gdbserver/linux-nios2-low.cc > index e850fcfc1efc..675305f0de51 100644 > --- a/gdbserver/linux-nios2-low.cc > +++ b/gdbserver/linux-nios2-low.cc > @@ -119,7 +119,7 @@ static int nios2_regmap[] = { > void > nios2_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_nios2_linux; > + current_thread->tdesc = tdesc_nios2_linux; > } > > /* Implement the low_cannot_fetch_register linux target ops method. */ > diff --git a/gdbserver/linux-or1k-low.cc b/gdbserver/linux-or1k-low.cc > index 4c6d69496fb2..0288d634367e 100644 > --- a/gdbserver/linux-or1k-low.cc > +++ b/gdbserver/linux-or1k-low.cc > @@ -115,7 +115,7 @@ static int or1k_regmap[] = { > void > or1k_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_or1k_linux; > + current_thread->tdesc = tdesc_or1k_linux; > } > > /* Implement the low_cannot_fetch_register linux target ops method. */ > diff --git a/gdbserver/linux-ppc-low.cc b/gdbserver/linux-ppc-low.cc > index 08608b2dcc38..486574bd3dbb 100644 > --- a/gdbserver/linux-ppc-low.cc > +++ b/gdbserver/linux-ppc-low.cc > @@ -212,7 +212,7 @@ ppc_check_regset (int tid, int regset_id, int regsetsize) > bool > ppc_target::low_cannot_store_register (int regno) > { > - const struct target_desc *tdesc = current_process ()->tdesc; > + const struct target_desc *tdesc = current_thread->tdesc; > > #ifndef __powerpc64__ > /* Some kernels do not allow us to store fpscr. */ > @@ -890,9 +890,9 @@ ppc_target::low_arch_setup () > else > tdesc = tdesc_powerpc_64l; > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > > - /* The value of current_process ()->tdesc needs to be set for this > + /* The value of current_thread->tdesc needs to be set for this > call. */ > ppc_hwcap = linux_get_hwcap (current_thread, features.wordsize); > ppc_hwcap2 = linux_get_hwcap2 (current_thread, features.wordsize); > @@ -952,7 +952,7 @@ ppc_target::low_arch_setup () > } > #endif > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > > for (regset = ppc_regsets; regset->size >= 0; regset++) > switch (regset->get_request) > @@ -1094,7 +1094,7 @@ is_elfv2_inferior (void) > CORE_ADDR phdr; > Elf64_Ehdr ehdr; > > - const struct target_desc *tdesc = current_process ()->tdesc; > + const struct target_desc *tdesc = current_thread->tdesc; > int wordsize = register_size (tdesc, 0); > > if (!linux_get_auxv (current_thread, wordsize, AT_PHDR, &phdr)) > diff --git a/gdbserver/linux-riscv-low.cc b/gdbserver/linux-riscv-low.cc > index 6b2902e422d9..c1c3e5fa5cae 100644 > --- a/gdbserver/linux-riscv-low.cc > +++ b/gdbserver/linux-riscv-low.cc > @@ -92,7 +92,7 @@ riscv_target::low_arch_setup () > > if (!tdesc->expedite_regs) > init_target_desc (tdesc.get (), expedite_regs); > - current_process ()->tdesc = tdesc.release (); > + current_thread->tdesc = tdesc.release (); > } > > /* Collect GPRs from REGCACHE into BUF. */ > diff --git a/gdbserver/linux-s390-low.cc b/gdbserver/linux-s390-low.cc > index 0d01dffa64a4..4d3e81a05c76 100644 > --- a/gdbserver/linux-s390-low.cc > +++ b/gdbserver/linux-s390-low.cc > @@ -697,7 +697,7 @@ s390_target::low_arch_setup () > break; > } > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > } > > > @@ -771,7 +771,7 @@ s390_target::get_regs_info () > if (have_hwcap_s390_high_gprs) > { > #ifdef __s390x__ > - const struct target_desc *tdesc = current_process ()->tdesc; > + const struct target_desc *tdesc = current_thread->tdesc; > > if (register_size (tdesc, 0) == 4) > return ®s_info_3264; > diff --git a/gdbserver/linux-sh-low.cc b/gdbserver/linux-sh-low.cc > index 966bdeb8ba7a..bee46b8892a3 100644 > --- a/gdbserver/linux-sh-low.cc > +++ b/gdbserver/linux-sh-low.cc > @@ -180,7 +180,7 @@ sh_target::get_regs_info () > void > sh_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_sh; > + current_thread->tdesc = tdesc_sh; > } > > /* The linux target ops object. */ > diff --git a/gdbserver/linux-sparc-low.cc b/gdbserver/linux-sparc-low.cc > index d4826d029a9d..7c9d4d456926 100644 > --- a/gdbserver/linux-sparc-low.cc > +++ b/gdbserver/linux-sparc-low.cc > @@ -299,7 +299,7 @@ sparc_target::low_breakpoint_at (CORE_ADDR where) > void > sparc_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_sparc64; > + current_thread->tdesc = tdesc_sparc64; > } > > static struct regset_info sparc_regsets[] = { > diff --git a/gdbserver/linux-tic6x-low.cc b/gdbserver/linux-tic6x-low.cc > index 893b5f795ac1..02032112a1be 100644 > --- a/gdbserver/linux-tic6x-low.cc > +++ b/gdbserver/linux-tic6x-low.cc > @@ -389,7 +389,7 @@ tic6x_target::low_arch_setup () > } > tic6x_usrregs_info.regmap = tic6x_regmap; > > - current_process ()->tdesc = tic6x_read_description (feature); > + current_thread->tdesc = tic6x_read_description (feature); > } > > static struct regsets_info tic6x_regsets_info = > diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc > index d2b55f6f0d2b..14c42603a67e 100644 > --- a/gdbserver/linux-x86-low.cc > +++ b/gdbserver/linux-x86-low.cc > @@ -1091,7 +1091,7 @@ x86_target::get_regs_info () > void > x86_target::low_arch_setup () > { > - current_process ()->tdesc = x86_linux_read_description (); > + current_thread->tdesc = x86_linux_read_description (); > } > > bool > diff --git a/gdbserver/linux-xtensa-low.cc b/gdbserver/linux-xtensa-low.cc > index 8e7c4c08b7bd..7035edff7bd2 100644 > --- a/gdbserver/linux-xtensa-low.cc > +++ b/gdbserver/linux-xtensa-low.cc > @@ -311,7 +311,7 @@ static struct regs_info myregs_info = > void > xtensa_target::low_arch_setup () > { > - current_process ()->tdesc = tdesc_xtensa; > + current_thread->tdesc = tdesc_xtensa; > } > > const regs_info * > diff --git a/gdbserver/netbsd-aarch64-low.cc b/gdbserver/netbsd-aarch64-low.cc > index f8447b0d1eec..211a0794b7fc 100644 > --- a/gdbserver/netbsd-aarch64-low.cc > +++ b/gdbserver/netbsd-aarch64-low.cc > @@ -101,7 +101,7 @@ netbsd_aarch64_target::low_arch_setup () > static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL }; > init_target_desc (tdesc, expedite_regs_aarch64); > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > } > > /* The singleton target ops object. */ > diff --git a/gdbserver/netbsd-amd64-low.cc b/gdbserver/netbsd-amd64-low.cc > index d08e3489f580..024401a6418c 100644 > --- a/gdbserver/netbsd-amd64-low.cc > +++ b/gdbserver/netbsd-amd64-low.cc > @@ -194,7 +194,7 @@ netbsd_amd64_target::low_arch_setup () > > init_target_desc (tdesc, amd64_expedite_regs); > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > } > > /* The singleton target ops object. */ > diff --git a/gdbserver/netbsd-i386-low.cc b/gdbserver/netbsd-i386-low.cc > index f6fa40c144e3..eec149aa9f99 100644 > --- a/gdbserver/netbsd-i386-low.cc > +++ b/gdbserver/netbsd-i386-low.cc > @@ -145,7 +145,7 @@ netbsd_i386_target::low_arch_setup () > > init_target_desc (tdesc, i386_expedite_regs); > > - current_process ()->tdesc = tdesc; > + current_thread->tdesc = tdesc; > } > > /* The singleton target ops object. */ > diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc > index ebaeb5e86895..9e8572fbee50 100644 > --- a/gdbserver/regcache.cc > +++ b/gdbserver/regcache.cc > @@ -39,11 +39,9 @@ get_thread_regcache (struct thread_info *thread, int fetch) > have. */ > if (regcache == NULL) > { > - struct process_info *proc = get_thread_process (thread); > + gdb_assert (thread->tdesc != NULL); > > - gdb_assert (proc->tdesc != NULL); > - > - regcache = new_register_cache (proc->tdesc); > + regcache = new_register_cache (thread->tdesc); > set_thread_regcache_data (thread, regcache); > } > > diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc > index 5693cc6626fb..17666c33661f 100644 > --- a/gdbserver/tdesc.cc > +++ b/gdbserver/tdesc.cc > @@ -129,7 +129,7 @@ current_target_desc (void) > if (current_thread == NULL) > return &default_description; > > - return current_process ()->tdesc; > + return current_thread->tdesc; > } > > /* An empty structure. */