From patchwork Mon Jan 18 18:37:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 10428 Received: (qmail 537 invoked by alias); 18 Jan 2016 18:38:32 -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 457 invoked by uid 89); 18 Jan 2016 18:38:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.5 required=5.0 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=270, 2.7.0, thread_info, sk:elf_int X-HELO: bigwig.baldwin.cx Received: from bigwig.baldwin.cx (HELO bigwig.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 18 Jan 2016 18:38:29 +0000 Received: from ralph.com (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 1A7C6B9B2 for ; Mon, 18 Jan 2016 13:38:27 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v4 3/7] Add support for extracting thread names from cores. Date: Mon, 18 Jan 2016 10:37:30 -0800 Message-Id: <1453142254-20266-4-git-send-email-jhb@FreeBSD.org> In-Reply-To: <1453142254-20266-1-git-send-email-jhb@FreeBSD.org> References: <1453142254-20266-1-git-send-email-jhb@FreeBSD.org> X-IsSubscribed: yes Add a new gdbarch method to extract a thread name from a core for a given thread. Use this new method in core_thread_name to implement the to_thread_name target op. gdb/ChangeLog: * corelow.c (core_thread_name): New function. (init_core_ops): Use "core_thread_name" for the "to_thread_name" target op. * gdbarch.sh (core_thread_name): New gdbarch callback. * gdbarch.h: Re-generate. * gdbarch.c: Re-generate. --- gdb/ChangeLog | 9 +++++++++ gdb/corelow.c | 10 ++++++++++ gdb/gdbarch.c | 32 ++++++++++++++++++++++++++++++++ gdb/gdbarch.h | 9 +++++++++ gdb/gdbarch.sh | 4 ++++ 5 files changed, 64 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fe8fd6c..bbac503 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2016-01-16 John Baldwin + + * corelow.c (core_thread_name): New function. + (init_core_ops): Use "core_thread_name" for the "to_thread_name" + target op. + * gdbarch.sh (core_thread_name): New gdbarch callback. + * gdbarch.h: Re-generate. + * gdbarch.c: Re-generate. + 2016-01-15 Sandra Loosemore * charset.c [PHONY_ICONV] (GDB_DEFAULT_HOST_CHARSET): diff --git a/gdb/corelow.c b/gdb/corelow.c index 90e3d56..224719e 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -986,6 +986,15 @@ core_pid_to_str (struct target_ops *ops, ptid_t ptid) return buf; } +static const char * +core_thread_name (struct target_ops *self, struct thread_info *thr) +{ + if (core_gdbarch + && gdbarch_core_thread_name_p (core_gdbarch)) + return gdbarch_core_thread_name (core_gdbarch, thr); + return NULL; +} + static int core_has_memory (struct target_ops *ops) { @@ -1038,6 +1047,7 @@ init_core_ops (void) core_ops.to_thread_alive = core_thread_alive; core_ops.to_read_description = core_read_description; core_ops.to_pid_to_str = core_pid_to_str; + core_ops.to_thread_name = core_thread_name; core_ops.to_stratum = process_stratum; core_ops.to_has_memory = core_has_memory; core_ops.to_has_stack = core_has_stack; diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index d45af1a..4143744 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -269,6 +269,7 @@ struct gdbarch gdbarch_core_xfer_shared_libraries_ftype *core_xfer_shared_libraries; gdbarch_core_xfer_shared_libraries_aix_ftype *core_xfer_shared_libraries_aix; gdbarch_core_pid_to_str_ftype *core_pid_to_str; + gdbarch_core_thread_name_ftype *core_thread_name; const char * gcore_bfd_target; int vtable_function_descriptors; int vbit_in_delta; @@ -612,6 +613,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of core_xfer_shared_libraries, has predicate. */ /* Skip verify of core_xfer_shared_libraries_aix, has predicate. */ /* Skip verify of core_pid_to_str, has predicate. */ + /* Skip verify of core_thread_name, has predicate. */ /* Skip verify of gcore_bfd_target, has predicate. */ /* Skip verify of vtable_function_descriptors, invalid_p == 0 */ /* Skip verify of vbit_in_delta, invalid_p == 0 */ @@ -824,6 +826,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: core_read_description = <%s>\n", host_address_to_string (gdbarch->core_read_description)); fprintf_unfiltered (file, + "gdbarch_dump: gdbarch_core_thread_name_p() = %d\n", + gdbarch_core_thread_name_p (gdbarch)); + fprintf_unfiltered (file, + "gdbarch_dump: core_thread_name = <%s>\n", + host_address_to_string (gdbarch->core_thread_name)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_core_xfer_shared_libraries_p() = %d\n", gdbarch_core_xfer_shared_libraries_p (gdbarch)); fprintf_unfiltered (file, @@ -3554,6 +3562,30 @@ set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, } int +gdbarch_core_thread_name_p (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + return gdbarch->core_thread_name != NULL; +} + +const char * +gdbarch_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->core_thread_name != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_core_thread_name called\n"); + return gdbarch->core_thread_name (gdbarch, thr); +} + +void +set_gdbarch_core_thread_name (struct gdbarch *gdbarch, + gdbarch_core_thread_name_ftype core_thread_name) +{ + gdbarch->core_thread_name = core_thread_name; +} + +int gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 3c16af2..3fadcd1 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -63,6 +63,7 @@ struct ravenscar_arch_ops; struct elf_internal_linux_prpsinfo; struct mem_range; struct syscalls_info; +struct thread_info; #include "regcache.h" @@ -866,6 +867,14 @@ typedef char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t extern char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str); +/* How the core target extracts the name of a thread from a core file. */ + +extern int gdbarch_core_thread_name_p (struct gdbarch *gdbarch); + +typedef const char * (gdbarch_core_thread_name_ftype) (struct gdbarch *gdbarch, struct thread_info *thr); +extern const char * gdbarch_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr); +extern void set_gdbarch_core_thread_name (struct gdbarch *gdbarch, gdbarch_core_thread_name_ftype *core_thread_name); + /* BFD target to use when generating a core file. */ extern int gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch); diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index f80cd51..4ac6b90 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -721,6 +721,9 @@ M:ULONGEST:core_xfer_shared_libraries_aix:gdb_byte *readbuf, ULONGEST offset, UL # How the core target converts a PTID from a core file to a string. M:char *:core_pid_to_str:ptid_t ptid:ptid +# How the core target extracts the name of a thread from a core file. +M:const char *:core_thread_name:struct thread_info *thr:thr + # BFD target to use when generating a core file. V:const char *:gcore_bfd_target:::0:0:::pstring (gdbarch->gcore_bfd_target) @@ -1247,6 +1250,7 @@ struct ravenscar_arch_ops; struct elf_internal_linux_prpsinfo; struct mem_range; struct syscalls_info; +struct thread_info; #include "regcache.h"