Method: DEBUGGER__::Client#connect

Defined in:
lib/debug/client.rb

#connectObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/debug/client.rb', line 196

def connect
  pre_commands = (CONFIG[:commands] || '').split(';;')

  trap(:SIGINT){
    send "pause"
  }

  begin
    trap(:SIGWINCH){
      @width = IO.console_size[1]
    }
  rescue ArgumentError
    @width = 80
  end

  while line = @s.gets
    p recv: line if $VERBOSE
    case line

    when /^out (.*)/
      puts "#{$1}"

    when /^input (.+)/
      pid = $1
      @multi_process = true if @pid && @pid != pid
      @pid = pid
      prev_trap = trap(:SIGINT, 'DEFAULT')

      begin
        if pre_commands.empty?
          line = readline
        else
          line = pre_commands.shift
          puts "(rdbg:remote:command) #{line}"
        end
      rescue Interrupt
        retry
      ensure
        trap(:SIGINT, prev_trap)
      end

      line = (line || 'quit').strip
      send "command #{pid} #{@width} #{line}"

    when /^ask (\d+) (.*)/
      pid = $1
      print $2
      send "answer #{pid} #{$stdin.gets || ''}"

    when /^quit/
      raise 'quit'

    else
      puts "(unknown) #{line.inspect}"
    end
  end
rescue => e
  STDERR.puts "disconnected (#{e})"
  exit
ensure
  deactivate
end