Class: Debugger::ControlCommandProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/ruby-debug/processor.rb

Overview

:nodoc:

Defined Under Namespace

Classes: State

Instance Attribute Summary

Attributes inherited from Processor

#interface

Instance Method Summary collapse

Methods inherited from Processor

#afmt, #aprint, #errmsg, #print, print, protect, #split_commands

Constructor Details

#initialize(interface) ⇒ ControlCommandProcessor

Returns a new instance of ControlCommandProcessor.



401
402
403
404
405
# File 'lib/ruby-debug/processor.rb', line 401

def initialize(interface)
  super()
  @interface = interface
  @debugger_context_was_dead = true # Assume we haven't started.
end

Instance Method Details

#process_commands(verbose = false) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/ruby-debug/processor.rb', line 407

def process_commands(verbose=false)
  control_cmds = Command.commands.select do |cmd|
    cmd.allow_in_control
  end
  state = State.new(@interface, control_cmds)
  commands = control_cmds.map{|cmd| cmd.new(state) }

  unless @debugger_context_was_dead
    if Debugger.annotate.to_i > 2
      aprint 'exited'
      print "The program finished.\n"
    end
    @debugger_context_was_dead = true
  end

  while input = @interface.read_command(prompt(nil))
    print "+#{input}" if verbose
    catch(:debug_error) do
      if cmd = commands.find{|c| c.match(input) }
        cmd.execute
      else
        errmsg "Unknown command\n"
      end
    end
  end
rescue IOError, Errno::EPIPE
rescue Exception
  print "INTERNAL ERROR!!! #{$!}\n" rescue nil
  print $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
ensure
  @interface.close
end

#prompt(context) ⇒ Object

The prompt shown before reading a command. Note: have an unused ‘context’ parameter to match the local interface.



442
443
444
445
446
447
# File 'lib/ruby-debug/processor.rb', line 442

def prompt(context)
  p = '(rdb:ctrl) '
  p = afmt("pre-prompt")+p+"\n"+afmt("prompt") if
    Debugger.annotate.to_i > 2
  return p
end