From patchwork Mon Jan 13 17:42:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 182817 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4425515ile; Mon, 13 Jan 2020 10:00:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyDsdTVxPj0S2HTh+ihotU37Ij5VPg7vhIBnbJS/yF3uB0qPUy5DKnfbW5m/OUsYPnP7RVY X-Received: by 2002:a9d:5918:: with SMTP id t24mr14392248oth.310.1578937387263; Mon, 13 Jan 2020 09:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578937387; cv=none; d=google.com; s=arc-20160816; b=vYCpcA74g/aLukAkI0Q5QSpnVrnWkYHg7N+TaAEqk9lXwMCVlpT1Tt89VnVbLmICc/ aJSw4FuExf9PsoLAIR/yaT0es8TCzq5l+1jx5kZGFpdeUznOu8Pf7hHalacjBf5POcFb in/SQJ8Rgu7gz6f/r/sWpasxcJ3ud4lR1VmGJ0J1TvUIstsXUiiON/ewvJ2j1c9hM1vn VaawUkgHuM/aqM7eahdjuewM/NJbvlbjTLa5xxNym/wLEhDwwIsmeyXbmEJjrXs0Mncj UckKTxbcPwk6oQTiLOaOi6Z9nLkvdLQ819LbXWgp7+gD2kcIDhanX+3uZ7i6inI9N4fV 6ETw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=repniiy/ejxFy7QNvZEzaawwVjD7pBDbdOdDrNLJ1Vg=; b=EZVAd065/k/Ub1sDjF5YBYrH9CZ8odkYunLaE7Vx5v8niwwFxsFgquM41OZXRVAj7t 8XbZous5cqzhufV4TVHgp1RVmCg9Pv9UwrDGM4e9DFkzngKFQbqbrKqcTBU6kmY6mNRg mZyOiIop+dp92b1U30971EF46usFZ9bl2RNuEWmbviPhNVAGQRNvavm6PhN5pM5Jq8it rzueuS2KSk66YP4/EV+iM5qx6bwEMXDhpwyckXGVdlDRjRygjtQggKifJ/pUCHonBTDn gIoTNzDn2NHXgSM+Dm9WkXGoEuKfU1KeXlwTZrHDvWq1okUrDRqaB8RlDNt53c5xPYQN yvag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=DWUMChjN; dkim=pass header.i=@linaro.org header.s=google header.b="nOH/zX6D"; spf=pass (google.com: domain of gdb-patches-return-163027-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163027-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l26si6640491oti.152.2020.01.13.09.43.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jan 2020 09:43:07 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-163027-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=DWUMChjN; dkim=pass header.i=@linaro.org header.s=google header.b="nOH/zX6D"; spf=pass (google.com: domain of gdb-patches-return-163027-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163027-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=aOPIZ0VWEHMp/bYtpOGkhaqpI3giUG5 PBKj43R5Vp2UVDUuphCHEFlnhqnwUSi3inTVX42gv7tWesvvpSe3UQVE2ha2KYAb zcMnvgvBZdTCO9BOakCJP1oT1c6/XDAkBIa3PGarEdpkr632MDk4/XyX5EzgQhu9 AEp2CKAhgh7A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=YN3snBNt6nXejJWjvugIxhVNzPU=; b=DWUMC hjNfxCRypMG/Z6istPa5hsHXBBlTk2sXvXDQPW/wHwExptgONyfd5pzHicjyANut uT4uSm+L2Jqu5Cq87dfA5YxLRGQMZ8OGHVxzA+rAP28pBZAf7BnbCYib4bo9vNo7 B1t3qGp+y4TMSc1NqT3rmnaNLlxbK9KfAkgVXI= Received: (qmail 34546 invoked by alias); 13 Jan 2020 17:42:57 -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 34455 invoked by uid 89); 13 Jan 2020 17:42:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f176.google.com Received: from mail-qk1-f176.google.com (HELO mail-qk1-f176.google.com) (209.85.222.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 13 Jan 2020 17:42:55 +0000 Received: by mail-qk1-f176.google.com with SMTP id z14so9269292qkg.9 for ; Mon, 13 Jan 2020 09:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=repniiy/ejxFy7QNvZEzaawwVjD7pBDbdOdDrNLJ1Vg=; b=nOH/zX6D9KOH2zuN8SWgrTfxbTLsb4+bjecGiEOuVfb07GrAw1EMV/FFGBjLElsFgQ nN6VWoC8N0tasm42g0rIQnWBBFArduTSXtczm2PxUtuc04stJuG1Fu5H2IMKJBcvKEAx 3uvrBh3H+k7tZ1as5Vef8NKoebHwntdYGPq8O8lOw+DVE8Zbc5J6VOXDMb8lUB2/ThaR fUzVbQlFJ1rQMf83hQz16rFUq0cvNt319HSEhzgEIVXsKGm7Ob0T6vKORM7yrVyBJ9LA 91+3Z+iVqMnnuaIO88gnYWWxd0wEaeNoXO0hJXsfHbkHOIycAD3E/KJmUZ11LlKVIpve OPtw== Return-Path: Received: from localhost.localdomain ([179.183.9.215]) by smtp.gmail.com with ESMTPSA id s27sm5247049qkm.97.2020.01.13.09.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 09:42:51 -0800 (PST) From: Luis Machado To: gdb-patches@sourceware.org Cc: alan.hayward@arm.com Subject: [PATCH,v2][AArch64] Fix step-over-syscall.exp failure Date: Mon, 13 Jan 2020 14:42:39 -0300 Message-Id: <20200113174239.7819-3-luis.machado@linaro.org> In-Reply-To: <20200113174239.7819-1-luis.machado@linaro.org> References: <20200113174239.7819-1-luis.machado@linaro.org> X-IsSubscribed: yes New in v2: - Reverted to using pc_adjust as bool/offset and added more comments to explain how it is being used. -- In particular, this one: FAIL: gdb.base/step-over-syscall.exp: fork: displaced=on: check_pc_after_cross_syscall: single step over fork final pc When ptrace fork event reporting is enabled, GDB gets a PTRACE_EVENT_FORK event whenever the inferior executes the fork syscall. Then the logic is that GDB needs to step the inferior yet again in order to receive a predetermined SIGTRAP, but no execution takes place because the signal was already queued for delivery. That means the PC should stay the same. I noticed the aarch64 code is currently adjusting the PC in this situation, making the inferior skip an instruction without executing it. The following change checks if we did not execute the instruction (pc - to == 0), making proper adjustments for such case. Regression tested on aarch64-linux-gnu. gdb/ChangeLog: 2020-01-13 Luis Machado * aarch64-tdep.c (struct aarch64_displaced_step_closure ) : Adjust the documentation. (aarch64_displaced_step_fixup): Check if PC really moved before adjusting it. --- gdb/aarch64-tdep.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index da41e22130..6a9d34dc67 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2737,7 +2737,8 @@ struct aarch64_displaced_step_closure : public displaced_step_closure is being displaced stepping. */ int cond = 0; - /* PC adjustment offset after displaced stepping. */ + /* PC adjustment offset after displaced stepping. If 0, then we don't + write the PC back, assuming the PC is already the right address. */ int32_t pc_adjust = 0; }; @@ -3032,11 +3033,12 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch, { aarch64_displaced_step_closure *dsc = (aarch64_displaced_step_closure *) dsc_; + ULONGEST pc; + + regcache_cooked_read_unsigned (regs, AARCH64_PC_REGNUM, &pc); + if (dsc->cond) { - ULONGEST pc; - - regcache_cooked_read_unsigned (regs, AARCH64_PC_REGNUM, &pc); if (pc - to == 8) { /* Condition is true. */ @@ -3052,6 +3054,13 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch, if (dsc->pc_adjust != 0) { + /* Make sure the previous instruction was executed (that is, the PC + has changed). If the PC didn't change, then discard the adjustment + offset. Otherwise we may skip an instruction before its execution + took place. */ + if ((pc - to) == 0) + dsc->pc_adjust = 0; + if (debug_displaced) { debug_printf ("displaced: fixup: set PC to %s:%d\n",