From patchwork Thu Feb 28 02:30:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 31679 Received: (qmail 128497 invoked by alias); 28 Feb 2019 02:30:30 -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 128448 invoked by uid 89); 28 Feb 2019 02:30:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=beneath, 1848, Attempts 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 ESMTP; Thu, 28 Feb 2019 02:30:27 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5946173641 for ; Thu, 28 Feb 2019 02:30:26 +0000 (UTC) Received: from f29-4.lan (ovpn-117-11.phx2.redhat.com [10.3.117.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF38A5C882 for ; Thu, 28 Feb 2019 02:30:25 +0000 (UTC) Date: Wed, 27 Feb 2019 19:30:25 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v2 1/5] Introduce target_ops method thread_info_to_thread_handle Message-ID: <20190227193025.3a6750ed@f29-4.lan> In-Reply-To: <20190227192416.613752c8@f29-4.lan> References: <20190227192416.613752c8@f29-4.lan> MIME-Version: 1.0 X-IsSubscribed: yes This patch adds a thread_info_to_thread_handle method to the target_ops struct. It also implements this functionality for remote targets and linux native threads. gdb/ChangeLog: * gdbthread.h (thread_to_thread_handle): Declare. * thread.c (gdbtypes.h): Include. (thread_to_thread_handle): New function. * target.h (struct target_ops): Add thread_info_to_thread_handle. (target_thread_info_to_thread_handle): Declare. * target.c (target_thread_info_to_thread_handle): New function. * target-debug.h, target-delegates.c: Regenerate. * linux-thread-db.c (class thread_db_target): Add method thread_info_to_thread_handle. (thread_db_target::thread_info_to_thread_handle): Define. * remote.c (class remote_target): Add new method thread_info_to_thread_handle. (remote_target::thread_info_to_thread_handle): Define. --- gdb/linux-thread-db.c | 19 +++++++++++++++++++ gdb/remote.c | 10 ++++++++++ gdb/target-debug.h | 2 ++ gdb/target-delegates.c | 28 ++++++++++++++++++++++++++++ gdb/target.c | 6 ++++++ gdb/target.h | 6 ++++++ 6 files changed, 71 insertions(+) diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index fd67dcb17b..fe9f44046a 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -105,6 +105,7 @@ public: thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle, int handle_len, inferior *inf) override; + gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) override; }; static char *libthread_db_search_path; @@ -1698,6 +1699,24 @@ thread_db_target::thread_handle_to_thread_info (const gdb_byte *thread_handle, return NULL; } +/* Return the thread handle associated the thread_info pointer TP. */ + +gdb::byte_vector +thread_db_target::thread_info_to_thread_handle (struct thread_info *tp) +{ + thread_db_thread_info *priv = get_thread_db_thread_info (tp); + + if (priv == NULL) + return gdb::byte_vector (); + + int handle_size = sizeof (priv->tid); + gdb::byte_vector rv (handle_size); + + memcpy (rv.data (), &priv->tid, handle_size); + + return rv; +} + /* Get the address of the thread local variable in load module LM which is stored at OFFSET within the thread local storage for thread PTID. */ diff --git a/gdb/remote.c b/gdb/remote.c index 36136e3e3e..546b0f36f7 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -495,6 +495,9 @@ public: int handle_len, inferior *inf) override; + gdb::byte_vector thread_info_to_thread_handle (struct thread_info *tp) + override; + void stop (ptid_t) override; void interrupt () override; @@ -14047,6 +14050,13 @@ remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle, return NULL; } +gdb::byte_vector +remote_target::thread_info_to_thread_handle (struct thread_info *tp) +{ + remote_thread_info *priv = get_remote_thread_info (tp); + return priv->thread_handle; +} + bool remote_target::can_async_p () { diff --git a/gdb/target-debug.h b/gdb/target-debug.h index d9f7d46dd9..23a8d25420 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -184,6 +184,8 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_thread_info_pp(X) \ target_debug_do_print (host_address_to_string (X)) +#define target_debug_print_gdb_byte_vector(X) \ + target_debug_do_print (host_address_to_string (X.data ())) static void target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status) diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index a25851e9cf..ffa90d966f 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -70,6 +70,7 @@ struct dummy_target : public target_ops const char *extra_thread_info (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; + gdb::byte_vector thread_info_to_thread_handle (struct thread_info *arg0) override; void stop (ptid_t arg0) override; void interrupt () override; void pass_ctrlc () override; @@ -237,6 +238,7 @@ struct debug_target : public target_ops const char *extra_thread_info (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; + gdb::byte_vector thread_info_to_thread_handle (struct thread_info *arg0) override; void stop (ptid_t arg0) override; void interrupt () override; void pass_ctrlc () override; @@ -1854,6 +1856,32 @@ debug_target::thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, infe return result; } +gdb::byte_vector +target_ops::thread_info_to_thread_handle (struct thread_info *arg0) +{ + return this->beneath ()->thread_info_to_thread_handle (arg0); +} + +gdb::byte_vector +dummy_target::thread_info_to_thread_handle (struct thread_info *arg0) +{ + return gdb::byte_vector (); +} + +gdb::byte_vector +debug_target::thread_info_to_thread_handle (struct thread_info *arg0) +{ + gdb::byte_vector result; + fprintf_unfiltered (gdb_stdlog, "-> %s->thread_info_to_thread_handle (...)\n", this->beneath ()->shortname ()); + result = this->beneath ()->thread_info_to_thread_handle (arg0); + fprintf_unfiltered (gdb_stdlog, "<- %s->thread_info_to_thread_handle (", this->beneath ()->shortname ()); + target_debug_print_struct_thread_info_p (arg0); + fputs_unfiltered (") = ", gdb_stdlog); + target_debug_print_gdb_byte_vector (result); + fputs_unfiltered ("\n", gdb_stdlog); + return result; +} + void target_ops::stop (ptid_t arg0) { diff --git a/gdb/target.c b/gdb/target.c index 116510e8cb..8bfedb3619 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2082,6 +2082,12 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle, handle_len, inf); } +gdb::byte_vector +target_thread_info_to_thread_handle (struct thread_info *tip) +{ + return current_top_target ()->thread_info_to_thread_handle (tip); +} + void target_resume (ptid_t ptid, int step, enum gdb_signal signal) { diff --git a/gdb/target.h b/gdb/target.h index c95151a404..4920f00eeb 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -659,6 +659,8 @@ struct target_ops int, inferior *inf) TARGET_DEFAULT_RETURN (NULL); + virtual gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) + TARGET_DEFAULT_RETURN (gdb::byte_vector ()); virtual void stop (ptid_t) TARGET_DEFAULT_IGNORE (); virtual void interrupt () @@ -1851,6 +1853,10 @@ extern const char *target_thread_name (struct thread_info *); extern struct thread_info *target_thread_handle_to_thread_info (const gdb_byte *thread_handle, int handle_len, struct inferior *inf); +/* Given a thread, return the thread handle. */ +extern gdb::byte_vector target_thread_info_to_thread_handle + (struct thread_info *); + /* Attempts to find the pathname of the executable file that was run to create a specified process.