From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 4D95A3857418 for ; Tue, 15 Jun 2021 14:09:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D95A3857418 Received: by mail-qk1-x731.google.com with SMTP id j62so28257563qke.10 for ; Tue, 15 Jun 2021 07:09:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FjD6sci2yeME5NKIZFYostxzAIDrBAX9xG/EgXFOe7w=; b=KGptPP7hoqsHa9IvKmmRcvfHRgyJm7IgDUmiatjhgxzC9YVR+z0W+00Cp385r4Z08c qvOEvnSA7AsydR6RqfvGORWe3iPUEjycIWBP6iiCQ/KvmWF9tAVIz5GVEpHZIlzSh7LD h5gNQxsgDDtUyin5fi+qb0Hfvtll7Xqx/4sQwSUfkkLid1FzGaxu1r/SyWfMkTnyvg55 vkeYTciZmF/Hv2vCVHHQYqvJsL99a2wV9A9a8qLLEvD7ZdQuhVMEj7v7nP/yrKBVBnl/ 4C9/1STERrTxMLP414+RSqfMxgj5TbIkiVh7WGmoWOqu3hl/yb/4X3GWsHn1AL8GQpk4 HL3Q== X-Gm-Message-State: AOAM5333f2Y+/G39fqbt5+834ifv4m8LX0rerFpidYeAYGTJNZGH9kXy 1H5Wv2mcaSsRGClqSHHYOLursAFgX0CRDQ== X-Google-Smtp-Source: ABdhPJzLruFV7QPAgTSNQsv6yEEV2zW5GpyGetgPlEVhVvLQE7H1cMX7GWlDcKuCrUk4vFY69bZtOw== X-Received: by 2002:a05:620a:109a:: with SMTP id g26mr13303362qkk.450.1623766174183; Tue, 15 Jun 2021 07:09:34 -0700 (PDT) Received: from ?IPv6:2804:7f0:4841:a0:d942:8bb2:2901:cab7? ([2804:7f0:4841:a0:d942:8bb2:2901:cab7]) by smtp.gmail.com with ESMTPSA id s81sm12347772qka.82.2021.06.15.07.09.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 07:09:33 -0700 (PDT) Subject: [Ping][PATCH] Fix displaced stepping watchpoint check order From: Luis Machado To: gdb-patches@sourceware.org References: <20210608154230.354202-1-luis.machado@linaro.org> Message-ID: <37591f25-1e3c-74a8-8cda-12e5a9b48866@linaro.org> Date: Tue, 15 Jun 2021 11:09:30 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210608154230.354202-1-luis.machado@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jun 2021 14:09:36 -0000 On 6/8/21 12:42 PM, Luis Machado wrote: > When checking the stopped data address, I noticed, under some circumstances, > that the instruction at PC wasn't the expected one. This happens because the > displaced stepping machinery restores the buffer before checking if the > instruction executed successfully, which in turn calls the watchpoint check. > > I guess this was never noticed because stopped data address checks usually > don't need to fetch the instruction at PC, but AArch64 needs to do it from > now on. > > We should check if the instruction executed successfully before we restore the > scratchpad contents. > > Regression tested on aarch64-linux/Ubuntu 20.04. > > gdb/ChangeLog: > > YYYY-MM-DD Luis Machado > > * displaced-stepping.c (displaced_step_buffers::finish): Move check > upwards. > --- > gdb/displaced-stepping.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/gdb/displaced-stepping.c b/gdb/displaced-stepping.c > index 59b78c22f6a..06324d523d8 100644 > --- a/gdb/displaced-stepping.c > +++ b/gdb/displaced-stepping.c > @@ -227,6 +227,11 @@ displaced_step_buffers::finish (gdbarch *arch, thread_info *thread, > > ULONGEST len = gdbarch_max_insn_length (arch); > > + /* Check if the execution was successful before restoring the buffer > + contents. */ > + bool instruction_executed_successfully > + = displaced_step_instruction_executed_successfully (arch, sig); > + > /* Restore memory of the buffer. */ > write_memory_ptid (thread->ptid, buffer->addr, > buffer->saved_copy.data (), len); > @@ -237,9 +242,6 @@ displaced_step_buffers::finish (gdbarch *arch, thread_info *thread, > > regcache *rc = get_thread_regcache (thread); > > - bool instruction_executed_successfully > - = displaced_step_instruction_executed_successfully (arch, sig); > - > if (instruction_executed_successfully) > { > gdbarch_displaced_step_fixup (arch, copy_insn_closure.get (), >