From patchwork Wed Jan 13 21:45:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 10369 Received: (qmail 51327 invoked by alias); 13 Jan 2016 21:46:33 -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 51052 invoked by uid 89); 13 Jan 2016 21:46:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.6 required=5.0 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=sk:normal_, alloca, 286, 28, 6 X-Spam-User: qpsmtpd, 2 recipients 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; Wed, 13 Jan 2016 21:46:31 +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 9C8ACB99A; Wed, 13 Jan 2016 16:46:28 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH v2 3/6] Display per-thread information for threads in FreeBSD cores. Date: Wed, 13 Jan 2016 13:45:48 -0800 Message-Id: <1452721551-657-4-git-send-email-jhb@FreeBSD.org> In-Reply-To: <1452721551-657-1-git-send-email-jhb@FreeBSD.org> References: <1452721551-657-1-git-send-email-jhb@FreeBSD.org> X-IsSubscribed: yes Display the LWP ID of each thread in a FreeBSD core. Extract thread names from the per-thread THRMISC note. gdb/ChangeLog: * fbsd_tdep.c (fbsd_core_pid_to_str): New function. (fbsd_init_abi): Add "core_pid_to_str" gdbarch method. --- gdb/ChangeLog | 5 +++++ gdb/fbsd-tdep.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 471d02b..93760ba 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2016-01-09 John Baldwin + + * fbsd_tdep.c (fbsd_core_pid_to_str): New function. + (fbsd_init_abi): Add "core_pid_to_str" gdbarch method. + 2016-01-08 Yao Qi * extension.c: Include target.h. diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 0ef94d6..6851cc1 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -28,6 +28,46 @@ #include "fbsd-tdep.h" +/* This is how we want PTIDs from core files to be printed. */ + +static char * +fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) +{ + static char buf[80], name[64]; + struct bfd_section *section; + bfd_size_type size; + char sectionstr[32]; + + if (ptid_get_lwp (ptid) != 0) + { + snprintf (sectionstr, sizeof sectionstr, ".thrmisc/%ld", + ptid_get_lwp (ptid)); + section = bfd_get_section_by_name (core_bfd, sectionstr); + if (section != NULL) + { + char *name; + + size = bfd_section_size (core_bfd, section); + name = alloca (size + 1); + if (bfd_get_section_contents (core_bfd, section, name, (file_ptr) 0, + size) && name[0] != '\0') + { + name[size] = '\0'; + if (strcmp(name, elf_tdata (core_bfd)->core->program) != 0) + { + snprintf (buf, sizeof buf, "LWP %ld \"%s\"", + ptid_get_lwp (ptid), name); + return buf; + } + } + } + snprintf (buf, sizeof buf, "LWP %ld", ptid_get_lwp (ptid)); + return buf; + } + + return normal_pid_to_str (ptid); +} + static int find_signalled_thread (struct thread_info *info, void *data) { @@ -132,5 +172,6 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) void fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { + set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str); set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes); }