From patchwork Fri Feb 26 14:03:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 11111 Received: (qmail 88116 invoked by alias); 26 Feb 2016 14:04:08 -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 88035 invoked by uid 89); 26 Feb 2016 14:04:08 -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= X-HELO: mail-pf0-f194.google.com Received: from mail-pf0-f194.google.com (HELO mail-pf0-f194.google.com) (209.85.192.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 26 Feb 2016 14:04:03 +0000 Received: by mail-pf0-f194.google.com with SMTP id e127so4727352pfe.3 for ; Fri, 26 Feb 2016 06:04:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=QuRVsmLo4GybgN2yUZBce400SLrVHfY//+tmHlp1HBY=; b=aGg+TMMQlo/k6bYqaD2MSheGcEUIPQtceykLWOR7E8rPzNyNACYi8aK0Y70Ahe5G1u FheGmuojEl2V7/0da8b8wFiZx16qBm5TQNXQ93O3LaGlEB/rBNDb/yUt7j/6F4F1c9nO zWadbTFgco0rk7LutunHDsX0AxARvhmxZzd+ADHM8vyT/B6HSsT5R2E+e/9E3arwtywR MfxDAiH5cOtaTzEAX8RmiFPtwQlrmuud0bB55Lrkm8MZRTeg0xRbYxELs1Af4qeZ/cQR HWB+Gwnuf7c8CW2dLOxX3Dcn8ACcb/rCADvJn4/FlFDCY7Cf45L8ZKu1g85Teo5U/2TI HdqA== X-Gm-Message-State: AD7BkJJZ8UryXaehIKHReVQ3nvkWmk3Hf/vCXJm3R6VqR0plw5cEs7el1aeFyPmY01k1SA== X-Received: by 10.98.86.139 with SMTP id h11mr2277272pfj.105.1456495441369; Fri, 26 Feb 2016 06:04:01 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id d81sm19745089pfj.77.2016.02.26.06.04.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 06:04:00 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 4/7] Step over fork/vfork syscall insn in gdbserver Date: Fri, 26 Feb 2016 14:03:43 +0000 Message-Id: <1456495426-7520-5-git-send-email-yao.qi@linaro.org> In-Reply-To: <1456495426-7520-1-git-send-email-yao.qi@linaro.org> References: <1455892594-2294-1-git-send-email-yao.qi@linaro.org> <1456495426-7520-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes We can also extend disp-step-syscall.exp to test GDBserver step over breakpoint on syscall instruction. That is, we set a breakpoint with a false condition on syscall instruction, so that GDBserver will step over it. This test triggers a GDBserver internal error, which can be fixed by this series. (gdb) PASS: gdb.base/disp-step-syscall.exp: fork: break cond on target: break on syscall insns continue^M Continuing.^M Remote connection closed^M (gdb) FAIL: gdb.base/disp-step-syscall.exp: fork: break cond on target: continue to fork again In GDBserver, there is an internal error, /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:1922: A problem internal to GDBserver has been detected. unsuspend LWP 25554, suspended=-1 the simplified reproducer is like, $ ./gdb ./testsuite/outputs/gdb.base/disp-step-syscall/disp-step-fork (gdb) b main (gdb) c (gdb) disassemble fork // in order to find the address of insn 'syscall' .... 0x00007ffff7ad6023 <+179>: syscall (gdb) b *0x00007ffff7ad6023 if main == 0 (gdb) c gdb/testsuite: 2016-02-26 Yao Qi * gdb.base/disp-step-syscall.exp (break_cond_on_syscall): New. If target supports condition evaluation on target, invoke break_cond_on_syscall for fork and vfork. --- gdb/testsuite/gdb.base/disp-step-syscall.exp | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/gdb/testsuite/gdb.base/disp-step-syscall.exp b/gdb/testsuite/gdb.base/disp-step-syscall.exp index 3cf436d..9ecf2a5 100644 --- a/gdb/testsuite/gdb.base/disp-step-syscall.exp +++ b/gdb/testsuite/gdb.base/disp-step-syscall.exp @@ -168,5 +168,62 @@ proc disp_step_cross_syscall { syscall } { } } +# Set a breakpoint with a condition that evals false on syscall +# instruction. In fact, it tests GDBserver steps over syscall +# instruction. + +proc break_cond_on_syscall { syscall } { + with_test_prefix "break cond on target : $syscall" { + set testfile "disp-step-$syscall" + + set ret [setup $syscall] + + set syscall_insn_addr [lindex $ret 0] + set syscall_insn_next_addr [lindex $ret 1] + if { $syscall_insn_addr == -1 } { + return -1 + } + + gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, (.* in |__libc_|)$syscall \\(\\).*" \ + "continue to $syscall" + # Delete breakpoint syscall insns to avoid interference to other syscalls. + delete_breakpoints + + + # Create a breakpoint with a condition that evals false. + gdb_test "break \*$syscall_insn_addr if main == 0" \ + "Breakpoint \[0-9\]* at .*" + + gdb_test "break marker" "Breakpoint.*at.* file .*${testfile}.c, line.*" + gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, marker \\(\\) at.*" \ + "continue to marker ($syscall)" + } +} + disp_step_cross_syscall "fork" disp_step_cross_syscall "vfork" + +set testfile "disp-step-fork" +clean_restart $testfile +if { ![runto main] } then { + fail "run to main" + return -1 +} + +set cond_bp_target 1 + +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. + set cond_bp_target 0 + } + -re "^$test\r\n$gdb_prompt $" { + } +} + +if { $cond_bp_target } { + break_cond_on_syscall "fork" + break_cond_on_syscall "vfork" +}