Class: Debugger::ControlCommandProcessor
- Inherits:
-
Object
- Object
- Debugger::ControlCommandProcessor
- Defined in:
- lib/ruby-debug/processor.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(interface) ⇒ ControlCommandProcessor
constructor
A new instance of ControlCommandProcessor.
- #print(*args) ⇒ Object
- #process_commands ⇒ Object
- #process_context_commands(input) ⇒ Object
- #splitter ⇒ Object
Constructor Details
#initialize(interface) ⇒ ControlCommandProcessor
Returns a new instance of ControlCommandProcessor.
7 8 9 10 |
# File 'lib/ruby-debug/processor.rb', line 7 def initialize(interface) @interface = interface @printer = XmlPrinter.new(@interface) end |
Instance Method Details
#print(*args) ⇒ Object
12 13 14 |
# File 'lib/ruby-debug/processor.rb', line 12 def print(*args) @interface.print(*args) end |
#process_commands ⇒ Object
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 |
# File 'lib/ruby-debug/processor.rb', line 16 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
44 45 46 47 48 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 |
# File 'lib/ruby-debug/processor.rb', line 44 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 |
#splitter ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ruby-debug/processor.rb', line 80 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 |