From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id vcCJISNPAGuwSiQAWB0awg (envelope-from ) for ; Fri, 20 Nov 2026 08:46:11 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=qOe1vY1K; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 728691E091; Fri, 20 Nov 2026 08:46:11 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 78E591E091 for ; Fri, 20 Nov 2026 08:46:10 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D9154368E24 for ; Fri, 20 Nov 2026 13:46:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D9154368E24 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=qOe1vY1K Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 13A5A4BC89A1 for ; Fri, 20 Nov 2026 13:45:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13A5A4BC89A1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13A5A4BC89A1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795182343; cv=none; b=O4vXeuN3AThtOp0gDXNs9FeYvs0oDIM9PP75dwNH+ik/j3uyu1I2hh8Pg/+jmxGsWBCmDdUB1aWZhvr5BnFssPVxqo5q7STq7rgc/HfTH0EkY/mLc1GBZsfG8A1pxgMv8uL/7J7PJiNa2hquu+S0i+Mmx9kifHFk0gZMaTzXHIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795182343; c=relaxed/simple; bh=Oc5WReb064FGO7KBhuCZOw0zPiDp4/SZUPdEA1gUXfg=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=hwSEfCAcfh16tce8grhY3YjD/MOQ2Y3UCHj2x/b5x73PA0DefntetfHu78FWEv6dF/dsdahy0G5HQQx6AZq6U6YyzoWc/HOg7gHM9+Tp9vqcWjzz3vNSzLW5BpCD4vP5GBm34ioeDDJeQA4ofnmj6AXliGW5UgftPIcrCMOQ3Fs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=qOe1vY1K DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13A5A4BC89A1 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xUOvt-00074O-Nk; Fri, 20 Nov 2026 08:45:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Tz9VtUAs9xypdS08FjUVDBqSHZ4wmjpxc1B0thWjYGA=; b=qOe1vY1K93V3 ijYzUMUYcM7bRQc3IhhwsTQR8iakU4/TnQ1/FtTOYez7A1JwrDnfKRBN5iJm6IGR8OSPTuoaAtD2f sXgTff97l8mQsECEVXjjhyAOoWjEenwAJ1wNw502JoNCgGeVUGbE3xvjbpt9F79hVQdzA6HR98qQj a2grrQbQbVAQBIbAMEMJzMm9V2eHbGGX4IN2puZuW54k1bSRCJwTTn9kVf5vulo63WvXQTR6BMnNT KVbCIqYqEA+JE1JFfzVBeeg03MSBOMSvNyqFc8yAPbTly69K0FqqqJtOXGeAj3dYnI5uIqam++6OF yYPFPEpOsnDkTeCeVWqd7Q==; Date: Fri, 20 Nov 2026 15:45:39 +0200 Message-Id: <86a4n3k458.fsf@gnu.org> From: Eli Zaretskii To: Mohamed Bouhaouel Cc: gdb-patches@sourceware.org, kevinb@redhat.com, guinevere@redhat.com, abdul.b.ijaz@intel.com In-Reply-To: <20261120132155.430400-1-mohamed.bouhaouel@intel.com> (message from Mohamed Bouhaouel on Fri, 20 Nov 2026 14:21:55 +0100) Subject: Re: [PATCH v2 1/1] gdb, infcall, breakpoint: Handle cycles in conditional expr evaluation References: <20261120132155.430400-1-mohamed.bouhaouel@intel.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org > From: Mohamed Bouhaouel > Cc: kevinb@redhat.com, guinevere@redhat.com, abdul.b.ijaz@intel.com, > mohamed.bouhaouel@intel.com > Date: Fri, 20 Nov 2026 14:21:55 +0100 > > Take the following scenario: > > (gdb) break foo if foo (1) == 2 > (gdb) run > > The program stops at 'foo', then GDB tries to evaluate the condition. > The condition triggers an inferior call of 'foo', which causes a stop at > 'foo' again, and GDB is stuck in this infinite cycle. > > The same issue exists also for indirect cycles, e.g., > > (gdb) break foo if bar (1) > (gdb) break bar if foo (1) > (gdb) run > > To avoid this, check for cycles just before evaluating a breakpoint > condition. If a breakpoint is hit again while its own condition is > being evaluated, the evaluation of that condition is aborted with an > error message. > > Since this also rejects recursion that terminates, e.g., > > (gdb) break factorial if value > 1 && factorial (value - 1) > 100 > > add a new setting, "set breakpoint condition-cycle-detection on|off" > (on by default), which allows turning the check off. > > With the patch, the behavior becomes: > > (gdb) break foo if foo (1) == 2 > Breakpoint 2 at 0x55555555514c: file infcall-from-bp-cond-cycle.c, line 27. > (gdb) continue > Continuing. > Error in testing condition for breakpoint 2: > Aborting evaluation of the breakpoint condition: > A cycle was detected during the evaluation. > To change this behavior use "set breakpoint condition-cycle-detection off". > > Breakpoint 2, foo (a=1) at infcall-from-bp-cond-cycle.c:27 > 27 return a + add_one (a); > Error in testing condition for breakpoint 2: > The program being debugged stopped while in a function called from GDB. > Evaluation of the expression containing the function > (foo) will be abandoned. > When the function is done executing, GDB will silently stop. > (gdb) backtrace > #0 foo (a=1) at infcall-from-bp-cond-cycle.c:27 > #1 > #2 foo (a=11) at infcall-from-bp-cond-cycle.c:27 > #3 0x00005555555551df in main () at infcall-from-bp-cond-cycle.c:55 > > Tested-By: Guinevere Larsen > --- > Changes in v2: > - Add "set breakpoint condition-cycle-detection on|off" (on by > default) to allow recursion through a breakpoint condition that > terminates, as in the factorial example from the v1 review. > - Use "breakpoint" instead of "bp" in the error message, and mention > the new setting in it. > - Add NEWS and documentation entries. > - Extend the test with the factorial case. > > gdb/NEWS | 8 ++ > gdb/breakpoint.c | 44 ++++++++- > gdb/doc/gdb.texinfo | 19 ++++ > gdb/gdbthread.h | 10 ++- > gdb/infcall.c | 2 +- > gdb/infrun.c | 6 +- > .../gdb.base/infcall-from-bp-cond-cycle.c | 60 +++++++++++++ > .../gdb.base/infcall-from-bp-cond-cycle.exp | 89 +++++++++++++++++++ > 8 files changed, 231 insertions(+), 7 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.c > create mode 100644 gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.exp Thanks. > diff --git a/gdb/NEWS b/gdb/NEWS > index db3fa820df1..b38eaee5c09 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -67,6 +67,14 @@ maintenance info source-tracking-context BPNUM > Display the captured source context that GDB uses to track and > adjust a breakpoint when source changes. > > +set breakpoint condition-cycle-detection on|off > +show breakpoint condition-cycle-detection > + When on (the default), GDB aborts the evaluation of a breakpoint > + condition that is reentered, e.g. because the condition calls a > + function that hits the same breakpoint again, to avoid an infinite > + cycle. When off, the evaluation continues, which allows recursion > + through a breakpoint condition. I think the name of the option could be made more meaningful: this is not about "detection", this is about aborting evaluation of breakpoint condition. So I would suggest "set breakpoint allow-cycles-in-condition" or something similar (yes, that reverts the meaning). > + add_setshow_boolean_cmd ("condition-cycle-detection", class_breakpoint, > + &bp_cond_cycle_detection, _("\ > +Set whether cycles in breakpoint conditions are detected."), _("\ ^^^^^^^^ Not "detected", but "allowed". Even if we keep the name of the option, the doc string should be amended to be more accurate. > +A function called from a breakpoint condition may itself hit the same > +breakpoint, so that the condition is evaluated again before the outer > +evaluation completes. By default, @value{GDBN} considers this a cycle > +and aborts the evaluation, as it would otherwise likely never end. I would add to the paragraph above something like You can control this behavior using the following option. It adds continuity to the manual. The documentation parts are okay with these nits fixed. Reviewed-By: Eli Zaretskii