Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC]: Ugly thread step situation
@ 2004-09-14 21:44 jjohnstn
  2004-09-14 22:42 ` Andrew Cagney
  2004-09-14 23:25 ` Daniel Jacobowitz
  0 siblings, 2 replies; 7+ messages in thread
From: jjohnstn @ 2004-09-14 21:44 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1713 bytes --]

I recently tracked down a problem with gdb on RHEL3 Linux regarding 
stepping threads.  What happens is that in some instances, lin-lwp.c is 
asked to step the thread of interest.  We then wait on all threads.  Due 
to some form of race condition, the wait does not get back the trap from 
the stepped thread.  If we have a number of waiting events (e.g. thread 
create events, other breakpoints), lin-lwp picks one of them.

Now it gets interesting.  Infrun.c thinks the current thread is being 
stepped and isn't ready for a breakpoint coming back.  On x86, it makes a 
miscalculation of the pc value (for a breakpoint it should back up 1, for 
a step it doesn't have to).  We end up pointing at an invalid pc (we 
didn't back up 1) and everything falls apart from there.

To fix this quickly, I added the accompanying patch to lin-lwp.c.  What it 
does is ensure that we wait on any currently stepping lwp.  In truth, this 
isn't as bad as it sounds.  The lin-lwp code later on is set up to pick 
the stepping lwp over all other events.  This just keeps the scenario 
above from occurring.

Obviously, this doesn't solve everything.  Perhaps the decrement of the pc 
needs to be done once we have established whether the thread has changed 
underneath us.  We also could use a hook to run the lwp list and find out 
if the current lwp was stepping or encountered a breakpoint.

Anyway, if the consensus is that the patch is helpful in the short-term, I 
am more than happy to check it in.

-- Jeff J.

2004-09-14  Jeff Johnston  <jjohnstn@redhat.com>

	* lin-lwp.c (find_singlestep_lwp_callback): New static function.
	(lin_lwp_wait): Change code to specifically wait on any LWP
	that is currently stepping.



[-- Attachment #2: Type: TEXT/PLAIN, Size: 1848 bytes --]

--- gdb+dejagnu-20040607/gdb/lin-lwp.c.fix	Thu Sep  2 11:20:07 2004
+++ gdb+dejagnu-20040607/gdb/lin-lwp.c	Thu Sep  2 11:27:32 2004
@@ -1004,7 +1004,18 @@ count_events_callback (struct lwp_info *
   return 0;
 }
 
-/* Select the LWP (if any) that is currently being single-stepped.  */
+/* Find an LWP (if any) that is currently being single-stepped.  */
+
+static int
+find_singlestep_lwp_callback (struct lwp_info *lp, void *data)
+{
+  if (lp->step)
+    return 1;
+  else
+    return 0;
+}
+
+/* Select the LWP with an event (if any) that is currently being single-stepped.  */
 
 static int
 select_singlestep_lwp_callback (struct lwp_info *lp, void *data)
@@ -1289,7 +1300,24 @@ retry:
      least if there are any LWPs at all.  */
   gdb_assert (num_lwps == 0 || iterate_over_lwps (resumed_callback, NULL));
 
-  /* First check if there is a LWP with a wait status pending.  */
+  /* Check if there is any LWP that is being single-stepped.  We need to
+     wait specifically on such an LWP because the higher-level code is
+     expecting a step operation to find an event on the stepped LWP.
+     It is possible for other events to occur before the step operation
+     gets the expected trap so we don't want to wait on any LWP.
+     This has ramifications when adjustment of the PC is required which can be 
+     different after a breakpoint vs a step (e.g. x86).  */
+  lp = iterate_over_lwps (find_singlestep_lwp_callback, NULL);
+  if (lp) {
+    if (debug_lin_lwp)
+      fprintf_unfiltered (gdb_stdlog,
+ 			  "LLW: Found step lwp %s.\n",
+			  target_pid_to_str (lp->ptid));
+    ptid = lp->ptid;
+    pid = PIDGET (ptid);
+  }
+
+  /* If any pid, check if there is a LWP with a wait status pending.  */
   if (pid == -1)
     {
       /* Any LWP that's been resumed will do.  */

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-09-15 18:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-14 21:44 [RFC]: Ugly thread step situation jjohnstn
2004-09-14 22:42 ` Andrew Cagney
2004-09-14 23:25 ` Daniel Jacobowitz
2004-09-15 17:36   ` Jeff Johnston
2004-09-15 17:53     ` Andrew Cagney
2004-09-15 17:59       ` Jeff Johnston
2004-09-15 18:21     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox