[PATCH 2/8] Delete reinsert breakpoints from forked child

Yao Qi
2016-05-20T15:13:07Z

When a thread is stepping over a syscall instruction with software
single step, GDBserver inserts reinsert breakpoints at the next pcs.
If the syscall call is fork, the forked child has reinsert breakpoint
in its space, and GDBserver clones parent's breakpoint list to child's.
When GDBserver resumes the child, it hits the reinsert breakpoint. Since
it is a GDBserver internal breakpoint, GDBserver will do step-over again,
and remove this reinsert breakpoint on step-over is finished, so the
reinsert breakpoint left in the child process doesn't make any trouble.
However, GDBserver still need to remove the reinsert breakpoints from
the child, in order to avoid the unnecessary breakpoint hit and
step-over.

gdb/gdbserver:

2016-05-20 Yao Qi <yao.qi@linaro.org>

* linux-low.c (handle_extended_wait): If the parent is doing
step-over, remove the reinsert breakpoints from the child.
---
gdb/gdbserver/linux-low.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 8e8f710..a63cc7a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -568,6 +568,25 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
event_lwp->status_pending_p = 1;
event_lwp->status_pending = wstat;

+ /* If the parent thread is doing step-over with reinsert
+ breakpoints, the reinsert breakpoints are still in child's
+ process space and cloned to its breakpoint list from the
+ parent's. Remove them. */
+ if (event_lwp->bp_reinsert != 0 && can_software_single_step ())
+ {
+ struct thread_info *saved_thread = current_thread;
+
+ /* The child process is forked and stopped, so it is safe
+ to access its memory without stopping all other threads
+ from other processes. */
+ current_thread = child_thr;
+ delete_reinsert_breakpoints ();
+ current_thread = saved_thread;
+
+ gdb_assert (has_reinsert_breakpoints (parent_proc));
+ gdb_assert (!has_reinsert_breakpoints (child_proc));
+ }
+
/* Report the event. */
return 0;
}
--
1.9.1