Feature Request: Push debugger activation to first breakpoint hit instead of `require "debug"`
还没有人认领这个 Issue。
评估
调研方向
Start by reading lib/debug.rb and the Kernel#debugger implementation in lib/debug/session.rb, then trace how require "debug", require "debug/prelude", and the open variants initialize sessions. Verify the proposed behavior against activation, TracePoint, thread, UI, and forking-message concerns described in the issue. Done means requiring debug is passive while the first breakpoint activates the debugger without changing the open variants.
由索引模型根据 Issue 内容生成。
描述
Proposal
require "debug"won't activate the debugger. Debugger will only be activated when the first breakpoint is triggered.require "debug"will be the same asrequire "debug/prelude"
require "debug/open"andrequire "debug/open_nonstop"'s behaviour will remain the same.
Why
Side-effects
In apps that have Bundler.require, like most Rails apps, having gem "debug" in Gemfile means the debug gem is always activated when the app is booted.
However, with the debugger's activation, many things will happen in the background:
- Additional
TracePoints would be enabled (example) - A new thread will be spawned
- Additional computation and object allocation that come with the above
To most apps, having them in the background doesn't make a huge difference. But to some, having the debugger activated causes tests to fail.
For example, I tested 5 mid-to-large Rails apps in Shopify, and 3 of them have test failures that only happen when debug is activated:
- Some tests mock
File.readlinesand could break when this line is triggered in the background. - There's also weird
NoMethodErrorexceptions that only happens with the debugger activated.
Therefore, we always have require: false after gem "debug".
Problem Solved?
However, having require: false means users need to manually type require "debug" before start debugging with console. But in the meantime, byebug can be required by default without the same side-effects. So byebug doesn't need that manual require.
This extra require step is quite inconvenient for people considering switching from byebug to debug.
Other Smaller Issues
- The activation and forking messages are noisy and disabling them project-by-project is not trivial.
require "debug"locks the UI to console, so if users want to use the remote UI by requiringdebug/openafter the app is booted,require: falseis also needed.
Possible Change
diff --git a/lib/debug.rb b/lib/debug.rb
index 15ebccb..3489268 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -1,5 +1,3 @@
# frozen_string_literal: true
require_relative 'debug/session'
-return unless defined?(DEBUGGER__)
-DEBUGGER__::start no_sigint_hook: true, nonstop: true
diff --git a/lib/debug/session.rb b/lib/debug/session.rb
index a900f89..ffb2604 100644
--- a/lib/debug/session.rb
+++ b/lib/debug/session.rb
@@ -2486,7 +2486,9 @@ end
module Kernel
def debugger pre: nil, do: nil, up_level: 0
- return if !defined?(::DEBUGGER__::SESSION) || !::DEBUGGER__::SESSION.active?
+ if !defined?(::DEBUGGER__::SESSION) || !::DEBUGGER__::SESSION.active?
+ DEBUGGER__::start no_sigint_hook: true, nonstop: true
+ end
if pre || (do_expr = binding.local_variable_get(:do))
cmds = ['binding.break', pre, do_expr]
- 主要语言
- Ruby
- 星标
- 1.3k
- 派生
- 146
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/debug 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 68/100
-
Support exceptionOptions in setExceptionBreakpoints to catch arbitrary exception classes via DAP 未关闭
难度 4/5 3-5 天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 52/100
-
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
バグ
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 75/100
voxpupuli/puppet-epel#186 · 1 条评论 ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) 未关闭Bug Frontend
难度 2/5 1-3 小时 新手友好度 78/100