From patchwork Sat Feb 9 00:40:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 31383 Received: (qmail 28694 invoked by alias); 9 Feb 2019 00:42:46 -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 28512 invoked by uid 89); 9 Feb 2019 00:42:45 -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; Sat, 09 Feb 2019 00:42:43 +0000 Received: from ralph.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 4910610B770 for ; Fri, 8 Feb 2019 19:42:41 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 11/11] Support TLS variables on FreeBSD/powerpc. Date: Fri, 8 Feb 2019 16:40:14 -0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes Derive the pointer to the DTV array from the %r2 register on 32-bit powerpc and %r13 on 64-bit powerpc. gdb/ChangeLog: * ppc-fbsd-tdep.c (ppcfbsd_get_thread_local_address): New. (ppcfbsd_init_abi): Install gdbarch "fetch_tls_load_module_address" and "get_thread_local_address" methods. --- gdb/ChangeLog | 7 +++++++ gdb/ppc-fbsd-tdep.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6fa12ff815..90070b4039 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-02-08 John Baldwin + + * ppc-fbsd-tdep.c (ppcfbsd_get_thread_local_address): New. + (ppcfbsd_init_abi): Install gdbarch + "fetch_tls_load_module_address" and "get_thread_local_address" + methods. + 2019-02-08 John Baldwin * riscv-fbsd-tdep.c (riscv_fbsd_get_thread_local_address): New. diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c index c21a52c898..290bd1fd88 100644 --- a/gdb/ppc-fbsd-tdep.c +++ b/gdb/ppc-fbsd-tdep.c @@ -279,6 +279,39 @@ ppcfbsd_return_value (struct gdbarch *gdbarch, struct value *function, regcache, readbuf, writebuf); } +/* Implement the "get_thread_local_address" gdbarch method. */ + +static CORE_ADDR +ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, + CORE_ADDR lm_addr, CORE_ADDR offset) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + struct regcache *regcache; + int tp_offset, tp_regnum; + + regcache = get_thread_arch_regcache (ptid, gdbarch); + + if (tdep->wordsize == 4) + { + tp_offset = 0x7008; + tp_regnum = PPC_R0_REGNUM + 2; + } + else + { + tp_offset = 0x7010; + tp_regnum = PPC_R0_REGNUM + 13; + } + target_fetch_registers (regcache, tp_regnum); + + ULONGEST tp; + if (regcache->cooked_read (tp_regnum, &tp) != REG_VALID) + error (_("Unable to fetch tcb pointer")); + + /* tp points to the end of the TCB block. The first member of the + TCB is the pointer to the DTV array. */ + CORE_ADDR dtv_addr = tp - tp_offset; + return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); +} static void ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) @@ -322,6 +355,8 @@ ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_fetch_tls_load_module_address (gdbarch, svr4_fetch_objfile_link_map); + set_gdbarch_get_thread_local_address (gdbarch, + ppcfbsd_get_thread_local_address); } void