Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>,
	gdb-patches@sourceware.org
Cc: abdul.b.ijaz@intel.com
Subject: Re: [PATCH 1/1] gdb, infcall, breakpoint: Handle cycles in conditional expr evaluation
Date: Mon, 16 Nov 2026 22:16:54 -0700	[thread overview]
Message-ID: <afcac469-a07f-4cbb-bf8f-ada75e90a03a@redhat.com> (raw)
In-Reply-To: <20261002143505.38658-1-mohamed.bouhaouel@intel.com>



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  <function called from gdb>
>   #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  <function called from gdb>
#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


  parent reply	other threads:[~2026-11-17  5:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 14:35 Mohamed Bouhaouel
2026-10-19  9:38 ` [PING 1][PATCH " Bouhaouel, Mohamed
2026-10-19 17:57 ` [PATCH " Guinevere Larsen
2026-10-20 16:50   ` Bouhaouel, Mohamed
2026-11-17  5:16 ` Kevin Buettner [this message]
2026-11-20  8:28   ` Bouhaouel, Mohamed
2026-11-20 13:26     ` Bouhaouel, Mohamed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afcac469-a07f-4cbb-bf8f-ada75e90a03a@redhat.com \
    --to=kevinb@redhat.com \
    --cc=abdul.b.ijaz@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mohamed.bouhaouel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox