This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
support waiting for any thread of a specific process, in the remote target
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 24 Feb 2010 17:09:53 +0000
- Subject: support waiting for any thread of a specific process, in the remote target
I've applied this patch below.
remote.c's implementation of target_wait didn't allow
waiting for any thread of a specific process correctly.
The problem is in queued_stop_reply. Another patch I'll
push afterwards revealed this problem, but I think it's
better to keep this bit separate. I'm moving ptid_match
out of linux-nat.c into common code with a couple of
tweaks, to be able to use it in remote.c as well.
--
Pedro Alves
2010-02-24 Pedro Alves <pedro@codesourcery.com>
* inferior.h (ptid_match): Declare.
* infrun.c (ptid_match): New.
* remote.c (queued_stop_reply): Rewrite and use ptid_match.
(handle_notification): Add debug output.
* linux-nat.c (ptid_match): Delete.
---
gdb/inferior.h | 10 ++++++++++
gdb/infrun.c | 20 ++++++++++++++++++++
gdb/linux-nat.c | 27 ---------------------------
gdb/remote.c | 45 ++++++++++++++++++++++++---------------------
4 files changed, 54 insertions(+), 48 deletions(-)
Index: src/gdb/inferior.h
===================================================================
--- src.orig/gdb/inferior.h 2010-02-24 16:08:19.000000000 +0000
+++ src/gdb/inferior.h 2010-02-24 16:10:29.000000000 +0000
@@ -105,6 +105,16 @@ extern int ptid_equal (ptid_t p1, ptid_t
/* Return true if PTID represents a process id. */
extern int ptid_is_pid (ptid_t ptid);
+/* Returns true if PTID matches filter FILTER. FILTER can be the wild
+ card MINUS_ONE_PTID (all ptid match it); can be a ptid representing
+ a process (ptid_is_pid returns true), in which case, all lwps and
+ threads of that given process match, lwps and threads of other
+ processes do not; or, it can represent a specific thread, in which
+ case, only that thread will match true. PTID must represent a
+ specific LWP or THREAD, it can never be a wild card. */
+
+extern int ptid_match (ptid_t ptid, ptid_t filter);
+
/* Save value of inferior_ptid so that it may be restored by
a later call to do_cleanups(). Returns the struct cleanup
pointer needed for later doing the cleanup. */
Index: src/gdb/infrun.c
===================================================================
--- src.orig/gdb/infrun.c 2010-02-24 16:08:19.000000000 +0000
+++ src/gdb/infrun.c 2010-02-24 16:28:12.000000000 +0000
@@ -6126,6 +6126,26 @@ ptid_is_pid (ptid_t ptid)
return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
}
+int
+ptid_match (ptid_t ptid, ptid_t filter)
+{
+ /* Since both parameters have the same type, prevent easy mistakes
+ from happening. */
+ gdb_assert (!ptid_equal (ptid, minus_one_ptid)
+ && !ptid_equal (ptid, null_ptid)
+ && !ptid_is_pid (ptid));
+
+ if (ptid_equal (filter, minus_one_ptid))
+ return 1;
+ if (ptid_is_pid (filter)
+ && ptid_get_pid (ptid) == ptid_get_pid (filter))
+ return 1;
+ else if (ptid_equal (ptid, filter))
+ return 1;
+
+ return 0;
+}
+
/* restore_inferior_ptid() will be used by the cleanup machinery
to restore the inferior_ptid value saved in a call to
save_inferior_ptid(). */
Index: src/gdb/remote.c
===================================================================
--- src.orig/gdb/remote.c 2010-02-24 16:08:19.000000000 +0000
+++ src/gdb/remote.c 2010-02-24 16:39:57.000000000 +0000
@@ -4637,26 +4637,23 @@ do_stop_reply_xfree (void *arg)
static struct stop_reply *
queued_stop_reply (ptid_t ptid)
{
- struct stop_reply *it, *prev;
- struct stop_reply head;
-
- head.next = stop_reply_queue;
- prev = &head;
-
- it = head.next;
-
- if (!ptid_equal (ptid, minus_one_ptid))
- for (; it; prev = it, it = it->next)
- if (ptid_equal (ptid, it->ptid))
- break;
+ struct stop_reply *it;
+ struct stop_reply **it_link;
- if (it)
+ it = stop_reply_queue;
+ it_link = &stop_reply_queue;
+ while (it)
{
- prev->next = it->next;
- it->next = NULL;
- }
+ if (ptid_match (it->ptid, ptid))
+ {
+ *it_link = it->next;
+ it->next = NULL;
+ break;
+ }
- stop_reply_queue = head.next;
+ it_link = &it->next;
+ it = *it_link;
+ }
if (stop_reply_queue)
/* There's still at least an event left. */
@@ -6169,10 +6166,13 @@ handle_notification (char *buf, size_t l
if (strncmp (buf, "Stop:", 5) == 0)
{
if (pending_stop_reply)
- /* We've already parsed the in-flight stop-reply, but the stub
- for some reason thought we didn't, possibly due to timeout
- on its side. Just ignore it. */
- ;
+ {
+ /* We've already parsed the in-flight stop-reply, but the
+ stub for some reason thought we didn't, possibly due to
+ timeout on its side. Just ignore it. */
+ if (remote_debug)
+ fprintf_unfiltered (gdb_stdlog, "ignoring resent notification\n");
+ }
else
{
struct cleanup *old_chain;
@@ -6190,6 +6190,9 @@ handle_notification (char *buf, size_t l
/* Notify the event loop there's a stop reply to acknowledge
and that there may be more events to fetch. */
mark_async_event_handler (remote_async_get_pending_events_token);
+
+ if (remote_debug)
+ fprintf_unfiltered (gdb_stdlog, "stop notification captured\n");
}
}
else
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2010-02-24 16:30:20.000000000 +0000
+++ src/gdb/linux-nat.c 2010-02-24 16:30:25.000000000 +0000
@@ -1221,33 +1221,6 @@ find_lwp_pid (ptid_t ptid)
return NULL;
}
-/* Returns true if PTID matches filter FILTER. FILTER can be the wild
- card MINUS_ONE_PTID (all ptid match it); can be a ptid representing
- a process (ptid_is_pid returns true), in which case, all lwps of
- that give process match, lwps of other process do not; or, it can
- represent a specific thread, in which case, only that thread will
- match true. PTID must represent an LWP, it can never be a wild
- card. */
-
-static int
-ptid_match (ptid_t ptid, ptid_t filter)
-{
- /* Since both parameters have the same type, prevent easy mistakes
- from happening. */
- gdb_assert (!ptid_equal (ptid, minus_one_ptid)
- && !ptid_equal (ptid, null_ptid));
-
- if (ptid_equal (filter, minus_one_ptid))
- return 1;
- if (ptid_is_pid (filter)
- && ptid_get_pid (ptid) == ptid_get_pid (filter))
- return 1;
- else if (ptid_equal (ptid, filter))
- return 1;
-
- return 0;
-}
-
/* Call CALLBACK with its second argument set to DATA for every LWP in
the list. If CALLBACK returns 1 for a particular LWP, return a
pointer to the structure describing that LWP immediately.