diff options
author | Stan Lo <stan001212@gmail.com> | 2022-11-18 09:11:19 +0000 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-11-18 09:11:23 +0000 |
commit | 00872d120b017de2270fe18068cea2d37d41ed71 (patch) | |
tree | c346ab6256c7ed0c0aac9814daea88e16fdd9d26 /lib/irb/cmd | |
parent | a80b66e7ebf1179964b416cee6fd236048a73dcf (diff) |
[ruby/irb] Add debug command (https://github.com/ruby/irb/pull/446)
https://github.com/ruby/irb/commit/30faa13fa3
Diffstat (limited to 'lib/irb/cmd')
-rw-r--r-- | lib/irb/cmd/debug.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/irb/cmd/debug.rb b/lib/irb/cmd/debug.rb new file mode 100644 index 0000000000..8aab40cf84 --- /dev/null +++ b/lib/irb/cmd/debug.rb @@ -0,0 +1,33 @@ +require_relative "nop" + +module IRB + # :stopdoc: + + module ExtendCommand + class Debug < Nop + def execute(*args) + require "debug/session" + DEBUGGER__.start(nonstop: true) + DEBUGGER__.singleton_class.send(:alias_method, :original_capture_frames, :capture_frames) + + def DEBUGGER__.capture_frames(skip_path_prefix) + frames = original_capture_frames(skip_path_prefix) + frames.reject! do |frame| + frame.realpath&.start_with?(::IRB::Irb::DIR_NAME) || frame.path.match?(/internal:prelude/) + end + frames + end + + file, lineno = IRB::Irb.instance_method(:debug_break).source_location + DEBUGGER__::SESSION.add_line_breakpoint(file, lineno + 1, oneshot: true, hook_call: false) + # exit current Irb#run call + throw :IRB_EXIT + rescue LoadError => e + puts <<~MSG + You need to install the debug gem before using this command. + If you use `bundle exec`, please add `gem "debug"` into your Gemfile. + MSG + end + end + end +end |