--- 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. */