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.



12
13
14
15
# File 'lib/ruby-debug/processor.rb', line 12

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

Instance Method Details



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

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

#process_commandsObject



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

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



49
50
51
52
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
# File 'lib/ruby-debug/processor.rb', line 49

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ruby-debug/processor.rb', line 85

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