Module: Debugger

Defined in:
lib/ruby-debug.rb,
lib/ruby-debug/helper.rb,
lib/ruby-debug/command.rb,
lib/ruby-debug/interface.rb,
lib/ruby-debug/processor.rb,
lib/ruby-debug/xml_printer.rb,
lib/ruby-debug/commands/eval.rb,
lib/ruby-debug/commands/load.rb,
lib/ruby-debug/commands/frame.rb,
lib/ruby-debug/commands/enable.rb,
lib/ruby-debug/event_processor.rb,
lib/ruby-debug/commands/control.rb,
lib/ruby-debug/commands/inspect.rb,
lib/ruby-debug/commands/threads.rb,
lib/ruby-debug/commands/stepping.rb,
lib/ruby-debug/commands/condition.rb,
lib/ruby-debug/commands/variables.rb,
lib/ruby-debug/commands/catchpoint.rb,
lib/ruby-debug/commands/breakpoints.rb

Defined Under Namespace

Modules: EnableDisableFunctions, FrameFunctions, Kernel, ParseFunctions Classes: AddBreakpoint, BreakpointsCommand, CatchCommand, Command, ConditionCommand, Context, ContinueCommand, ControlCommandProcessor, ControlState, DeleteBreakpointCommand, DisableCommand, DownCommand, EnableCommand, EvalCommand, EventProcessor, Exception, FinishCommand, FrameCommand, InspectCommand, InterruptCommand, LoadCommand, NextCommand, PPCommand, QuitCommand, RemoteInterface, RestartCommand, StartCommand, State, StepCommand, ThreadCurrentCommand, ThreadListCommand, ThreadResumeCommand, ThreadStopCommand, ThreadSwitchCommand, UpCommand, VarConstantCommand, VarGlobalCommand, VarInstanceCommand, VarLocalCommand, WhereCommand, XmlPrinter

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.control_threadObject (readonly)

Returns the value of attribute control_thread.



57
58
59
# File 'lib/ruby-debug.rb', line 57

def control_thread
  @control_thread
end

.event_processorObject

Returns the value of attribute event_processor.



56
57
58
# File 'lib/ruby-debug.rb', line 56

def event_processor
  @event_processor
end

.is_debugObject

Returns the value of attribute is_debug.



56
57
58
# File 'lib/ruby-debug.rb', line 56

def is_debug
  @is_debug
end

Class Method Details

.interruptObject

Interrupts the current thread



62
63
64
# File 'lib/ruby-debug.rb', line 62

def interrupt
  current_context.interrupt
end

.interrupt_lastObject

Interrupts the last debugged thread



69
70
71
72
73
74
75
76
77
# File 'lib/ruby-debug.rb', line 69

def interrupt_last
  skip do
    if context = last_context
      return nil unless context.thread.alive?
      context.interrupt
    end
    context
  end
end

.main(host, port) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ruby-debug.rb', line 79

def main(host, port)
  return if started?
  
  start
  
  start_control(host, port)
  
  raise "Control thread did not start (#{@control_thread}}" unless @control_thread && @control_thread.alive?
  
  @mutex = Mutex.new
  @proceed = ConditionVariable.new
  
  # wait for 'start' command
  @mutex.synchronize do
    @proceed.wait(@mutex)
  end
  
  debug_load Debugger::PROG_SCRIPT
end

Prints to the stderr using printf(*args) if debug logging flag (-d) is on.



14
15
16
17
18
19
20
# File 'lib/ruby-debug.rb', line 14

def print_debug(*args)
  if Debugger.is_debug
    $stderr.printf(*args)
    $stderr.printf("\n")
    $stderr.flush
  end
end

.run_prog_scriptObject



99
100
101
102
103
# File 'lib/ruby-debug.rb', line 99

def run_prog_script
  @mutex.synchronize do
    @proceed.signal
  end
end

.start_control(host, port) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ruby-debug.rb', line 105

def start_control(host, port)
  raise "Debugger is not started" unless started?
  return if @control_thread
  @control_thread = DebugThread.new do
    unless RUBY_PLATFORM =~ /darwin/i # Mac OS X seems to have problem with 'localhost'
      host ||= 'localhost' # nil does not seem to work for IPv6, localhost does
    end
    Debugger.print_debug("Waiting for connection on '#{host}:#{port}'")
    $stderr.puts "Fast Debugger (ruby-debug-ide 0.2.1) listens on #{host}:#{port}"
    server = TCPServer.new(host, port)
    while (session = server.accept)
      begin
        interface = RemoteInterface.new(session)
        @event_processor = EventProcessor.new(interface)
        ControlCommandProcessor.new(interface).process_commands
      rescue StandardError, ScriptError => ex
        puts ex
      end
    end
  end
end