From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8B12B3858D28 for ; Wed, 21 Jun 2023 13:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B12B3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687353575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dTR/OdbWmMn0BqbNAqcpag8ID5NkkNFDf7GFfqfB34c=; b=EuIyheqfOkpVNo5YwoD4Qp9rCWbp1YS/bh6iV0ayOl+ZdizE40jRtGzDEVl/PMfRuacZuW tZmSssHbByqKQ8PYqZ0zdFjicmmpQYjaBhvLpySPByZCDNEVPDwkcrriv5xk1VA/MfQpet XIsupzq4hYp+Sk4QUfvamznnYuCshqU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-13-QRgACMURNPCv_6Ug-qU4nw-1; Wed, 21 Jun 2023 09:19:34 -0400 X-MC-Unique: QRgACMURNPCv_6Ug-qU4nw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3113da8b778so1422970f8f.3 for ; Wed, 21 Jun 2023 06:19:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687353573; x=1689945573; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dTR/OdbWmMn0BqbNAqcpag8ID5NkkNFDf7GFfqfB34c=; b=NvQwlnNYZo/dqzORUwR8VrP4UmxlFXJ8rbUdE9wGc4Xj7bnSH8U4CgZKq5D82XgNQi po4x03mNVsqthIToz/NsHSI8uUaL1WWOIfuj+0Vv37VWfLHdgpSS6/QcVo/84cJJ17GN Li9lZlDvYDGTiGCUpik5GAwEh0BNNBQdBn2XczR1bsCrJMqo42DoYCHnthsj/MlOSU9L PEqoE1jtACvD7IDlOSmVjqItZqnG1Qq4NwrsamppnLQ6Uf1G9+0Yx40UbV8ZBra42Eqz az3o5bLJMx9AK8d1m5/aM3ngl2EeGd5EwzakLIbQlyXPJArq4Sf7ZAULE2ajuXVCNH4d u+mQ== X-Gm-Message-State: AC+VfDzsO54VSixjCzKB/8c8PJ50aAqHhr7LeH4MEAYkDkQLZ9UNrBST 4CqdOsKWBmU+H9c142X8JS2hCC59O/pCKBrjozuGH4X4LnuzoblpRyIYTPz/nPvNTLArxNtIokF sjFy47lE7BRpF0HPaDT75zw== X-Received: by 2002:adf:f6ca:0:b0:30e:438f:8ceb with SMTP id y10-20020adff6ca000000b0030e438f8cebmr9529410wrp.59.1687353572834; Wed, 21 Jun 2023 06:19:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bEFXGmqi1Vq7mtUnKnSfdy2CO4x0pAGxrFaAVOGg2lA9TTQsEoe5WLu1JK+FmlYna/Dqoiw== X-Received: by 2002:adf:f6ca:0:b0:30e:438f:8ceb with SMTP id y10-20020adff6ca000000b0030e438f8cebmr9529399wrp.59.1687353572459; Wed, 21 Jun 2023 06:19:32 -0700 (PDT) Received: from [192.168.0.129] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id o14-20020a5d408e000000b00300aee6c9cesm4483967wrp.20.2023.06.21.06.19.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Jun 2023 06:19:31 -0700 (PDT) Message-ID: <4937d19e-72c0-2b8b-01e6-f984bc922c58@redhat.com> Date: Wed, 21 Jun 2023 15:19:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v2 1/1] gdb, breakpoint: add a destructor to the watchpoint struct To: Mohamed Bouhaouel , gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com References: <20230405133456.16087-1-mohamed.bouhaouel@intel.com> From: Bruno Larsen In-Reply-To: <20230405133456.16087-1-mohamed.bouhaouel@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 05/04/2023 15:34, Mohamed Bouhaouel via Gdb-patches wrote: > Make sure to unlink the related breakpoint when the watchpoint instance > is deleted. This prevents having a wp-related breakpoint that is > linked to a NULL watchpoint (e.g. the watchpoint instance is being > deleted when the 'watch' command fails). With the below scenario, > having such a left out breakpoint will lead to a GDB hang, and this > is due to an infinite loop when deleting all inferior breakpoints. > > Scenario: > (gdb) set can-use-hw-watchpoints 0 > (gdb) awatch > Can't set read/access watchpoint when hardware watchpoints are disabled. > (gdb) rwatch > Can't set read/access watchpoint when hardware watchpoints are disabled. > (gdb) > >> HANG << > > Signed-off-by: Mohamed Bouhaouel Hi Mohamed! Thank you for working on this! I have tried it, your test reproduces the issue, and your changes fix them. I only have one small nit inlined. Other than that: Reviewed-By: Bruno Larsen Do note that that tag is not enough to push, so here's hoping a maintainer looks at it soon! > --- > gdb/breakpoint.c | 15 +++++++ > gdb/breakpoint.h | 3 ++ > .../gdb.base/scope-hw-watch-disable.c | 26 ++++++++++++ > .../gdb.base/scope-hw-watch-disable.exp | 40 +++++++++++++++++++ > 4 files changed, 84 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/scope-hw-watch-disable.c > create mode 100644 gdb/testsuite/gdb.base/scope-hw-watch-disable.exp > > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index ebe97940f54..862e9a372ab 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -9594,6 +9594,21 @@ break_range_command (const char *arg, int from_tty) > install_breakpoint (false, std::move (br), true); > } > > +/* See breakpoint.h. */ > + > +watchpoint::~watchpoint () > +{ > + /* Make sure to unlink the destroyed watchpoint from the related > + breakpoint ring. */ > + > + breakpoint *bpt = this; The bpt variable seems unnecessary to me. you could remove this line and substitute all occurrences of bpt in the following lines with "this" > + breakpoint *related = bpt; and in doing that, I think it might make sense to rename this to bpt? This second one is just a suggestion, though, so no need to change if you prefer it like this. -- Cheers, Bruno > + while (related->related_breakpoint != bpt) > + related = related->related_breakpoint; > + > + related->related_breakpoint = bpt->related_breakpoint; > +} > + > /* Return non-zero if EXP is verified as constant. Returned zero > means EXP is variable. Also the constant detection may fail for > some constant expressions and in such case still falsely return > diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h > index 7c5cf3f2bef..cccd331e6e8 100644 > --- a/gdb/breakpoint.h > +++ b/gdb/breakpoint.h > @@ -933,6 +933,9 @@ struct watchpoint : public breakpoint > void print_recreate (struct ui_file *fp) const override; > bool explains_signal (enum gdb_signal) override; > > + /* Destructor for WATCHPOINT. */ > + ~watchpoint (); > + > /* String form of exp to use for displaying to the user (malloc'd), > or NULL if none. */ > gdb::unique_xmalloc_ptr exp_string; > diff --git a/gdb/testsuite/gdb.base/scope-hw-watch-disable.c b/gdb/testsuite/gdb.base/scope-hw-watch-disable.c > new file mode 100644 > index 00000000000..30956fe1b84 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/scope-hw-watch-disable.c > @@ -0,0 +1,26 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +int > +main () > +{ > + int a = 0, b = 0; > + b = a; > + a = b + 10; > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/scope-hw-watch-disable.exp b/gdb/testsuite/gdb.base/scope-hw-watch-disable.exp > new file mode 100644 > index 00000000000..54ebb4e4226 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/scope-hw-watch-disable.exp > @@ -0,0 +1,40 @@ > +# Copyright 2023 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test that GDB displays the correct error message when hardware watchpoints > +# are not supported or explicitly disabled. Test also that GDB terminates > +# successfully after several attempts to insert a hardware watchpoint. > + > +standard_testfile > + > +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { > + return -1 > +} > + > +gdb_test_no_output "set can-use-hw-watchpoints 0" > + > +if {![runto_main]} { > + return -1 > +} > + > +gdb_test "awatch a" \ > + "Can't set read/access watchpoint when hardware watchpoints are disabled." \ > + "unsuccessful attempt to create an access watchpoint" > +gdb_test "rwatch b" \ > + "Can't set read/access watchpoint when hardware watchpoints are disabled." \ > + "unsuccessful attempt to create a read watchpoint" > + > +# The program continues until termination. > +gdb_continue_to_end