From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/12] Step over exit with reinsert breakpoints
Date: Thu, 02 Jun 2016 09:31:00 -0000 [thread overview]
Message-ID: <1464859846-15619-4-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1464859846-15619-1-git-send-email-yao.qi@linaro.org>
This patch fixes a GDBserver crash when one thread is stepping over
a syscall instruction which is exit. Step-over isn't finished due
to the exit, but GDBserver doesn't clean up the state of step-over,
so in the wait next time, GDBserver will wait on step_over_bkpt,
which is already exited, and GDBserver crashes because
'requested_child' is NULL. See gdbserver logs below,
Need step over [LWP 14858]? yes, found breakpoint at 0x2aaaaad91307^M
proceed_all_lwps: found thread 14858 needing a step-over^M
Starting step-over on LWP 14858. Stopping all threads^M
>>>> entering void stop_all_lwps(int, lwp_info*)
....
<<<< exiting void stop_all_lwps(int, lwp_info*)^M
Done stopping all threads for step-over.^M
pc is 0x2aaaaad91307^M
Writing 0f to 0x2aaaaad91307 in process 14858^M
Could not find fast tracepoint jump at 0x2aaaaad91307 in list (uninserting).^M
pending reinsert at 0x2aaaaad91307^M
step from pc 0x2aaaaad91307^M
Resuming lwp 14858 (step, signal 0, stop not expected)^M
# Start step-over for LWP 14858
>>>> entering ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)
....
LLFE: 14858 exited.
...
<<<< exiting ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)
# LWP 14858 exited
.....
>>>> entering ptid_t linux_wait_1(ptid_t, target_waitstatus*, int)^M
linux_wait_1: [<all threads>]^M
step_over_bkpt set [LWP 14858.14858], doing a blocking wait
# but step_over_bkpt is still LWP 14858, which is wrong
The fix is to finish step-over if it is ongoing, and unsuspend other
threads. Without the fix in linux-low.c, GDBserver will crash in
with running gdb.base/step-over-exit.exp.
gdb/gdbserver:
2016-05-26 Yao Qi <yao.qi@linaro.org>
* linux-low.c (unsuspend_all_lwps): Declare.
(linux_low_filter_event): If thread exited, call finish_step_over.
If step-over is finished, unsuspend other threads.
gdb/testsuite:
2016-05-26 Yao Qi <yao.qi@linaro.org>
* gdb.base/step-over-exit.c: New.
* gdb.base/step-over-exit.exp: New.
---
gdb/gdbserver/linux-low.c | 8 ++
gdb/testsuite/gdb.base/step-over-exit.c | 50 ++++++++++++
gdb/testsuite/gdb.base/step-over-exit.exp | 127 ++++++++++++++++++++++++++++++
3 files changed, 185 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/step-over-exit.c
create mode 100644 gdb/testsuite/gdb.base/step-over-exit.exp
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 5f025b5..95104d2 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -252,6 +252,7 @@ static void linux_resume_one_lwp (struct lwp_info *lwp,
static void linux_resume (struct thread_resume *resume_info, size_t n);
static void stop_all_lwps (int suspend, struct lwp_info *except);
static void unstop_all_lwps (int unsuspend, struct lwp_info *except);
+static void unsuspend_all_lwps (struct lwp_info *except);
static int linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
int *wstat, int options);
static int linux_wait_for_event (ptid_t ptid, int *wstat, int options);
@@ -2357,6 +2358,13 @@ linux_low_filter_event (int lwpid, int wstat)
{
if (debug_threads)
debug_printf ("LLFE: %d exited.\n", lwpid);
+
+ if (finish_step_over (child))
+ {
+ /* Unsuspend all other LWPs, and set them back running again. */
+ unsuspend_all_lwps (child);
+ }
+
/* If there is at least one more LWP, then the exit signal was
not the end of the debugged application and should be
ignored, unless GDB wants to hear about thread exits. */
diff --git a/gdb/testsuite/gdb.base/step-over-exit.c b/gdb/testsuite/gdb.base/step-over-exit.c
new file mode 100644
index 0000000..fd0de71
--- /dev/null
+++ b/gdb/testsuite/gdb.base/step-over-exit.c
@@ -0,0 +1,50 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2016 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+static void
+marker (void)
+{}
+
+int
+main (void)
+{
+ int pid;
+
+ pid = fork ();
+ if (pid == 0) /* child */
+ {
+ _exit (0);
+ }
+ else
+ {
+ }
+
+ pid = fork ();
+ if (pid == 0) /* child */
+ {
+ marker ();
+ _exit (0);
+ }
+ else
+ {
+ marker ();
+ }
+}
diff --git a/gdb/testsuite/gdb.base/step-over-exit.exp b/gdb/testsuite/gdb.base/step-over-exit.exp
new file mode 100644
index 0000000..9827cde
--- /dev/null
+++ b/gdb/testsuite/gdb.base/step-over-exit.exp
@@ -0,0 +1,127 @@
+# Copyright 2016 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+# Test a thread is doing step-over a syscall instruction which is exit,
+# and GDBserver should cleanup its state of step-over properly.
+
+set syscall_insn ""
+
+# Define the syscall instruction for each target.
+
+if { [istarget "i\[34567\]86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
+ set syscall_insn "\[ \t\](int|syscall|sysenter)\[ \t\]"
+} elseif { [istarget "aarch64*-*-linux*"] || [istarget "arm*-*-linux*"] } {
+ set syscall_insn "\[ \t\](swi|svc)\[ \t\]"
+} else {
+ unsupported "unknown syscall instruction"
+ return -1
+}
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+ untested $testfile.exp
+ return -1
+}
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+if ![runto_main] {
+ fail "Can't run to main"
+ return -1
+}
+
+gdb_test "set follow-fork-mode child"
+gdb_test "set detach-on-fork off"
+
+# Step 1, find the syscall instruction address.
+
+gdb_test "break _exit" "Breakpoint $decimal at .*"
+
+# Hit the breakpoint on _exit. The address of syscall insn is recorded.
+
+gdb_test "continue" \
+ "Continuing\\..*Breakpoint $decimal.*_exit \\(.*\\).*" \
+ "continue to exit"
+
+gdb_test "display/i \$pc" ".*"
+
+# Single step until we see a syscall insn or we reach the
+# upper bound of loop iterations.
+set msg "find syscall insn in exit"
+set steps 0
+set max_steps 1000
+gdb_test_multiple "stepi" $msg {
+ -re ".*$syscall_insn.*$gdb_prompt $" {
+ pass $msg
+ }
+ -re "x/i .*=>.*\r\n$gdb_prompt $" {
+ incr steps
+ if {$steps == $max_steps} {
+ fail $msg
+ } else {
+ send_gdb "stepi\n"
+ exp_continue
+ }
+ }
+}
+
+if {$steps == $max_steps} {
+ return
+}
+
+# Remove the display
+gdb_test_no_output "delete display 1"
+
+set syscall_insn_addr [get_hexadecimal_valueof "\$pc" "0"]
+
+gdb_test "continue" "exited normally.*" "continue to end (2)"
+gdb_test "inferior 1" ".*Switching to inferior 1.*" \
+ "switch back to inferior 1 (2)"
+
+delete_breakpoints
+
+gdb_test "break marker"
+
+gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
+ "continue to marker (1)"
+
+# Step 2, create a breakpoint which evaluates false, and force it
+# evaluated on the target side.
+
+set test "set breakpoint condition-evaluation target"
+gdb_test_multiple $test $test {
+ -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" {
+ # Target doesn't support breakpoint condition evaluation
+ # on its side, but it is no harm to run the test.
+ }
+ -re "^$test\r\n$gdb_prompt $" {
+ }
+}
+
+gdb_test "break \*$syscall_insn_addr if main == 0" \
+ "Breakpoint \[0-9\]* at .*"
+
+# Resume the child process, and the step-over is being done.
+
+gdb_test "continue" "exited normally.*" "continue to end (3)"
+gdb_test "inferior 1" ".*Switching to inferior 1.*" \
+ "switch back to inferior 1 (3)"
+
+# Switch back to the parent process, continue to the marker to
+# test GDBserver's state is still correct.
+
+gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \
+ "continue to marker (2)"
--
1.9.1
next prev parent reply other threads:[~2016-06-02 9:31 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-02 9:31 [PATCH 00/12 V2] Use reinsert breakpoint for vCont;s Yao Qi
2016-06-02 9:31 ` [PATCH 01/12] Switch to current thread in finish_step_over Yao Qi
2016-06-13 14:25 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 07/12] Create sub classes of 'struct breakpoint' Yao Qi
2016-06-13 15:09 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 08/12] Refactor clone_all_breakpoints Yao Qi
2016-06-13 15:14 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 09/12] Make reinsert_breakpoint thread specific Yao Qi
[not found] ` <71a5322e-41e3-9e23-df73-e14b14c1d656@redhat.com>
2016-06-14 12:52 ` Yao Qi
2016-06-14 12:57 ` Pedro Alves
2016-06-02 9:31 ` Yao Qi [this message]
2016-06-13 14:37 ` [PATCH 03/12] Step over exit with reinsert breakpoints Pedro Alves
2016-06-13 14:52 ` Yao Qi
2016-06-13 15:01 ` Pedro Alves
2016-06-17 9:50 ` Yao Qi
2016-06-02 9:31 ` [PATCH 06/12] Pass breakpoint type in set_breakpoint_at Yao Qi
2016-06-13 15:07 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 05/12] Handle reinsert breakpoints for vforked child Yao Qi
2016-06-13 15:07 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 10/12] Switch current_thread to lwp's thread in install_software_single_step_breakpoints Yao Qi
2016-06-13 15:26 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 04/12] Delete reinsert breakpoints from forked child Yao Qi
2016-06-13 15:02 ` Pedro Alves
2016-06-13 16:53 ` Yao Qi
2016-06-13 17:29 ` Pedro Alves
2016-06-14 11:17 ` Yao Qi
2016-06-14 11:40 ` Pedro Alves
2016-06-17 9:53 ` Yao Qi
2016-06-02 9:31 ` [PATCH 02/12] More assert checks on reinsert breakpoint Yao Qi
2016-06-13 14:25 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 12/12] Support vCont s and S actions with software single step Yao Qi
2016-06-13 15:56 ` Pedro Alves
2016-06-02 9:31 ` [PATCH 11/12] Use reinsert_breakpoint for vCont;s Yao Qi
2016-06-13 15:55 ` Pedro Alves
2016-06-14 13:14 ` Yao Qi
2016-06-14 15:48 ` Pedro Alves
2016-06-15 16:41 ` Yao Qi
2016-06-17 15:10 ` Pedro Alves
2016-06-20 18:09 ` 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=1464859846-15619-4-git-send-email-yao.qi@linaro.org \
--to=qiyaoltc@gmail.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