Class: Debugger::CommandProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/ruby-debug/processor.rb

Overview

:nodoc:

Defined Under Namespace

Classes: State

Constant Summary collapse

@@Show_breakpoints_postcmd =

FIXME: get from Command regexp method.

[
 /^\s*b(?:reak)?/,
 /^\s* cond(?:ition)? (?:\s+(\d+)\s*(.*))?$/ix,
 /^\s*del(?:ete)?(?:\s+(.*))?$/ix,
 /^\s* dis(?:able)? (?:\s+(.*))?$/ix,
 /^\s* en(?:able)? (?:\s+(.*))?$/ix,
 # "tbreak", "clear",
]
@@Show_annotations_run =

“tbreak”, “clear”,

[
  /^\s*c(?:ont(?:inue)?)?(?:\s+(.*))?$/,
  /^\s*fin(?:ish)?$/,
  /^\s*n(?:ext)?([+-])?(?:\s+(.*))?$/,
  /^\s*s(?:tep)?([+-])?(?:\s+(.*))?$/
]
@@Show_annotations_postcmd =
[
 /^\s* down (?:\s+(.*))? .*$/x,
 /^\s* f(?:rame)? (?:\s+ (.*))? \s*$/x,
 /^\s* u(?:p)? (?:\s+(.*))?$/x
]

Instance Attribute Summary collapse

Attributes inherited from Processor

#interface

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Processor

#afmt, #aprint, #errmsg, #print

Constructor Details

#initialize(interface = LocalInterface.new) ⇒ CommandProcessor

Returns a new instance of CommandProcessor.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruby-debug/processor.rb', line 61

def initialize(interface = LocalInterface.new)
  @interface = interface
  @display = []

  @mutex = Mutex.new
  @last_cmd = nil
  @last_file = nil   # Filename the last time we stopped
  @last_line = nil   # line number the last time we stopped
  @debugger_breakpoints_were_empty = false # Show breakpoints 1st time
  @debugger_displays_were_empty = true # No display 1st time
  @debugger_context_was_dead = true # Assume we haven't started.
end

Instance Attribute Details

#displayObject (readonly)

Returns the value of attribute display.



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

def display
  @display
end

Class Method Details

.canonic_file(filename) ⇒ Object

Regularize file name. This is also used as a common funnel place if basename is desired or if we are working remotely and want to change the basename. Or we are eliding filenames.



87
88
89
90
91
92
93
94
95
# File 'lib/ruby-debug/processor.rb', line 87

def self.canonic_file(filename)
  # For now we want resolved filenames
  if Command.settings[:basename]
    File.basename(filename)
  else
    # Cache this?
    Pathname.new(filename).cleanpath.to_s
  end
end


97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruby-debug/processor.rb', line 97

def self.print_location_and_text(file, line)
  file_line = "%s:%s\n%s" % [canonic_file(file), line,
                             Debugger.line_at(file, line)]
  # FIXME: use annotations routines
  if Debugger.annotate.to_i > 2
    file_line = "\032\032source #{file_line}"
  elsif ENV['EMACS']
    file_line = "\032\032#{file_line}"
  end
  print file_line
end

.protect(mname) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ruby-debug/processor.rb', line 109

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

#at_breakpoint(context, breakpoint) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/ruby-debug/processor.rb', line 128

def at_breakpoint(context, breakpoint)
  aprint 'stopped' if Debugger.annotate.to_i > 2
  n = Debugger.breakpoints.index(breakpoint) + 1
  file = CommandProcessor.canonic_file(breakpoint.source)
  line = breakpoint.pos
  if Debugger.annotate.to_i > 2
    print afmt("source #{file}:#{line}")
  end
  print "Breakpoint %d at %s:%s\n", n, file, line
end

#at_catchpoint(context, excpt) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/ruby-debug/processor.rb', line 140

def at_catchpoint(context, excpt)
  aprint 'stopped' if Debugger.annotate.to_i > 2
  file = CommandProcessor.canonic_file(context.frame_file(0))
  line = context.frame_line(0)
  print afmt("%s:%d" % [file, line]) if ENV['EMACS']
  print "Catchpoint at %s:%d: `%s' (%s)\n", file, line, excpt, excpt.class
  fs = context.stack_size
  tb = caller(0)[-fs..-1]
  if tb
    for i in tb
      print "\tfrom %s\n", i
    end
  end
end

#at_line(context, file, line) ⇒ Object



172
173
174
# File 'lib/ruby-debug/processor.rb', line 172

def at_line(context, file, line)
  process_commands(context, file, line)
end

#at_return(context, file, line) ⇒ Object



177
178
179
180
# File 'lib/ruby-debug/processor.rb', line 177

def at_return(context, file, line)
  context.stop_frame = -1
  process_commands(context, file, line)
end

#at_tracing(context, file, line) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/ruby-debug/processor.rb', line 156

def at_tracing(context, file, line)
  return if defined?(Debugger::RDEBUG_FILE) &&
    Debugger::RDEBUG_FILE == file # Don't trace ourself
  @last_file = CommandProcessor.canonic_file(file)
  file = CommandProcessor.canonic_file(file)
  unless file == @last_file and @last_line == line and
      Command.settings[:tracing_plus]
    print "Tracing(%d):%s:%s %s",
    context.thnum, file, line, Debugger.line_at(file, line)
    @last_file = file
    @last_line = line
  end
  always_run(context, file, line, 2)
end

#interface=(interface) ⇒ Object



74
75
76
77
78
79
# File 'lib/ruby-debug/processor.rb', line 74

def interface=(interface)
  @mutex.synchronize do
    @interface.close if @interface
    @interface = interface
  end
end