Class: Debugger::IdeCommandProcessor

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

Direct Known Subclasses

IdeControlCommandProcessor

Instance Method Summary collapse

Constructor Details

#initialize(interface = nil) ⇒ IdeCommandProcessor

Returns a new instance of IdeCommandProcessor.



6
7
8
9
# File 'lib/ruby-debug-ide/ide_processor.rb', line 6

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

Instance Method Details



11
12
13
# File 'lib/ruby-debug-ide/ide_processor.rb', line 11

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

#process_commandsObject



15
16
17
18
19
20
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
48
49
50
51
52
53
# File 'lib/ruby-debug-ide/ide_processor.rb', line 15

def process_commands
  unless Debugger.handler.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.handler.context
  file = Debugger.handler.file
  line = Debugger.handler.line
  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 = Command.commands.map{|cmd| cmd.new(state, @printer) }
  until state.proceed? do
    input = @interface.command_queue.pop
    catch(:debug_error) do
      splitter[input].each do |input|
        # escape % since print_debug might use printf
        @printer.print_debug "Processing in 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
    state.restore_context
  end
rescue ::Exception
  @printer.print_error "INTERNAL ERROR!!! #{$!}\n" rescue nil
  @printer.print_error $!.backtrace.map{|l| "\t#{l}"}.join("\n") rescue nil
end

#splitterObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ruby-debug-ide/ide_processor.rb', line 55

def splitter
  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