From patchwork Tue Jan 22 18:42:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 31167 Received: (qmail 86064 invoked by alias); 22 Jan 2019 18:43:49 -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 85976 invoked by uid 89); 22 Jan 2019 18:43:48 -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=HContent-Transfer-Encoding:8bit 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:43:47 +0000 Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 051A810B707 for ; Tue, 22 Jan 2019 13:43:43 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 6/9] Support TLS variables on FreeBSD/amd64. Date: Tue, 22 Jan 2019 10:42:59 -0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes Use the fs_base register to fetch the address of a thread's tcb and calculate the address of the DTV array. This value is then passed to fbsd_get_thread_local_address to compute the final variable address. Note that fs_base is currently only available via the native target as core dumps on FreeBSD do not store the value of fs_base. gdb/ChangeLog: * amd64-fbsd-tdep.c (amd64fbsd_get_thread_local_address): New. (amd64fbsd_init_abi): Install gdbarch "fetch_tls_load_module_address" and "get_thread_local_address" methods. --- gdb/ChangeLog | 7 +++++++ gdb/amd64-fbsd-tdep.c | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 09e57e7474..7e97fae997 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-01-22 John Baldwin + + * amd64-fbsd-tdep.c (amd64fbsd_get_thread_local_address): New. + (amd64fbsd_init_abi): Install gdbarch + "fetch_tls_load_module_address" and "get_thread_local_address" + methods. + 2019-01-22 John Baldwin * fbsd-tdep.c (fbsd_pspace_data_handle): New variable. diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c index 628d42f7a0..32bda5741c 100644 --- a/gdb/amd64-fbsd-tdep.c +++ b/gdb/amd64-fbsd-tdep.c @@ -204,6 +204,26 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, &amd64fbsd_xstateregset, "XSAVE extended state", cb_data); } +/* Implement the get_thread_local_address gdbarch method. */ + +static CORE_ADDR +amd64fbsd_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, AMD64_FSBASE_REGNUM); + + ULONGEST fsbase; + if (regcache->cooked_read (AMD64_FSBASE_REGNUM, &fsbase) != REG_VALID) + error (_("Unable to fetch %%fsbase")); + + CORE_ADDR dtv_addr = fsbase + gdbarch_ptr_bit (gdbarch) / 8; + return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); +} + static void amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -241,6 +261,11 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) /* FreeBSD uses SVR4-style shared libraries. */ set_solib_svr4_fetch_link_map_offsets (gdbarch, svr4_lp64_fetch_link_map_offsets); + + set_gdbarch_fetch_tls_load_module_address (gdbarch, + svr4_fetch_objfile_link_map); + set_gdbarch_get_thread_local_address (gdbarch, + amd64fbsd_get_thread_local_address); } void