This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/2] Avoid step-over infinite loop in GDBServer
- From: Antoine Tremblay <antoine dot tremblay at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: Antoine Tremblay <antoine dot tremblay at ericsson dot com>
- Date: Tue, 29 Nov 2016 07:07:02 -0500
- Subject: [PATCH 2/2] Avoid step-over infinite loop in GDBServer
- Authentication-results: sourceware.org; auth=none
- References: <20161129120702.9490-1-antoine.tremblay@ericsson.com>
Before this patch, GDBServer always executed a step-over if it found a
thread that needed one.
This could be a problem in a situation exposed by non-stop-fair-events.exp
where the code and the breakpoint placement is like so:
instruction A : has a single-step breakpoint installed for thread 1 and 2
instruction B : has a single-step breakpoint installed for thread 3
and is a branch to A.
In this particular case:
- GDBServer stops on instruction A in thread 1.
- Deletes thread 1 single-step breakpoint.
- Starts a step-over of thread 1 to step-over the thread 2 breakpoint.
- GDBServer finishes a step-over and is at instruction B.
- GDBserver starts a step-over of thread 1 to step-over the thread 3
breakpoint at instruction B.
- GDBServer stops on instuction A in thread 1.
- GDBServer is now in an infinite loop.
This patch avoids this issue by counting the number of times a thread does
a step-over consecutively. If the thread reaches a threshold, which is
currently 32, GDBServer will not step-over but rather restart all the
threads.
I chose a threshold of 32, so to trigger this there needs to be 32
consecutive instructions with breakpoints installed that one thread needs
to step over. I think this should be rare enought to trigger only in this
case but suggestions on the threshold value are welcome.
If the threshold is hit and the step-over is delayed, when the thread
that needed a step-over runs it will simply hit the breakpoint it needed
to step-over and retry to start a step-over.
This makes it possible for other threads to run and start a step-over
dance of their own or pending events like signals to be handled.
This patch fixes the intermittent FAILs for
gdb.threads/non-stop-fair-events.exp on ARM like discussed here:
https://sourceware.org/ml/gdb-patches/2016-11/msg00132.html
No regressions, tested on ubuntu 14.04 ARMv7.
With gdbserver-native/-m{arm,thumb}
gdb/gdbserver/ChangeLog:
* linux-low.c (class step_over_limiter): New class.
(_step_over_limiter): New global variable.
(linux_wait_1): Count step-overs.
(proceed_all_lwps): Delay step-over if threshold is reached.
---
gdb/gdbserver/linux-low.c | 76 +++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 70 insertions(+), 6 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 15fb726..b84b62a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -282,6 +282,53 @@ static int proceed_one_lwp (struct inferior_list_entry *entry, void *except);
being stepped. */
ptid_t step_over_bkpt;
+/* Class limiting the number of consecutive step-overs for a thread. */
+
+class step_over_limiter
+{
+ public:
+
+ step_over_limiter () : m_ptid (null_ptid), m_count (0), m_max_count (32) {}
+
+ void step_over_done (struct lwp_info *lwp)
+ {
+ ptid_t ptid = lwp->thread->entry.id;
+
+ if (!ptid_equal (ptid, m_ptid))
+ {
+ m_ptid = ptid;
+ m_count = 0;
+ }
+
+ m_count++;
+ }
+
+ bool can_step_over (struct lwp_info *lwp)
+ {
+ if (!ptid_equal(lwp->thread->entry.id, m_ptid)
+ || m_count < m_max_count)
+ return true;
+ else
+ {
+ /* Reset here so that the step_over is retried. */
+ m_ptid = null_ptid;
+ m_count = 0;
+ return false;
+ }
+ }
+
+ private:
+
+ ptid_t m_ptid;
+ int m_count;
+
+ /* Maximum step overs for a thread, before all threads are run instead of
+ stepping over. */
+ const int m_max_count;
+};
+
+step_over_limiter _step_over_limiter;
+
/* True if the low target can hardware single-step. */
static int
@@ -3607,6 +3654,8 @@ linux_wait_1 (ptid_t ptid,
doesn't lose it. */
enqueue_pending_signal (event_child, WSTOPSIG (w), info_p);
+ _step_over_limiter.step_over_done (event_child);
+
proceed_all_lwps ();
}
else
@@ -3694,6 +3743,8 @@ linux_wait_1 (ptid_t ptid,
We're going to keep waiting, so use proceed, which
handles stepping over the next breakpoint. */
unsuspend_all_lwps (event_child);
+
+ _step_over_limiter.step_over_done (event_child);
}
else
{
@@ -5400,13 +5451,26 @@ proceed_all_lwps (void)
if (need_step_over != NULL)
{
- if (debug_threads)
- debug_printf ("proceed_all_lwps: found "
- "thread %ld needing a step-over\n",
- lwpid_of (need_step_over));
+ /* Don't step over if we're looping too much. */
+ if (_step_over_limiter.can_step_over
+ (get_thread_lwp (need_step_over)))
+ {
+ if (debug_threads)
+ debug_printf ("proceed_all_lwps: found "
+ "thread %ld needing a step-over\n",
+ lwpid_of (need_step_over));
- start_step_over (get_thread_lwp (need_step_over));
- return;
+ start_step_over (get_thread_lwp (need_step_over));
+ return;
+ }
+ else
+ {
+ if (debug_threads)
+ debug_printf ("proceed_all_lwps: found "
+ "thread %ld needing a step-over "
+ "but max consecutive step-overs reached\n",
+ lwpid_of (need_step_over));
+ }
}
}
--
2.9.2