From: Antoine Tremblay <antoine.tremblay@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Antoine Tremblay <antoine.tremblay@ericsson.com>
Subject: [PATCH 2/2] Avoid step-over infinite loop in GDBServer
Date: Tue, 29 Nov 2016 12:07:00 -0000 [thread overview]
Message-ID: <20161129120702.9490-2-antoine.tremblay@ericsson.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2016-11-29 12:07 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-29 12:07 [PATCH 1/2] This patch fixes GDBServer's run control for single stepping Antoine Tremblay
2016-11-29 12:07 ` Antoine Tremblay [this message]
2017-01-16 17:27 ` [PATCH 2/2] Avoid step-over infinite loop in GDBServer Antoine Tremblay
2017-01-18 16:31 ` Antoine Tremblay
2017-02-03 16:21 ` Pedro Alves
2017-02-17 3:39 ` Antoine Tremblay
2017-02-22 10:15 ` Yao Qi
2017-03-27 13:28 ` Antoine Tremblay
2016-11-29 12:12 ` [PATCH 1/2] This patch fixes GDBServer's run control for single stepping Antoine Tremblay
2017-01-16 17:28 ` Antoine Tremblay
2017-01-27 15:01 ` Yao Qi
2017-01-27 16:07 ` Antoine Tremblay
2017-01-27 17:01 ` Yao Qi
2017-01-27 18:24 ` Antoine Tremblay
2017-01-29 21:41 ` Yao Qi
2017-01-30 13:29 ` Antoine Tremblay
2017-02-03 16:13 ` Pedro Alves
2017-02-17 1:42 ` Antoine Tremblay
2017-02-17 2:05 ` Pedro Alves
2017-02-17 3:06 ` Antoine Tremblay
2017-02-17 22:19 ` Yao Qi
2017-02-18 0:19 ` Antoine Tremblay
2017-02-18 22:49 ` Yao Qi
2017-02-19 19:40 ` Antoine Tremblay
2017-02-19 20:31 ` Antoine Tremblay
2017-03-29 12:41 ` Antoine Tremblay
2017-03-29 14:11 ` Antoine Tremblay
2017-03-29 17:54 ` Antoine Tremblay
2017-03-30 16:06 ` Yao Qi
2017-03-30 18:31 ` Antoine Tremblay
2017-03-31 16:31 ` Yao Qi
2017-03-31 18:22 ` Antoine Tremblay
2017-04-03 12:41 ` Yao Qi
2017-04-03 13:18 ` Antoine Tremblay
2017-04-03 15:18 ` Yao Qi
2017-04-03 16:57 ` Antoine Tremblay
2017-02-16 22:32 ` Yao Qi
2017-02-17 2:17 ` Antoine Tremblay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161129120702.9490-2-antoine.tremblay@ericsson.com \
--to=antoine.tremblay@ericsson.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).