`next` / `step` / `finish` are cancelled at a line whose breakpoint does not stop there (e.g. a false condition), and the program runs on

未關閉
#1,191 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
ruby
領域
devtools

研究方向

The report identifies ThreadClient#step_tp in lib/debug/thread_client.rb and Session#stop_stepping? in lib/debug/session.rb as the relevant paths, with breakpoint event and condition handling in lib/debug/breakpoint.rb. Read those checks alongside the behavior introduced by #784, then reproduce the listed next, step, and finish cases. Done means stepping completes as it does without the extra breakpoint, while breakpoints that do fire still stop execution.

由索引模型根據 Issue 內容生成。

描述

next, step and finish are cancelled when the step meets an event on a line that has a breakpoint, even when that breakpoint does not stop on that event (its condition is false, or it is bound to another event). Nothing stops the program after that: it runs to its end, or to the next breakpoint that does fire, possibly in a later call.

Your environment

  • ruby -v: ruby 4.0.10 (2026-11-19 revision a704b7cd95) +PRISM [x86_64-linux] (official ruby:4.0 Docker image); the same with ruby 3.4.13 (2026-11-19 revision 48857d6f2e) +PRISM [x86_64-linux]; with ruby 3.3.14 every case but case 3 (below).
  • rdbg -v: rdbg 1.11.1 (gem install debug -v 1.11.1). Cases 1 to 3 also on Windows, ruby 3.4.9 [x64-mingw-ucrt] with debug 1.11.0.

To Reproduce

target.rb:

def calc(x)
  a = x + 1
  b = a + 1
  c = b + 1
  return c
end

def helper(x)
  y = x * 2
  y + 1
end

def run
  n = $n
  v = helper(n)
  calc(v)
end

$n = 0
while $n < 3
  puts "run #{$n} => #{run}"
  $n += 1
end

Case 1, next onto a line whose breakpoint condition is false. Run from the directory of target.rb; the script has to be named by its absolute path (see the second details block):

rdbg --no-rc --no-color -e 'b 3 if: $n == 1' -e 'b 4 if: $n == 99' -e c -e next -e 'p $n' -e 'q!' "$PWD/target.rb"

Its output from the breakpoint stop on, and the same for the control run without -e 'b 4 if: $n == 99' (Ruby 4.0.10; [source listing] stands for the ten-line listing rdbg prints at a stop):

with b 4 if: $n == 99: the program runs to its endcontrol: next stops at line 4
Stop by #0  BP - Line  /tmp/repro/target.rb:3 (line) if: $n == 1
(rdbg:commands) next
run 1 => 6
run 2 => 8
Stop by #0  BP - Line  /tmp/repro/target.rb:3 (line) if: $n == 1
(rdbg:commands) next
[source listing]
=>#0	Object#calc(x=3) at /tmp/repro/target.rb:4
  #1	Object#run at /tmp/repro/target.rb:16
  # and 1 frames (use `bt' command for all frames)
(rdbg:commands) p $n
=> 1
(rdbg:commands) q!

Expected behavior

Each step completes where it does without the extra breakpoint. The other cases, same program, each stopped first in the call with $n == 1 (commands and output in the first details block):

case expected actual
1 with step instead of next stops at line 4, $n == 1 runs to the end
2. next over helper(n) from line 15: b 15 if: $n == 1, b 10 if: $n == 99 stops at line 16 runs to the end
3. finish from return c: b 5 if: $n == 1 stops at the return of calc, #=> 6 (as it does when the breakpoint is deleted first) runs to the end; with an unconditional b 5, Stop by #0 on line 5 in the next call
4. next from line 2: b 2 if: $n == 1 (reported as (call)), b 4 if: $n == 1 stops at line 3 Stop by #1 on line 4; line 3 ran without a stop

Additional context

The cause, read in v1.11.1 (master at 6510cfbc has the same lines):

  • Every step command installs one TracePoint in ThreadClient#step_tp, and its first act on every event is tp.disable when SESSION.stop_stepping? is true: thread_client.rb#L344-L348. This comes before the step's own filter (#L349), so it also applies inside a call that next steps over (case 2).
  • Session#stop_stepping? is true whenever @bps.has_key? [file, line]: session.rb#L158-L166. Nothing asks whether that breakpoint will suspend on this event; a line breakpoint is a TracePoint for one event type, with its condition checked in its own hook (breakpoint.rb#L165-L181).
  • #784 (first released in v1.7.0) changed this line from next if SESSION.break_at? tp.path, tp.lineno, which skipped this one event and kept stepping (v1.6.3 thread_client.rb#L334), into tp.disable, which ends the step.

#874 loses a next through the other half of the same check: debugger do: enters a subsession, and the changed subsession id cancels the step. Here no subsession is entered; the @bps.has_key? half cancels the step because a breakpoint exists on the line, whether or not it fires.

