From patchwork Tue Jan 22 18:43:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 31169 Received: (qmail 118932 invoked by alias); 22 Jan 2019 18:52:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 118910 invoked by uid 89); 22 Jan 2019 18:52:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Jan 2019 18:52:25 +0000 Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 638F510B716 for ; Tue, 22 Jan 2019 13:43:45 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 8/9] Support TLS variables on FreeBSD/riscv. Date: Tue, 22 Jan 2019 10:43:01 -0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes Derive the pointer to the DTV array from the tp register. gdb/ChangeLog: * riscv-fbsd-tdep.c (riscv_fbsd_get_thread_local_address): New. (riscv_fbsd_init_abi): Install gdbarch "fetch_tls_load_module_address" and "get_thread_local_address" methods. --- gdb/ChangeLog | 7 +++++++ gdb/riscv-fbsd-tdep.c | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 06c637c80a..5d228614db 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-01-22 John Baldwin + + * riscv-fbsd-tdep.c (riscv_fbsd_get_thread_local_address): New. + (riscv_fbsd_init_abi): Install gdbarch + "fetch_tls_load_module_address" and "get_thread_local_address" + methods. + 2019-01-22 John Baldwin * i386-fbsd-tdep.c (i386fbsd_get_thread_local_address): New. diff --git a/gdb/riscv-fbsd-tdep.c b/gdb/riscv-fbsd-tdep.c index 97ad28f59a..3125a2285e 100644 --- a/gdb/riscv-fbsd-tdep.c +++ b/gdb/riscv-fbsd-tdep.c @@ -174,6 +174,28 @@ static const struct tramp_frame riscv_fbsd_sigframe = riscv_fbsd_sigframe_init }; +/* Implement the "get_thread_local_address" gdbarch method. */ + +static CORE_ADDR +riscv_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 (ptid, gdbarch); + + target_fetch_registers (regcache, RISCV_TP_REGNUM); + + ULONGEST tp; + if (regcache->cooked_read (RISCV_TP_REGNUM, &tp) != REG_VALID) + error (_("Unable to fetch %%tp")); + + /* %tp points to the end of the TCB which contains two pointers. + The first pointer in the TCB points to the DTV array. */ + CORE_ADDR dtv_addr = tp - (gdbarch_ptr_bit (gdbarch) / 8) * 2; + return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); +} + /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */ static void @@ -193,6 +215,11 @@ riscv_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_iterate_over_regset_sections (gdbarch, riscv_fbsd_iterate_over_regset_sections); + + set_gdbarch_fetch_tls_load_module_address (gdbarch, + svr4_fetch_objfile_link_map); + set_gdbarch_get_thread_local_address (gdbarch, + riscv_fbsd_get_thread_local_address); } void