Module: Debugger

Defined in:
lib/ruby-debug-ide.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/jump.rb,
lib/ruby-debug/commands/load.rb,
lib/ruby-debug/commands/frame.rb,
lib/ruby-debug/commands/pause.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/set_type.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, JumpCommand, LoadCommand, NextCommand, PPCommand, PauseCommand, QuitCommand, RemoteInterface, RestartCommand, SetTypeCommand, 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.



81
82
83
# File 'lib/ruby-debug-ide.rb', line 81

def cli_debug
  @cli_debug
end

.control_threadObject (readonly)

Returns the value of attribute control_thread.



82
83
84
# File 'lib/ruby-debug-ide.rb', line 82

def control_thread
  @control_thread
end

.event_processorObject

Returns the value of attribute event_processor.



81
82
83
# File 'lib/ruby-debug-ide.rb', line 81

def event_processor
  @event_processor
end

.xml_debugObject

Returns the value of attribute xml_debug.



81
82
83
# File 'lib/ruby-debug-ide.rb', line 81

def xml_debug
  @xml_debug
end

Class Method Details

.debug_program(options) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ruby-debug-ide.rb', line 110

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



87
88
89
# File 'lib/ruby-debug-ide.rb', line 87

def interrupt
  current_context.interrupt
end

.interrupt_lastObject

Interrupts the last debugged thread



94
95
96
97
98
99
100
101
102
# File 'lib/ruby-debug-ide.rb', line 94

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.



20
21
22
23
24
25
26
# File 'lib/ruby-debug-ide.rb', line 20

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

.run_prog_scriptObject



130
131
132
133
134
135
# File 'lib/ruby-debug-ide.rb', line 130

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

.start_control(host, port) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/ruby-debug-ide.rb', line 137

def start_control(host, port)
  raise "Debugger is not started" unless started?
  return if @control_thread
  @control_thread = DebugThread.new do
    begin
      $stderr.printf "Fast Debugger (ruby-debug-ide 0.4.9) listens on #{host}:#{port}\n"
      # 127.0.0.1 seemingly works with all systems and with IPv6 as well.
      # "localhost" and nil on have problems on some systems.
      host ||= '127.0.0.1'
      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



104
105
106
107
108
# File 'lib/ruby-debug-ide.rb', line 104

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

.without_stderrObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby-debug-ide.rb', line 28

def without_stderr
  begin
    if RUBY_PLATFORM =~ /(win32|mingw32)/
      $stderr = File.open('NUL', 'w')
    else
      $stderr = File.open('/dev/null', 'w')
    end
    yield
  ensure
    $stderr = STDERR
  end
end