From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15692 invoked by alias); 9 Feb 2015 09:25:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 15673 invoked by uid 89); 9 Feb 2015 09:25:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga09.intel.com Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Feb 2015 09:25:07 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 09 Feb 2015 01:21:23 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 09 Feb 2015 01:17:04 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t199P20g026089; Mon, 9 Feb 2015 09:25:03 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id t199P2Pd002571; Mon, 9 Feb 2015 10:25:02 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id t199P2wR002567; Mon, 9 Feb 2015 10:25:02 +0100 From: Markus Metzger To: palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH] btrace: avoid tp != NULL assertion Date: Mon, 09 Feb 2015 09:25:00 -0000 Message-Id: <1423473902-2286-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2015-02/txt/msg00194.txt.bz2 On some targets, I see the LWP field patched out of INFERIOR_PTID before calling record_btrace_fetch_registers. Looking to the respective linux-nat versions, they use the PID field if the LWP field is zero. Implement a similar behavior for record-btrace. 2015-02-09 Markus Metzger gdb/ * record-btrace.c (record_btrace_inferior_thread): New. (require_btrace_thread, record_btrace_info): (record_btrace_tailcall_frame_sniffer): Call record_btrace_inferior_thread. (record_btrace_fetch_registers, record_btrace_frame_sniffer): Call record_btrace_inferior_thread. Replace tp != NULL assertion with error call. --- gdb/record-btrace.c | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 102e0eb..b7dedd9 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -97,6 +97,35 @@ static struct cmd_list_element *show_record_btrace_bts_cmdlist; while (0) +/* Return a pointer to the thread_info of inferior_ptid. + + In some cases, we see the LWP field of INFERIOR_PTID patched out. Use the + PID as LWP similar to what i386|amd64_linux_fetch_inferior_registers do. */ + +static struct thread_info * +record_btrace_inferior_thread (void) +{ + ptid_t ptid; + long lwp; + + DEBUG ("inferior thread"); + + ptid = inferior_ptid; + + /* GNU/Linux LWP ID's are process ID's. */ + lwp = ptid_get_lwp (ptid); + if (lwp == 0) + { + int pid; + + /* Not a threaded program. Use the PID as LWP ID. */ + pid = ptid_get_pid (ptid); + ptid = ptid_build (pid, pid, 0); + } + + return find_thread_ptid (ptid); +} + /* Update the branch trace for the current thread and return a pointer to its thread_info. @@ -110,7 +139,7 @@ require_btrace_thread (void) DEBUG ("require"); - tp = find_thread_ptid (inferior_ptid); + tp = record_btrace_inferior_thread (); if (tp == NULL) error (_("No thread.")); @@ -370,7 +399,7 @@ record_btrace_info (struct target_ops *self) DEBUG ("info"); - tp = find_thread_ptid (inferior_ptid); + tp = record_btrace_inferior_thread (); if (tp == NULL) error (_("No thread.")); @@ -1163,8 +1192,9 @@ record_btrace_fetch_registers (struct target_ops *ops, struct btrace_insn_iterator *replay; struct thread_info *tp; - tp = find_thread_ptid (inferior_ptid); - gdb_assert (tp != NULL); + tp = record_btrace_inferior_thread (); + if (tp == NULL) + error (_("No thread.")); replay = tp->btrace.replay; if (replay != NULL && !record_btrace_generating_corefile) @@ -1414,8 +1444,9 @@ record_btrace_frame_sniffer (const struct frame_unwind *self, struct frame_info *next; /* THIS_FRAME does not contain a reference to its thread. */ - tp = find_thread_ptid (inferior_ptid); - gdb_assert (tp != NULL); + tp = record_btrace_inferior_thread (); + if (tp == NULL) + error (_("No thread.")); bfun = NULL; next = get_next_frame (this_frame); @@ -1482,7 +1513,7 @@ record_btrace_tailcall_frame_sniffer (const struct frame_unwind *self, /* This is our frame. Initialize the frame cache. */ cache = bfcache_new (this_frame); - cache->tp = find_thread_ptid (inferior_ptid); + cache->tp = record_btrace_inferior_thread (); cache->bfun = bfun; *this_cache = cache; -- 1.8.3.1