aeaef79
2004-12-07  Jeff Johnston  <jjohnstn@redhat.com>
aeaef79
aeaef79
	* linux-nat.c (find_singlestep_lwp_callback): New function.
aeaef79
	(linux-nat-wait): Before waiting on any pid, check if there
aeaef79
	is a stepping lwp and if so, wait on it specifically.
aeaef79
aeaef79
--- gdb-6.3/gdb/linux-nat.c.fix	Tue Dec  7 19:39:34 2004
aeaef79
+++ gdb-6.3/gdb/linux-nat.c	Tue Dec  7 19:39:46 2004
aeaef79
@@ -1489,9 +1489,21 @@ count_events_callback (struct lwp_info *
aeaef79
   return 0;
aeaef79
 }
aeaef79
 
aeaef79
-/* Select the LWP (if any) that is currently being single-stepped.  */
aeaef79
+/* Find an LWP (if any) that is currently being single-stepped.  */
aeaef79
 
aeaef79
 static int
aeaef79
+find_singlestep_lwp_callback (struct lwp_info *lp, void *data)
aeaef79
+{
aeaef79
+  if (lp->step)
aeaef79
+    return 1;
aeaef79
+  else
aeaef79
+    return 0;
aeaef79
+}
aeaef79
+
aeaef79
+/* Select the LWP with an event (if any) that is currently being 
aeaef79
+   single-stepped.  */
aeaef79
+		 
aeaef79
+static int
aeaef79
 select_singlestep_lwp_callback (struct lwp_info *lp, void *data)
aeaef79
 {
aeaef79
   if (lp->step && lp->status != 0)
aeaef79
@@ -1774,7 +1786,25 @@ retry:
aeaef79
      least if there are any LWPs at all.  */
aeaef79
   gdb_assert (num_lwps == 0 || iterate_over_lwps (resumed_callback, NULL));
aeaef79
 
aeaef79
-  /* First check if there is a LWP with a wait status pending.  */
aeaef79
+  /* Check if there is any LWP that is being single-stepped.  We need to
aeaef79
+     wait specifically on such an LWP because the higher-level code is
aeaef79
+     expecting a step operation to find an event on the stepped LWP.
aeaef79
+     It is possible for other events to occur before the step operation
aeaef79
+     gets the expected trap so we don't want to wait on any LWP.
aeaef79
+     This has ramifications when adjustment of the PC is required which can be
aeaef79
+     different after a breakpoint vs a step (e.g. x86).  */
aeaef79
+  lp = iterate_over_lwps (find_singlestep_lwp_callback, NULL);
aeaef79
+  if (lp) {
95ac1d5
+    if (debug_linux_nat)
aeaef79
+      fprintf_unfiltered (gdb_stdlog,
aeaef79
+                         "LLW: Found step lwp %s.\n",
aeaef79
+                         target_pid_to_str (lp->ptid));
aeaef79
+    ptid = lp->ptid;
aeaef79
+    pid = PIDGET (ptid);
aeaef79
+  }
aeaef79
+
aeaef79
+  /* If any pid, check if there is a LWP with a wait status pending.  */
aeaef79
+
aeaef79
   if (pid == -1)
aeaef79
     {
aeaef79
       /* Any LWP that's been resumed will do.  */