Class: IRB::ExtendCommand::Debug

Inherits:
Nop show all
Defined in:
lib/irb/cmd/debug.rb

Direct Known Subclasses

DebugCommand

Defined Under Namespace

Modules: SkipPathHelperForIRB

Constant Summary collapse

BINDING_IRB_FRAME_REGEXPS =
[
  '<internal:prelude>',
  binding.method(:irb).source_location.first,
].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
IRB_DIR =
File.expand_path('..', __dir__)

Instance Attribute Summary

Attributes inherited from Nop

#irb_context

Instance Method Summary collapse

Methods inherited from Nop

category, description, execute, #initialize, #irb

Constructor Details

This class inherits a constructor from IRB::ExtendCommand::Nop

Instance Method Details

#execute(pre_cmds: nil, do_cmds: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/irb/cmd/debug.rb', line 17

def execute(pre_cmds: nil, do_cmds: nil)
  unless binding_irb?
    puts "`debug` command is only available when IRB is started with binding.irb"
    return
  end

  unless setup_debugger
    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
    return
  end

  options = { oneshot: true, hook_call: false }
  if pre_cmds || do_cmds
    options[:command] = ['irb', pre_cmds, do_cmds]
  end
  if DEBUGGER__::LineBreakpoint.instance_method(:initialize).parameters.include?([:key, :skip_src])
    options[:skip_src] = true
  end

  # To make debugger commands like `next` or `continue` work without asking
  # the user to quit IRB after that, we need to exit IRB first and then hit
  # a TracePoint on #debug_break.
  file, lineno = IRB::Irb.instance_method(:debug_break).source_location
  DEBUGGER__::SESSION.add_line_breakpoint(file, lineno + 1, **options)
  # exit current Irb#run call
  throw :IRB_EXIT
end