From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23286 invoked by alias); 24 Jan 2020 17:15:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 23248 invoked by uid 89); 24 Jan 2020 17:15:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Jan 2020 17:15:24 +0000 Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0C5DB1E5F7; Fri, 24 Jan 2020 12:15:22 -0500 (EST) Subject: Re: [PATCH,v2] Harden gdb.base/step-over-syscall.exp To: Luis Machado , gdb-patches@sourceware.org Cc: Alan.Hayward@arm.com References: <20200115203645.26360-1-luis.machado@linaro.org> <20200124163507.32131-1-luis.machado@linaro.org> From: Simon Marchi Message-ID: <1e1ccc71-fc1d-11b1-e5aa-7236edff9986@simark.ca> Date: Fri, 24 Jan 2020 17:35:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200124163507.32131-1-luis.machado@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2020-01/txt/msg00818.txt.bz2 On 2020-01-24 11:35 a.m., Luis Machado wrote: > New in v2: > > - Set initial values to -1 instead of 0. > - Rewrote RE to prevent unexpected matching when parsing one character at a > time. > - Used gdb_assert for an additional check. > - Validated with check-read1 > > Simon, > > I did some research on checking the syscall numbers to make sure we're calling > the right syscall, but there seems to be considerable variation in terms of > what registers are used to pass the syscall number and also the syscall > number itself. I would expect it to have exactly one register and one syscall number per architecture. > For example, aarch64 seems to use clone for fork/vfork, but arm does not. The > syscall number comes in through w0, but it also gets passed via x8 if it goes > into the kernel. So when we are stopped about to execute the svc instruction, the value should be in x8, that's the one we would care about. > Given the added complexity and the fact that the test is already breaking into > fork/vfork/clone, i think we can be reasonably sure that we are invoking the > right syscall. What do you think? Any other ideas? Yeah, it's probably overkill, forget about that. > @@ -75,39 +76,70 @@ proc setup { syscall } { > # Hit the breakpoint on $syscall for the second time. In this time, > # the address of syscall insn and next insn of syscall are recorded. > > - 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 $syscall" > - set steps 0 > - set max_steps 1000 > - gdb_test_multiple "stepi" $msg { > - -re ".*$syscall_insn.*$gdb_prompt $" { > - pass $msg > + # Check if the first instruction we stopped at is the syscall one. > + set syscall_insn_addr -1 > + set test "fetch first stop pc" > + gdb_test_multiple "display/i \$pc" $test { > + -re "display/i .*: x/i .*=> ($hex) .*:.*$syscall_insn.*$gdb_prompt $" { > + set syscall_insn_addr $expect_out(1,string) > + pass $test > } > - -re "x/i .*=>.*\r\n$gdb_prompt $" { > - incr steps > - if {$steps == $max_steps} { > - fail $msg > - } else { > - send_gdb "stepi\n" > - exp_continue > + -re ".*$gdb_prompt $" { > + pass $test > + } > + } Instead of setting the test variable, you can now just pass the test name to gdb_test_multiple and access it inside the callbacks as $gdb_test_name. See commit: gdb/testsuite: Add gdb_test_name variable 3d63690a0316d92cf248542ee12a3fc8b30152ea The patch LGTM with that fixed. Simon