From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 3C906385841B for ; Thu, 19 Aug 2021 01:31:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C906385841B Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 17J1V63V029926 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 21:31:11 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 17J1V63V029926 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E2E8D1E4A3; Wed, 18 Aug 2021 21:31:05 -0400 (EDT) Subject: Re: [PATCH] Fix displaced stepping watchpoint check order To: Luis Machado , gdb-patches@sourceware.org References: <20210608154230.354202-1-luis.machado@linaro.org> <9c697f35-1059-5ea8-83c3-ea75fcc95b32@polymtl.ca> <0ef1ceef-f6b4-7310-bec0-d54d4b646fea@linaro.org> From: Simon Marchi Message-ID: <18bc6e10-91e5-15c9-0455-30004d82b7c8@polymtl.ca> Date: Wed, 18 Aug 2021 21:31:05 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <0ef1ceef-f6b4-7310-bec0-d54d4b646fea@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 19 Aug 2021 01:31:06 +0000 X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thu, 19 Aug 2021 01:31:23 -0000 > No side effects of the instruction are committed in this case. Memory and registers will have their old values as if the instruction didn't execute. > > From reading the code, most architectures have non-steppable hardware watchpoints. GDB just disables the hardware watchpoints, single-steps past that instruction and then enables the hardware watchpoints again. > > GDB just disables all hardware watchpoints for the sake of simplicity. You can see this logic in infrun.c:handle_signal_stop, around this comment: > > /* If necessary, step over this watchpoint. We'll be back to display > it in a moment. */ > if (stopped_by_watchpoint > && (target_have_steppable_watchpoint () > || gdbarch_have_nonsteppable_watchpoint (gdbarch))) > > It is actually best to disable all hardware watchpoints. If we end up disabling just one hardware watchpoint, and then we happen to have another hardware watchpoint that is active and also getting triggered, we might be stuck in an endless loop as well. > Ok, thanks for the explanation. Watchpoints are usually (always?) defined in some per-thread register, so unlike software breakpoints, I suppose it's safe to remove the watchpoints just for the thread we step. I suppose that is what we are doing? >>>> Can you clarify what you mean by "from now on"? Can you indicate what >>>> change you are referring to? >>>> >>> >>> From the following change (https://sourceware.org/pipermail/gdb-patches/2021-July/181095.html) onwards, we need to look at the load/store instruction to figure out the memory access size so we can reliably tell if a hardware watchpoint has triggered. This is due to how AArch64's spec defines how to provide a stopped data address, and the valid ranges. >> >> Ok, but that patch you linked isn't merged yet? So it sounds strange to >> say "from now on", it sounds like there's a dependency between the two > > Absolutely. There is a dependency. My plan is to merge this fix first, and then merge the AArch64 hardware watchpoint detection fixes. I just didn't group those together, but that's the right order. I'll make sure to point out the dependency in the other patch. Ok. >> patches. Let's say the current patch is merged before the other one, >> maybe it should say "but AArch64 will need to do it it an upcoming >> patch", and then you can given the link. >> >>> With the old code, if we try to fetch the instruction at PC, we will get a bogus value that is not the real instruction that caused the hardware watchpoint trigger. Hence why the patch moves the call to displaced_step_instruction_executed_successfully (...) up and before we restore the displaced stepping buffer. >>> >>> If a hardware watchpoint trigger takes place and GDB doesn't recognize it, then displaced_step_instruction_executed_successfully (...) will return true and GDB will move on and will attempt to execute the same instruction again, only to be halted due to the same hardware watchpoint trigger that it can't detect. So GDB gets into an infinite loop. >>> >>> More generally, if we ever fail to acknowledge a hardware watchpoint trigger on an architecture with non-steppable watchpoints and displaced stepping support, we will run into this infinite loop (as far as I can tell). >>> >>> Does that make sense? >> >> Yes, this help. Please feel free to include in the commit message any >> additional detail that you gave here, since it might help somebody else >> in the future. > > I'll make the commit message more detailed. Thanks, Simon