This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] btrace: avoid tp != NULL assertion
- From: Markus Metzger <markus dot t dot metzger at intel dot com>
- To: palves at redhat dot com
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 9 Feb 2015 10:25:02 +0100
- Subject: [PATCH] btrace: avoid tp != NULL assertion
- Authentication-results: sourceware.org; auth=none
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