From patchwork Fri Jun 17 09:50:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 13154 Received: (qmail 48537 invoked by alias); 17 Jun 2016 09:50:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 48522 invoked by uid 89); 17 Jun 2016 09:50:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Writing, 1*, logs, 2526 X-HELO: mail-pf0-f196.google.com Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 17 Jun 2016 09:50:48 +0000 Received: by mail-pf0-f196.google.com with SMTP id i123so2945369pfg.3 for ; Fri, 17 Jun 2016 02:50:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=cRwtcMWzvGFvNzBE+krx3APrIokVOhoHNAGKW84o53Q=; b=QlkaQPLBVVEj01ZBrcjGJbwjwDukmfHqDiFgXpvoA1XubJTp0/K+ZwDv1oLP5iJ2O1 8/0XQUUoFRacXBj0+uXCfGWehvVyYALIipLUwbKHScmxCb0mhIfb0CFdCwVJsE/y6WGn vlFrYxgMPu+CqjZpiuyhqnMy8rVu4EYiWm9H1omY7ExHzL5KBqbucsclNQM2Wt0wKHIO pgUvrGd4j7hYBWVdlzN682rYEx5w2pfCgrKy0XaWtnK6RYvwIPj8SSbNzTvD8SyaNP/p iC3WeLU1SLPLb0OSiMosPpSAQ2afIuxLkRIYhcYLty5sMKkQJbZnSBLGOCSA49myQlPX L1fQ== X-Gm-Message-State: ALyK8tKrfhySdePAg+Ruc5E/06qqekk7SIcOVQBpvXP9ZvR/XRfjXGmamyALMJZYtrjTmQ== X-Received: by 10.98.24.134 with SMTP id 128mr1536985pfy.52.1466157046054; Fri, 17 Jun 2016 02:50:46 -0700 (PDT) Received: from E107787-LIN (gcc113.osuosl.org. [140.211.9.71]) by smtp.gmail.com with ESMTPSA id 69sm26998712pfc.90.2016.06.17.02.50.41 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 17 Jun 2016 02:50:45 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 03/12] Step over exit with reinsert breakpoints References: <1464859846-15619-1-git-send-email-yao.qi@linaro.org> <1464859846-15619-4-git-send-email-yao.qi@linaro.org> <86y469ta2r.fsf@gmail.com> Date: Fri, 17 Jun 2016 10:50:32 +0100 In-Reply-To: (Pedro Alves's message of "Mon, 13 Jun 2016 16:01:10 +0100") Message-ID: <8660t8ta8n.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Pedro Alves writes: >> so, I use "first time" and "second time" to differentiate the test, like >> >> gdb_test "inferior 1" ".*Switching to inferior 1.*" \ >> "switch back to inferior 1, second time" > > Yes, that's fine. Patch below is what I pushed in, diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index c7a9595..fd70f59 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,11 @@ 2016-06-17 Yao Qi + * 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. + +2016-06-17 Yao Qi + * linux-low.c (linux_resume_one_lwp_throw): Assert has_reinsert_breakpoints returns false. * mem-break.c (delete_disabled_breakpoints): Assert 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/ChangeLog b/gdb/testsuite/ChangeLog index 3dad273..fbdcd2b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-06-17 Yao Qi + + * gdb.base/step-over-exit.c: New. + * gdb.base/step-over-exit.exp: New. + 2016-06-17 Yan-Ting Lin * gdb.base/float.exp: Add target check for nds32*-*-*. 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 . */ + +#include +#include +#include + +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..9f4c826 --- /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 . + +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, first time" +gdb_test "inferior 1" ".*Switching to inferior 1.*" \ + "switch back to inferior 1, first time" + +delete_breakpoints + +gdb_test "break marker" + +gdb_test "continue" "Continuing\\..*Breakpoint $decimal, .*" \ + "continue to marker, first time" + +# 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, second time" +gdb_test "inferior 1" ".*Switching to inferior 1.*" \ + "switch back to inferior 1, second time" + +# 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, second time"