Class: Connection::RubyDebug

Inherits:
Base
  • Object
show all
Defined in:
lib/rudebug/connection/ruby-debug.rb

Defined Under Namespace

Classes: Session

Constant Summary

Constants inherited from Base

Base::Code

Instance Attribute Summary

Attributes inherited from Base

#on_disconnect, #on_session

Instance Method Summary collapse

Methods inherited from Base

load_rudebug_code

Instance Method Details

#connect(server) ⇒ Object



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

def connect(server)
  require 'ruby-debug'
  require 'socket'
  require 'thread'

  host, port = */^(.+):(\d+)$/.match(server).captures
  port = port.to_i

  @socket = TCPSocket.new(host, port)
  line = @socket.gets
  location = location?(line)

  result = @socket.gets.strip rescue nil
  if !prompt?(result) then
    raise "Not a ruby-debug server"
  end

  @mutex = Mutex.new

  session = Session.new(self, location)
  @on_session.call(session)
end

#disconnectObject



125
126
127
128
129
130
131
132
# File 'lib/rudebug/connection/ruby-debug.rb', line 125

def disconnect()
  begin
    @socket.close
  rescue Exception
  end

  @socket = @mutex = nil
end

#execute(cmd) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rudebug/connection/ruby-debug.rb', line 113

def execute(cmd)
  @mutex.synchronize do
    @socket.puts(cmd)
    result = @socket.gets
    prompt = @socket.gets

    #p result
    #p [:prompt, prompt]
    return result
  end
end

#location?(line) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
111
# File 'lib/rudebug/connection/ruby-debug.rb', line 106

def location?(line)
  if md = /^(.+?):(\d+): /.match(line) then
    file, line = *md.captures
    [file, line.to_i]
  end
end

#prompt?(line) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/rudebug/connection/ruby-debug.rb', line 102

def prompt?(line)
  line[/^PROMPT /] rescue nil
end

#stepping_support?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/rudebug/connection/ruby-debug.rb', line 4

def stepping_support?()
  true
end