The other cases: commands and output (Ruby 4.0.10)
$ rdbg --no-rc --no-color -e 'b 3 if: $n == 1' -e 'b 4 if: $n == 99' -e c -e step -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:3 (line) if: $n == 1
(rdbg:commands) step
run 1 => 6
run 2 => 8
$ rdbg --no-rc --no-color -e 'b 15 if: $n == 1' -e 'b 10 if: $n == 99' -e c -e next -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:15 (line) if: $n == 1
(rdbg:commands) next
run 1 => 6
run 2 => 8
$ rdbg --no-rc --no-color -e 'b 5 if: $n == 1' -e c -e finish -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:5 (line) if: $n == 1
(rdbg:commands) finish
run 1 => 6
run 2 => 8
$ rdbg --no-rc --no-color -e 'b 5' -e c -e 'p $n' -e finish -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:5 (line)
(rdbg:commands) p $n
=> 0
(rdbg:commands) finish
run 0 => 4
[source listing]
=>#0	Object#calc(x=3) at /tmp/repro/target.rb:5
  #1	Object#run at /tmp/repro/target.rb:16
  # and 1 frames (use `bt' command for all frames)

Stop by #0  BP - Line  /tmp/repro/target.rb:5 (line)
(rdbg:commands) p $n
=> 1
(rdbg:commands) q!
$ rdbg --no-rc --no-color -e 'b 2 if: $n == 1' -e 'b 4 if: $n == 1' -e c -e next -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:2 (call) if: $n == 1
(rdbg:commands) next
[source listing]
=>#0	Object#calc(x=3) at /tmp/repro/target.rb:4
  #1	Object#run at /tmp/repro/target.rb:16
  # and 1 frames (use `bt' command for all frames)

Stop by #1  BP - Line  /tmp/repro/target.rb:4 (line) if: $n == 1
(rdbg:commands) p $n
=> 1
(rdbg:commands) q!
Spy on stop_stepping?, why the script path matters, Ruby 3.3

A spy loaded with -x spy.cmds before the -e commands:

eval DEBUGGER__::SESSION.singleton_class.prepend(Module.new { def stop_stepping?(f, l, s = nil); r = super; ks = @bps.keys.select { |k| k.is_a?(Array) && k[1] == l }; STDERR.puts "SPY stop_stepping?(#{f.inspect}, #{l}) => #{r}; breakpoint keys for line #{l}: #{ks.inspect}"; r; end })

It printed, right before the program ran on (or stopped at the second breakpoint in case 4):

case 1: SPY stop_stepping?("/tmp/w/target.rb", 4) => true; breakpoint keys for line 4: [["/tmp/w/target.rb", 4]]
case 2: SPY stop_stepping?("/tmp/w/target.rb", 9) => false; breakpoint keys for line 9: []
case 2: SPY stop_stepping?("/tmp/w/target.rb", 10) => true; breakpoint keys for line 10: [["/tmp/w/target.rb", 10]]
case 3: SPY stop_stepping?("/tmp/w/target.rb", 5) => true; breakpoint keys for line 5: [["/tmp/w/target.rb", 5]]
case 4: SPY stop_stepping?("/tmp/w/target.rb", 2) => true; breakpoint keys for line 2: [["/tmp/w/target.rb", 2]]

In case 4 the true is for line 2, the line the next was issued from, whose key belongs to the (call) breakpoint; in its control (no breakpoint on line 4) the first line asked about is line 3 (false), and next stops there.

The breakpoint's key is built from iseq.absolute_path (breakpoint.rb#L192-L194), and stop_stepping? is called with tp.path. Started as rdbg ... target.rb, case 1 stops at line 4, and the spy printed:

SPY stop_stepping?("target.rb", 4) => false; breakpoint keys for line 4: [["/tmp/w/target.rb", 4]]

Two more runs with that in mind:

  • Relative path, b 3, b 4 (both unconditional), c, next: next stops at line 4 as a step, and c then stops at line 4 again (Stop by #1, $n still 0). With the absolute path the same commands stop at line 4 once.
  • A file loaded with require_relative loses the step even when the main script is named relatively (Ruby 4.0.10, calc moved to req_lib.rb, breakpoints on its lines 3 and 4 as in case 1: next runs to the end).

Ruby 3.3.14 reports the return event of calc on line 6 (end), so case 3 does not reproduce there:

$ rdbg --no-rc --no-color -e 'b 5 if: $n == 1' -e c -e finish -e 'p $n' -e 'q!' /tmp/repro/target.rb
Stop by #0  BP - Line  /tmp/repro/target.rb:5 (line) if: $n == 1
(rdbg:commands) finish
[source listing]
=>#0	Object#calc(x=3) at /tmp/repro/target.rb:6 #=> 6
  #1	Object#run at /tmp/repro/target.rb:16
  # and 1 frames (use `bt' command for all frames)
(rdbg:commands) p $n
=> 1
(rdbg:commands) q!

Found while building mcp-debugger, which drives rdbg over DAP and launches the script by its absolute path (debugmcp/mcp-debugger#1197). No patch is proposed; none was written or tested.


Disclosure: this report was prepared by an AI coding agent working for the mcp-debugger project. The reproduction above was run and the linked source lines were read as stated; nothing in it is inferred without a run or a source read.

主要語言
Ruby
星號
1.3k
分支
151
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ruby/debug 的其他 Issue

查看 ruby/debug 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。