Class: Debugger::Processor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby-debug/processor.rb,
lib/debugger/test/processor.rb

Overview

Should this be a mixin?

Direct Known Subclasses

CommandProcessor, ControlCommandProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#interfaceObject

:nodoc



8
9
10
# File 'lib/ruby-debug/processor.rb', line 8

def interface
  @interface
end

Class Method Details



3
4
5
# File 'lib/debugger/test/processor.rb', line 3

def print(message)
  Debugger.handler.interface.print_queue << message
end

.protect(mname) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby-debug/processor.rb', line 12

def self.protect(mname)
  alias_method "__#{mname}", mname
  module_eval %{
    def #{mname}(*args)
      @mutex.synchronize do
        return unless @interface
        __#{mname}(*args)
      end
    rescue IOError, Errno::EPIPE
      self.interface = nil
    rescue SignalException
      raise
    rescue Exception
      print "INTERNAL ERROR!!! #\{$!\}\n" rescue nil
      print $!.backtrace.map{|l| "\t#\{l\}"}.join("\n") rescue nil
    end
  }
end

Instance Method Details

#afmt(msg, newline = "\n") ⇒ Object

Format msg with gdb-style annotation header



32
33
34
# File 'lib/ruby-debug/processor.rb', line 32

def afmt(msg, newline="\n")
  "\032\032#{msg}#{newline}"
end

#aprint(msg) ⇒ Object



36
37
38
# File 'lib/ruby-debug/processor.rb', line 36

def aprint(msg)
  print afmt(msg) if Debugger.annotate.to_i > 2
end

#errmsg(*args) ⇒ Object

FIXME: use delegate?



41
42
43
# File 'lib/ruby-debug/processor.rb', line 41

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

Callers of this routine should make sure to use comma to separate format argments rather than %. Otherwise it seems that if the string you want to print has format specifier, which could happen if you are trying to show say a source-code line with “puts” or “print” in it, this print routine will give an error saying it is looking for more arguments.



51
52
53
# File 'lib/ruby-debug/processor.rb', line 51

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

#split_commands(input) ⇒ Object

Split commands like this: split_commands(“abc;def\;ghi;jkl”) => [“abc”, “def;ghi”, “jkl”]



57
58
59
# File 'lib/ruby-debug/processor.rb', line 57

def split_commands(input)
  input.split(/(?<!\\);/).map { |e| e.gsub("\\;", ";") }
end