From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id AD78B385803D for ; Tue, 12 Apr 2022 23:48:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD78B385803D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 1F1D61A84E2D for ; Tue, 12 Apr 2022 19:48:13 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 09/14] Support TLS variables on FreeBSD/Aarch64. Date: Tue, 12 Apr 2022 16:46:42 -0700 Message-Id: <20220412234647.84595-10-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220412234647.84595-1-jhb@FreeBSD.org> References: <20220412234647.84595-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Tue, 12 Apr 2022 19:48:13 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 12 Apr 2022 23:48:14 -0000 Derive the pointer to the DTV array from the tpidr register. --- gdb/aarch64-fbsd-tdep.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c index 91fccb36105..bd422a8c687 100644 --- a/gdb/aarch64-fbsd-tdep.c +++ b/gdb/aarch64-fbsd-tdep.c @@ -23,6 +23,7 @@ #include "fbsd-tdep.h" #include "aarch64-tdep.h" #include "aarch64-fbsd-tdep.h" +#include "inferior.h" #include "osabi.h" #include "solib-svr4.h" #include "target.h" @@ -178,6 +179,29 @@ aarch64_fbsd_core_read_description (struct gdbarch *gdbarch, return aarch64_read_description (0, false, false, tls != nullptr); } +/* Implement the get_thread_local_address gdbarch method. */ + +static CORE_ADDR +aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, + CORE_ADDR lm_addr, CORE_ADDR offset) +{ + struct regcache *regcache; + + regcache = get_thread_arch_regcache (current_inferior ()->process_target (), + ptid, gdbarch); + + target_fetch_registers (regcache, AARCH64_TPIDR_REGNUM); + + ULONGEST tpidr; + if (regcache->cooked_read (AARCH64_TPIDR_REGNUM, &tpidr) != REG_VALID) + error (_("Unable to fetch %%tpidr")); + + /* %tpidr points to the TCB whose first member is the dtv + pointer. */ + CORE_ADDR dtv_addr = tpidr; + return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); +} + /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */ static void @@ -200,6 +224,11 @@ aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) (gdbarch, aarch64_fbsd_iterate_over_regset_sections); set_gdbarch_core_read_description (gdbarch, aarch64_fbsd_core_read_description); + + set_gdbarch_fetch_tls_load_module_address (gdbarch, + svr4_fetch_objfile_link_map); + set_gdbarch_get_thread_local_address (gdbarch, + aarch64_fbsd_get_thread_local_address); } void _initialize_aarch64_fbsd_tdep (); -- 2.34.1