This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix software-single-step in multi-threaded applications


The schedlock.exp test has been failing on ARM GNU/Linux for a while.
The timeouts nearly double the length of my test run, so I finally sat
down to investigate it.

The symptom was a "next" that never returned.  We'd be stopped in
the thread function, which is running in both threads, and try to
single-step the second thread.  Both threads would be allowed to run,
and alternate hitting the single-step breakpoint (and actually going
around the loop, making progress, without GDB ever noticing).

Here's a sample of the infrun log when we step Thread 3916:

infrun: resume (step=1, signal=0), trap_expected=0
infrun: target_wait (-1, status) =
infrun:   42000 [Thread 3915],
infrun:   status->kind = stopped, signal = SIGTRAP
infrun: infwait_normal_state
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x8666
infrun: software single step trap for Thread 3915
infrun: unexpected thread
infrun: thread_hop_needed
infrun: Switching context from Thread 3916 to Thread 3915
infrun: resume (step=1, signal=0), trap_expected=1
infrun: target_wait (42000 [Thread 3915], status) =
infrun:   42000 [Thread 3915],
infrun:   status->kind = stopped, signal = SIGTRAP
infrun: infwait_thread_hop_state
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x8668
infrun: stepping_past_singlestep_breakpoint
infrun: Switching context from Thread 3915 to Thread 3916
infrun: resume (step=1, signal=0), trap_expected=0
infrun: target_wait (-1, status) =
infrun:   42000 [Thread 3915],
infrun:   status->kind = stopped, signal = SIGTRAP
infrun: infwait_normal_state
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x8666
infrun: software single step trap for Thread 3915
infrun: unexpected thread, but expected thread advanced also
infrun: switching back to stepped thread
infrun: Switching context from Thread 3916 to Thread 3915
infrun: resume (step=1, signal=0), trap_expected=1

And then it repeats.  The interesting bit is near the end, where we
switch back to thread 3915 and step it - even though we've noticed
that thread 3916 has finished!  After much staring at logs, Pedro
pointed me to the key, which is the "trap_expected=1" in that last
resume.

Ulrich Weigand added some code last year to correctly handle "step"
when some other thread hits an internal event, like a shared library
breakpoint.  That code searches for a non-current thread which is also
in the middle of stepping.  In this case, it found that 3915 appeared
to be still in the middle of a step (why else would we be expecting a
trap from it?) and helpfully resumed that step.

The problem was earlier in the function and had been there for a long
time.  We didn't clear trap_expected after finishing the singlestep
breakpoint equivalent of a thread hop.  Since we didn't clean up that
flag, later code would always think 3915 was being stepped.

This patch fixes the problem.  Tested on ARM GNU/Linux and committed.
Thanks Pedro!

-- 
Daniel Jacobowitz
CodeSourcery

2009-07-28  Daniel Jacobowitz  <dan@codesourcery.com>
	    Pedro Alves  <pedro@codesourcery.com>

	* infrun.c (handle_inferior_event): Clear trap_expected after
	stepping past a single-step breakpoint.

---
 gdb/infrun.c |    1 +
 1 file changed, 1 insertion(+)

Index: gdb-mainline/gdb/infrun.c
===================================================================
--- gdb-mainline.orig/gdb/infrun.c	2009-07-20 08:05:12.000000000 -0700
+++ gdb-mainline/gdb/infrun.c	2009-07-27 14:01:09.000000000 -0700
@@ -2813,6 +2813,7 @@ targets should add new threads to the th
 	  singlestep_breakpoints_inserted_p = 0;
 
 	  ecs->random_signal = 0;
+	  ecs->event_thread->trap_expected = 0;
 
 	  context_switch (saved_singlestep_ptid);
 	  if (deprecated_context_hook)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]