From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eFIxAJJa1mrlmDMAWB0awg (envelope-from ) for ; Mon, 19 Oct 2026 13:59:46 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D1VfuNIU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E02421E050; Mon, 19 Oct 2026 13:59:45 -0400 (EDT) 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 C77431E04E for ; Mon, 19 Oct 2026 13:59:41 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47B394BA2E16 for ; Mon, 19 Oct 2026 17:59:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47B394BA2E16 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D1VfuNIU Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 37DE44BA23EB for ; Mon, 19 Oct 2026 17:58:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37DE44BA23EB Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37DE44BA23EB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792432685; cv=none; b=VWet4UfKrcS5oaU5HlSqw07QhPewdpuug/DQcOBnh5sbAjFqXuW3K6ZflAbDqZQOviSTEHQJZlVFXX++e1W4i+wfQAZY8W8tnTEm8Pt/Jg/m2pOn04OINl6VdXPMK3/v1tbs3BOIfnz85nRgjAk9Sqqkcg1d4yZZQBX3yB2Sv1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792432685; c=relaxed/simple; bh=OKglyXBJ3lA0O1vOZ/D0+f2c/dig6iurOwfENwQgUhg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=oi767pfsahXJv97SnsQ7dbITk95WNT/M0qosHXhWAhXWFwh+32jRqe3AOI8Mhy8rjFhM+sw9r5J3Q66lC9G90y3vnvzdDyWnV9DKfa7jQ4aehilutJiqjWLRjkjZMUogsAN8YWCAD3bfOf3KxCfR16qcvQNwVvMrSWKyDNqphF4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D1VfuNIU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37DE44BA23EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792432684; 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=KEgQmd6d5lbp8/TAmA3XnWzl0BHQg5kkwnSQw5odJHc=; b=D1VfuNIUTk7md2SUGYaJd6UI5MZ8mITNFvLQa4efLgndn+YjH16V7t0yeyju1tdqATTpfu UwJ4PCyS7EfZF5V6/6jpBOxMaSO7y7Ng/8BBD4Q8SpFgQCfP8/7Nz2oy2gx7R2ov3vvJZK 5d+CPjeVdcDX14wetiUt9wmLzl++z0g= Received: from mail-vs1-f69.google.com (mail-vs1-f69.google.com [209.85.217.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-197-yMPoCrPaNO-aIis6jHjj3w-1; Mon, 19 Oct 2026 17:58:03 +0000 X-MC-Unique: yMPoCrPaNO-aIis6jHjj3w-1 X-Mimecast-MFC-AGG-ID: yMPoCrPaNO-aIis6jHjj3w_1792432682 Received: by mail-vs1-f69.google.com with SMTP id ada2fe7eead31-7bf5c02f7a3so190419137.2 for ; Mon, 19 Oct 2026 10:58:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792432682; x=1793037482; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KEgQmd6d5lbp8/TAmA3XnWzl0BHQg5kkwnSQw5odJHc=; b=aakYW1UWh0qrFzIyvIa51Sg3ea8/DcUPkbYW9FQa1mtm5gteihZGZJjw/lfMtN0reE mSBff5IXXEEBGay7DHAt1LpFXvDFSFXeg2orVvOfQbTmIDK8fJXh+MlKG+bRFabCOohR H19DUqAylO0MEcw8hGWznqB4sDoBdm5vlCSi0z+bBbt3b1ahqrx3mRvrpQ9QN7LrvvJe /2045gNwrbQWIKtydOdv7XsWpVJSpgXkyHT7fbaGuShcRyYHmixXF36jAeH0aWeeuVZi YB/f+EO0S4pLqdeMmPsVKD7ogJJ5pXbCg5oGsLzctlwH4XUTxXmJ1OudDjLIOoPM1qBw wKFA== X-Forwarded-Encrypted: i=1; AKwUvBzSR9oxOFsOIkD2k/N/hCiq7gTI4vKC1E4DPwJIvioTUSslJ2WxO6RwJLu9m7YgI0kESCQ+jEbBT71Grw==@sourceware.org X-Gm-Message-State: AFq9FYIXMRj7uBKSMCSeJTMdyvvhW8ivtuey7tQQG2hl6vCPxkAldd1L y9hjCR6nOxRGGfvdKReeDxiz1M/YcRMOuUonEPr+C2V1XFNoqgZJUWCbMeh19WjVrOZPAAw73mv +9gWHBsfGfe0azNd3gQyULPg3yzFgEE2rQqCJ+vAVYE7AFsc2lJ1NfCGYUAcF6Pc= X-Gm-Gg: AYBFou3RUvsG7fKCD4V3Ij/M0nGUpcNJN7rrhmrI3ZoguMDFXsXPZSdgL3qCOidQHyX eg+/wvZ3nvP9gvVNqWfQrIKr9vbpOq3+SqXvkqgCH2tiRVoHx32ufav45JEZBRt/YT9Su/20a6f Hgy4fk/FxJS7lAQh1AN8CeUiMBET9WDgqp0b8wS61HIjv8E15hMyJjrANEBDA6KYz4lgFE2P1/g 9B9gT+gY4JahxhJx/H8jjzxLdWmfTfl38bOuALOdjK+7FovPTUqIx9nkfAUz8zoWNRlpYy//K3v m5B7+1rgH0CoI5Pk+79QadZ2GTmv+u6jK1aypnElwXZ2bZH55SgwGb6EEgPAp7EARFxSxTpQViC FHx7JPJTHnRFRSbMN40Fa8zprh935J62NSAgXM21iqV1bfh9g X-Received: by 2002:a05:6102:5127:b0:7b3:6079:1900 with SMTP id ada2fe7eead31-7cc36b09d2dmr1774269137.37.1792432682211; Mon, 19 Oct 2026 10:58:02 -0700 (PDT) X-Received: by 2002:a05:6102:5127:b0:7b3:6079:1900 with SMTP id ada2fe7eead31-7cc36b09d2dmr1774262137.37.1792432681617; Mon, 19 Oct 2026 10:58:01 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:993e:22e8:4ed1:527a:55c0? ([2804:14d:8084:993e:22e8:4ed1:527a:55c0]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-990bb392504sm813650241.11.2026.10.19.10.57.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Oct 2026 10:58:00 -0700 (PDT) Message-ID: <8b70f4a3-cb1e-4fcc-b222-4c153833a4fc@redhat.com> Date: Mon, 19 Oct 2026 14:57:57 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] gdb, infcall, breakpoint: Handle cycles in conditional expr evaluation To: Mohamed Bouhaouel , gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com References: <20261002143505.38658-1-mohamed.bouhaouel@intel.com> From: Guinevere Larsen In-Reply-To: <20261002143505.38658-1-mohamed.bouhaouel@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _qbpowrBhEP8XNkgSmdP0xkfR-YNh0zXKtMSAul5jBE_1792432682 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 10/2/26 11:35 AM, Mohamed Bouhaouel wrote: > 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. > > 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 expression evaluation for the conditional bp: > A cycle was detected during the evaluation. > > 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 0x00005555555551af in main () at infcall-from-bp-cond-cycle.c:47 Hi! Thanks for working on this! I have a question, which may be somewhat silly, but... Why do we want a breakpoint to trigger if we're evaluating an inferior function call? To me, it seems like stopping on a call that wasn't generated by the inferior's execution is an anti-feature, but I recognize that this is based on my preference. If we agree that stopping on this isn't useful, then there's no need to look for cycles, making the fix simpler. If stopping is useful, I don't have comments on the changes themselves, they look ok tome, but I don't know enough to give a review tag, but I can confirm that it fixes the issue and doesn't cause problems, so feel free to add my test tag: Tested-By: Guinevere Larsen -- Cheers, Guinevere Larsen it/its she/her (deprecated) > --- > gdb/breakpoint.c | 14 +++- > gdb/gdbthread.h | 10 ++- > gdb/infcall.c | 2 +- > gdb/infrun.c | 6 +- > .../gdb.base/infcall-from-bp-cond-cycle.c | 51 +++++++++++++ > .../gdb.base/infcall-from-bp-cond-cycle.exp | 71 +++++++++++++++++++ > 6 files changed, 147 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 > > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index 0f5360c4ce5..a4ca10a95fe 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -6047,8 +6047,18 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) > { > try > { > - scoped_restore reset_in_cond_eval > - = make_scoped_restore (&thread->control.in_cond_eval, true); > + /* Check if we are already evaluating the same condition. This > + would lead to an infinite cycle. */ > + std::vector &cond_eval_bps > + = thread->control.cond_eval_bps; > + if (std::find (cond_eval_bps.begin (), cond_eval_bps.end (), b) > + != cond_eval_bps.end ()) > + error (_("Aborting expression evaluation for the " > + "conditional bp:\n" > + "A cycle was detected during the evaluation.")); > + > + cond_eval_bps.push_back (b); > + SCOPE_EXIT { cond_eval_bps.pop_back (); }; > condition_result = breakpoint_cond_eval (cond); > } > catch (const gdb_exception_error &ex) > diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h > index 51e9ae1b3f0..640c4a0fc2e 100644 > --- a/gdb/gdbthread.h > +++ b/gdb/gdbthread.h > @@ -234,8 +234,16 @@ struct thread_control_state > step" behaves like "on" or "off". */ > int stepping_command = 0; > > + /* A list of conditional breakpoints (if any) that the thread is evaluating. > + This list is tracking breakpoint hits during expression evaluation to make > + sure we don't run into cycles. */ > + std::vector cond_eval_bps; > + > /* True if the thread is evaluating a BP condition. */ > - bool in_cond_eval = false; > + bool in_cond_eval () const > + { > + return !cond_eval_bps.empty (); > + } > > private: > /* Function the thread was in as of last it started stepping. */ > diff --git a/gdb/infcall.c b/gdb/infcall.c > index 4c40f6cb06e..f4f15a946a6 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -865,7 +865,7 @@ run_inferior_call (std::unique_ptr sm, > > /* Setup a timer (if possible, and if the settings allow) to prevent > the inferior call running forever. */ > - bool direct_call_p = !call_thread->control.in_cond_eval; > + bool direct_call_p = !call_thread->control.in_cond_eval (); > infcall_timer_controller infcall_timer (call_thread, direct_call_p); > > /* Inferior function calls are always synchronous, even if the > diff --git a/gdb/infrun.c b/gdb/infrun.c > index 47966cf72db..c35e6d20532 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -2458,7 +2458,7 @@ user_visible_resume_ptid (int step) > resume_ptid = inferior_ptid; > } > else if (inferior_ptid != null_ptid > - && inferior_thread ()->control.in_cond_eval) > + && inferior_thread ()->control.in_cond_eval ()) > { > /* The inferior thread is evaluating a BP condition. Other threads > might be stopped or running and we do not want to change their > @@ -4711,7 +4711,7 @@ fetch_inferior_event () > /* Is the current thread performing an inferior function call as part > of a breakpoint condition evaluation? */ > bool in_cond_eval = (inferior_ptid != null_ptid > - && inferior_thread ()->control.in_cond_eval); > + && inferior_thread ()->control.in_cond_eval ()); > > /* If the thread is in the middle of the condition evaluation, wait for > an event from the current thread. Otherwise, wait for an event from > @@ -4780,7 +4780,7 @@ fetch_inferior_event () > function call as part of a condition evaluation, then we > don't want to stop all the other threads. */ > if (ecs.event_thread == nullptr > - || !ecs.event_thread->control.in_cond_eval) > + || !ecs.event_thread->control.in_cond_eval ()) > { > stop_all_threads_if_all_stop_mode (); > > diff --git a/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.c b/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.c > new file mode 100644 > index 00000000000..a9e270dc968 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.c > @@ -0,0 +1,51 @@ > +/* Copyright 2025-2026 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + 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 > +add_one (int a) > +{ > + return ++a; /* cond-bp-line. */ > +} > + > +int > +foo (int a) > +{ > + return a + add_one (a); > +} > + > +int > +bar (int a) > +{ > + return a + 100; > +} > + > +int > +baz (int a) > +{ > + return --a; > +} > + > +int > +main () > +{ > + int a = 10; > + int b = add_one (a); > + b += foo (b); > + b = bar (b) + baz (b); > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.exp b/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.exp > new file mode 100644 > index 00000000000..c67192165b0 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/infcall-from-bp-cond-cycle.exp > @@ -0,0 +1,71 @@ > +# Copyright 2025-2026 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 is able to detect a cycle when evaluating a conditional > +# breakpoint. In such a case, GDB should report the cycle and abort the > +# evaluation. > + > +require {!target_info exists gdb,cannot_call_functions} > + > +standard_testfile .c > + > +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { > + return -1 > +} > + > +set bp_line [gdb_get_line_number "cond-bp-line"] > +set conditional_bps [dict create \ > + direct-line [list "$bp_line if foo (1) == 2"] \ > + direct-func [list "foo if foo (1) == 2"] \ > + indirect-2 [list "foo if bar (1)" \ > + "bar if foo (1)"] \ > + indirect-3 [list "bar if baz (1)" \ > + "baz if add_one (1)" \ > + "add_one if bar (1)"]] > + > +foreach_with_prefix name [dict keys $conditional_bps] { > + set bps [dict get $conditional_bps $name] > + clean_restart $testfile > + if {![runto_main]} { > + return > + } > + foreach bp $bps { > + gdb_breakpoint $bp > + } > + gdb_test "continue" "A cycle was detected during the evaluation.*" > + > + delete_breakpoints > + set keep_going 1 > + set itr 0 > + while {$keep_going && $itr < 10} { > + set keep_going 0 > + gdb_test_multiple "backtrace" "check dummy frames: itr $itr" -lbl { > + -re "\r\n#$::decimal (?=\r\n)" { > + set keep_going 1 > + exp_continue > + } > + -re -wrap "" { > + pass $gdb_test_name > + } > + } > + if {$keep_going} { > + gdb_test "continue" "Continuing\\." "skip dummy frame: itr $itr" > + } > + incr itr > + } > + gdb_assert {!$keep_going} "no dummy frames left" > + > + gdb_continue_to_end > +}