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

.cli_debugObject

Returns the value of attribute cli_debug.



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

def cli_debug
  @cli_debug
end

.control_threadObject (readonly)

Returns the value of attribute control_thread.



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

def control_thread
  @control_thread
end

.event_processorObject

Returns the value of attribute event_processor.



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

def event_processor
  @event_processor
end

.xml_debugObject

Returns the value of attribute xml_debug.



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

def xml_debug
  @xml_debug
end

Class Method Details

.debug_program(options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ruby-debug.rb', line 90

def debug_program(options)
  start_server(options.host, options.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
  
  bt = debug_load(Debugger::PROG_SCRIPT, options.stop, options.load_mode)
  if bt
    $stderr.print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
    $stderr.print "Uncaught exception: #{bt}\n"
  end
end

.interruptObject

Interrupts the current thread



67
68
69
# File 'lib/ruby-debug.rb', line 67

def interrupt
  current_context.interrupt
end

.interrupt_lastObject

Interrupts the last debugged thread



74
75
76
77
78
79
80
81
82
# File 'lib/ruby-debug.rb', line 74

def interrupt_last
  skip do
    if context = last_context
      return nil unless context.thread.alive?
      context.interrupt
    end
    context
  end
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.cli_debug
    $stderr.printf(*args)
    $stderr.printf("\n")
    $stderr.flush
  end
end

.run_prog_scriptObject



110
111
112
113
114
115
# File 'lib/ruby-debug.rb', line 110

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

.start_control(host, port) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ruby-debug.rb', line 117

def start_control(host, port)
  raise "Debugger is not started" unless started?
  return if @control_thread
  @control_thread = DebugThread.new do
    begin
      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
      $stderr.printf "Fast Debugger (ruby-debug-ide 0.4.6) listens on #{host}:#{port}\n"
      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
          $stderr.printf "Exception in DebugThread loop: #{ex}\n"
          exit 1
        end
      end
    rescue
      $stderr.printf "Exception in DebugThread: #$!\n"
      exit 2
    end
  end
end

.start_server(host = nil, port = 1234) ⇒ Object



84
85
86
87
88
# File 'lib/ruby-debug.rb', line 84

def start_server(host = nil, port = 1234)
  return if started?
  start
  start_control(host, port)
end