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, print, protect, #split_commands

Constructor Details

#initialize(interface = LocalInterface.new) ⇒ CommandProcessor

Returns a new instance of CommandProcessor.



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

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.



63
64
65
# File 'lib/ruby-debug/processor.rb', line 63

def display
  @display
end

Class Method Details

.annotate_location_and_text(output) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/ruby-debug/processor.rb', line 131

def self.annotate_location_and_text(output)
  # FIXME: use annotations routines
  if Debugger.annotate.to_i > 2
    "\032\032source #{output}"
  elsif ENV['EMACS']
    "\032\032#{output}"
  else
    output
  end
end

.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.



113
114
115
116
117
118
119
120
121
# File 'lib/ruby-debug/processor.rb', line 113

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


123
124
125
126
127
128
129
# File 'lib/ruby-debug/processor.rb', line 123

def self.print_location_and_text(file, line, context)
  result = Debugger.printer.print("stop.suspend",
    file: canonic_file(file), line_number: line, line: Debugger.line_at(file, line),
    thnum: context && context.thnum, frames: context && context.stack_size
  )
  Debugger.handler.interface.print(annotate_location_and_text(result))
end

Instance Method Details

#at_breakpoint(context, breakpoint) ⇒ Object



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

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 pr(
    "breakpoints.stop_at_breakpoint", id: n, file: file, line: line, thread_id: Debugger.current_context.thnum
  )
  @last_breakpoint = breakpoint
end

#at_catchpoint(context, excpt) ⇒ Object



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

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



188
189
190
191
192
193
# File 'lib/ruby-debug/processor.rb', line 188

def at_line(context, file, line)
  CommandProcessor.print_location_and_text(file, line, context) unless @last_breakpoint
  process_commands(context, file, line)
ensure
  @last_breakpoint = nil
end

#at_return(context, file, line) ⇒ Object



196
197
198
199
200
# File 'lib/ruby-debug/processor.rb', line 196

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

#at_tracing(context, file, line) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ruby-debug/processor.rb', line 173

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



100
101
102
103
104
105
# File 'lib/ruby-debug/processor.rb', line 100

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