From patchwork Mon Jun 30 15:54:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1818 Received: (qmail 17991 invoked by alias); 30 Jun 2014 15:54: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 17691 invoked by uid 89); 30 Jun 2014 15:54:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 30 Jun 2014 15:54:36 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5UFsZ1x022910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 30 Jun 2014 11:54:35 -0400 Received: from barimba.redhat.com (ovpn-113-95.phx2.redhat.com [10.3.113.95]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5UFsYII009257; Mon, 30 Jun 2014 11:54:34 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] convert to_get_thread_local_address to use target delegation Date: Mon, 30 Jun 2014 09:54:31 -0600 Message-Id: <1404143672-11428-2-git-send-email-tromey@redhat.com> In-Reply-To: <1404143672-11428-1-git-send-email-tromey@redhat.com> References: <1404143672-11428-1-git-send-email-tromey@redhat.com> This converts to_get_thread_local_address to use TARGET_DEFAULT_NORETURN. One possible oddity is that this changes the text of the kind of exception thrown in some cases. This doesn't seem to be a problem; in fact perhaps the final call to 'error' in target_translate_tls_address should be changed to call generic_tls_error. 2014-06-30 Tom Tromey * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. * target.c (generic_tls_error): New function. (target_translate_tls_address): Don't search target stack. * target-delegates.c: Rebuild. * ppc-linux-tdep.c (ppc_linux_spe_context): Don't search target stack. * linux-thread-db.c (thread_db_get_thread_local_address): Unconditionally call beneath target. --- gdb/ChangeLog | 12 ++++++++++++ gdb/linux-thread-db.c | 6 +----- gdb/ppc-linux-tdep.c | 5 ----- gdb/target-delegates.c | 16 ++++++++++++++++ gdb/target.c | 24 +++++++++++++----------- gdb/target.h | 3 ++- 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index e693c65..15902d8 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1874,11 +1874,7 @@ thread_db_get_thread_local_address (struct target_ops *ops, } beneath = find_target_beneath (ops); - if (beneath->to_get_thread_local_address) - return beneath->to_get_thread_local_address (beneath, ptid, lm, offset); - else - throw_error (TLS_GENERIC_ERROR, - _("TLS not supported on this target")); + return beneath->to_get_thread_local_address (beneath, ptid, lm, offset); } /* Callback routine used to find a thread based on the TID part of diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 5410554..6e46765 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1078,11 +1078,6 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order, struct target_ops *target = ¤t_target; volatile struct gdb_exception ex; - while (target && !target->to_get_thread_local_address) - target = find_target_beneath (target); - if (!target) - return 0; - TRY_CATCH (ex, RETURN_MASK_ERROR) { /* We do not call target_translate_tls_address here, because diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index eac7018..a92c46a 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -767,6 +767,19 @@ tdefault_goto_bookmark (struct target_ops *self, const gdb_byte *arg1, int arg2) tcomplain (); } +static CORE_ADDR +delegate_get_thread_local_address (struct target_ops *self, ptid_t arg1, CORE_ADDR arg2, CORE_ADDR arg3) +{ + self = self->beneath; + return self->to_get_thread_local_address (self, arg1, arg2, arg3); +} + +static CORE_ADDR +tdefault_get_thread_local_address (struct target_ops *self, ptid_t arg1, CORE_ADDR arg2, CORE_ADDR arg3) +{ + generic_tls_error (); +} + static enum target_xfer_status delegate_xfer_partial (struct target_ops *self, enum target_object arg1, const char *arg2, gdb_byte *arg3, const gdb_byte *arg4, ULONGEST arg5, ULONGEST arg6, ULONGEST *arg7) { @@ -1781,6 +1794,8 @@ install_delegators (struct target_ops *ops) ops->to_get_bookmark = delegate_get_bookmark; if (ops->to_goto_bookmark == NULL) ops->to_goto_bookmark = delegate_goto_bookmark; + if (ops->to_get_thread_local_address == NULL) + ops->to_get_thread_local_address = delegate_get_thread_local_address; if (ops->to_xfer_partial == NULL) ops->to_xfer_partial = delegate_xfer_partial; if (ops->to_memory_map == NULL) @@ -1995,6 +2010,7 @@ install_dummy_methods (struct target_ops *ops) ops->to_make_corefile_notes = dummy_make_corefile_notes; ops->to_get_bookmark = tdefault_get_bookmark; ops->to_goto_bookmark = tdefault_goto_bookmark; + ops->to_get_thread_local_address = tdefault_get_thread_local_address; ops->to_xfer_partial = tdefault_xfer_partial; ops->to_memory_map = tdefault_memory_map; ops->to_flash_erase = tdefault_flash_erase; diff --git a/gdb/target.c b/gdb/target.c index ece59e6..91756c8 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -49,6 +49,8 @@ static void target_info (char *, int); +static void generic_tls_error (void) ATTRIBUTE_NORETURN; + static void default_terminal_info (struct target_ops *, const char *, int); static int default_watchpoint_addr_within_range (struct target_ops *, @@ -732,24 +734,24 @@ target_is_pushed (struct target_ops *t) return 0; } +/* Default implementation of to_get_thread_local_address. */ + +static void +generic_tls_error (void) +{ + throw_error (TLS_GENERIC_ERROR, + _("Cannot find thread-local variables on this target")); +} + /* Using the objfile specified in OBJFILE, find the address for the current thread's thread-local storage with offset OFFSET. */ CORE_ADDR target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) { volatile CORE_ADDR addr = 0; - struct target_ops *target; - - for (target = current_target.beneath; - target != NULL; - target = target->beneath) - { - if (target->to_get_thread_local_address != NULL) - break; - } + struct target_ops *target = ¤t_target; - if (target != NULL - && gdbarch_fetch_tls_load_module_address_p (target_gdbarch ())) + if (gdbarch_fetch_tls_load_module_address_p (target_gdbarch ())) { ptid_t ptid = inferior_ptid; volatile struct gdb_exception ex; diff --git a/gdb/target.h b/gdb/target.h index d0601b8..cf4ced1 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -610,7 +610,8 @@ struct target_ops CORE_ADDR (*to_get_thread_local_address) (struct target_ops *ops, ptid_t ptid, CORE_ADDR load_module_addr, - CORE_ADDR offset); + CORE_ADDR offset) + TARGET_DEFAULT_NORETURN (generic_tls_error ()); /* Request that OPS transfer up to LEN 8-bit bytes of the target's OBJECT. The OFFSET, for a seekable object, specifies the