lib/ruby-debug/processor.rb in ruby-debug-ide-0.4.16 vs lib/ruby-debug/processor.rb in ruby-debug-ide-0.4.17.beta3

- old
+ new

@@ -5,91 +5,68 @@ require_relative 'interface' require_relative 'command' end module Debugger - # this class is added to resolve problems, with ruby-debug gem incompatibility see - # http://rubyforge.org/tracker/index.php?func=detail&aid=27055&group_id=3085&atid=11903 class CommandProcessor - end - - class ControlCommandProcessor # :nodoc: - def initialize(interface) + def initialize(interface = nil) @interface = interface @printer = XmlPrinter.new(@interface) end - + def print(*args) @interface.print(*args) end - + 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 - - 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" + event_cmds = Command.commands.map{|cmd| cmd.new(state, @printer) } + while !state.proceed? do + input = @interface.command_queue.empty? ? nil : @interface.command_queue.shift + unless input + sleep 0.1 + next + end + 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 - cmd.execute + @printer.print_msg "Unknown command: #{input}" end - else - @printer.print_msg "Unknown command: #{input}" end end end - - context.thread.run if state.proceed? + 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 end - + def splitter - return lambda do |str| + lambda do |str| str.split(/;/).inject([]) do |m, v| if m.empty? m << v else if m.last[-1] == ?\\ @@ -100,9 +77,39 @@ end end m end end + end + end + + class ControlCommandProcessor < CommandProcessor# :nodoc: + def process_commands + @printer.print_debug("Starting control thread") + 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 + # sleep 0.3 + catch(:debug_error) do + if cmd = ctrl_cmds.find{|c| c.match(input) } + @printer.print_debug "Processing in control: #{input.gsub('%', '%%')}" + cmd.execute + else + @interface.command_queue << 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 end class State # :nodoc: