From: Markus Metzger <markus.t.metzger@intel.com>
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 [thread overview]
Message-ID: <1423473902-2286-1-git-send-email-markus.t.metzger@intel.com> (raw)
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 <markus.t.metzger@intel.com>
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
next reply other threads:[~2015-02-09 9:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 9:25 Markus Metzger [this message]
2015-03-02 22:09 ` Pedro Alves
2015-03-03 10:49 ` Metzger, Markus T
2015-03-03 11:55 ` Pedro Alves
2015-03-03 12:25 ` Metzger, Markus T
2015-03-03 13:41 ` Pedro Alves
2015-03-03 13:55 ` Metzger, Markus T
2015-03-03 14:03 ` Pedro Alves
2015-03-03 14:45 ` Metzger, Markus T
2015-03-03 15:25 ` Pedro Alves
2015-03-03 15:37 ` Metzger, Markus T
2015-03-03 15:49 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423473902-2286-1-git-send-email-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox