Hi Kevin, Thanks for testing and for the factorial example. You're right that terminating recursion shouldn't be unconditionally rejected! Since a real cycle can't be distinguished from finite recursion in general, I'll replace the check with a depth limit, similar to "max-user-call-depth" (a new "set max-breakpoint-condition-depth" setting, accepting "unlimited"). I'll add your example to the test and reword "bp" to "breakpoint" in the message. Thanks, --Mohamed ________________________________ From: Kevin Buettner Sent: Tuesday, November 17, 2026 6:16 AM To: Bouhaouel, Mohamed ; gdb-patches@sourceware.org Cc: Ijaz, Abdul B Subject: Re: [PATCH 1/1] gdb, infcall, breakpoint: Handle cycles in conditional expr evaluation On 10/2/26 7: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 My AI reviewer found a case which probably ought to be allowed. Perhaps a depth setting could be added? Alternately, a setting which disables cycle detection? The example uses factorial from gdb.base/break.c. Using the baseline build (without your patch): $ /home/kevinb-claude/installs/cycles-baseline/bin/gdb \ -q -nx -batch -iex 'set debuginfod enabled off' \ -ex 'break factorial if value > 1 && factorial (value - 1) > 100' \ -ex run -ex bt ./break Breakpoint 1 at 0x40055b: file break.c, line 63. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1, factorial (value=6) at break.c:63 63 if (value > 1) { /* set breakpoint 7 here */ #0 factorial (value=6) at break.c:63 #1 0x00000000004004f8 in main (argc=1, argv=0x7fffffffd238, envp=0x7fffffffd248) at break.c:47 Note that this worked perfectly well, but... With your patch: $ /home/kevinb-claude/installs/cycles-patched/bin/gdb \ -q -nx -batch -iex 'set debuginfod enabled off' \ -ex 'break factorial if value > 1 && factorial (value - 1) > 100' \ -ex run -ex bt ./break Breakpoint 1 at 0x40055b: file break.c, line 63. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Error in testing condition for breakpoint 1: Aborting expression evaluation for the conditional bp: A cycle was detected during the evaluation. Breakpoint 1, factorial (value=5) at break.c:63 63 if (value > 1) { /* set breakpoint 7 here */ Error in testing condition for breakpoint 1: The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function (factorial) will be abandoned. When the function is done executing, GDB will silently stop. #0 factorial (value=5) at break.c:63 #1 #2 factorial (value=6) at break.c:63 #3 0x00000000004004f8 in main (argc=1, argv=0x7fffffffd238, envp=0x7fffffffd248) at break.c:47 In any case, it'd be nice to have a way to run cases like this which terminate naturally. Also, I think that it'd be better if the new error message would use the word "breakpoint" instead of "bp". The AI mentioned that some wording involving "reentry" would be preferable to "cycle", but I find that your wording (with cycle) better conveys the problem to me. Kevin ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.