Class: Debugger::ControlCommandProcessor

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(interface) ⇒ ControlCommandProcessor

Returns a new instance of ControlCommandProcessor.



16
17
18
19
# File 'lib/ruby-debug/processor.rb', line 16

def initialize(interface)
  @interface = interface
  @printer = XmlPrinter.new(@interface)
end

Instance Method Details



21
22
23
# File 'lib/ruby-debug/processor.rb', line 21

def print(*args)
  @interface.print(*args)
end

#process_commandsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby-debug/processor.rb', line 25

def process_commands
  @printer.print_debug("Starting command read loop")
  ctrl_cmd_classes = Command.commands.select{|cmd| cmd.control}
  state = ControlState.new(@interface)
  ctrl_cmds = ctrl_cmd_classes.map{|cmd| cmd.new(state, @printer)}
  
  while input = @interface.read_command
    # escape % since print_debug might use printf
    @printer.print_debug "Processing: #{input.gsub('%', '%%')}"
    # sleep 0.3
    catch(:debug_error) do
      if cmd = ctrl_cmds.find{|c| c.match(input) }
        cmd.execute
      else
        process_context_commands(input)
      end
    end
  end
rescue IOError, Errno::EPIPE
  @printer.print_error "INTERNAL ERROR!!! #{$!}\n" rescue nil
  @printer.print_error $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
rescue Exception
  @printer.print_error "INTERNAL ERROR!!! #{$!}\n" rescue nil
  @printer.print_error $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
ensure
  @interface.close
end

#process_context_commands(input) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby-debug/processor.rb', line 53

def process_context_commands(input)
  unless Debugger.event_processor.at_line?
    @printer.print_error "There is no thread suspended at the time and therefore no context to execute '#{input.gsub('%', '%%')}'"
    return
  end
  context = Debugger.event_processor.context
  file = Debugger.event_processor.file
  line = Debugger.event_processor.line
  event_cmds_classes = Command.commands.select{|cmd| cmd.event}
  state = State.new do |s|
    s.context = context
    s.file    = file
    s.line    = line
    s.binding = context.frame_binding(0)
    s.interface = @interface
  end
  event_cmds = event_cmds_classes.map{|cmd| cmd.new(state, @printer) }
  catch(:debug_error) do
    splitter[input].each do |input|
      # escape % since print_debug might use printf
      @printer.print_debug "Processing context: #{input.gsub('%', '%%')}"
      if cmd = event_cmds.find{ |c| c.match(input) }
        if context.dead? && cmd.class.need_context
          @printer.print_msg "Command is unavailable\n"
        else
          cmd.execute
        end
      else
        @printer.print_msg "Unknown command: #{input}"
      end
    end
  end
  
  context.thread.run if state.proceed?
end

#splitterObject



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

def splitter
  return lambda do |str|
    str.split(/;/).inject([]) do |m, v|
      if m.empty?
        m << v
      else
        if m.last[-1] == ?\\
          m.last[-1,1] = ''
          m.last << ';' << v
        else
          m << v
        end
      end
      m
    end
  end
end