A Debugger::CommandProcessor is the kind of Debugger::Processor used when you are running inside the same process as the debugged program.
This is a callback routine when the debugged program hits a breakpoint event. For example ruby-debug-base calls this.
# File cli/ruby-debug/processor.rb, line 153 def at_breakpoint(context, breakpoint) @event_arg = 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
This is a callback routine when the debugged program hits a catchpoint. For example ruby-debug-base calls this.
# File cli/ruby-debug/processor.rb, line 168 def at_catchpoint(context, excpt) @event_arg = 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 Debugger.inside_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
This is a callback routine when the debugged program hits a “line” (or statement boundary) event. For example ruby-debug-base calls this.
# File cli/ruby-debug/processor.rb, line 204 def at_line(context, file, line) process_commands(context, file, line) end
This is a callback routine when the debugged program hits a “return” event. For example ruby-debug-base calls this. Note: right now ruby-debug-base does not call this. Perhaps other bases routines such as the one in JRuby do.
# File cli/ruby-debug/processor.rb, line 213 def at_return(context, file, line) context.stop_frame = -1 process_commands(context, file, line) end
# File cli/ruby-debug/processor.rb, line 185 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) canonic_file = CommandProcessor.canonic_file(file) unless canonic_file == @last_file and @last_line == line and Command.settings[:tracing_plus] print "Tracing(%d):%s:%s %s", context.thnum, canonic_file, line, Debugger.line_at(file, line) @last_file = canonic_file @last_line = line end always_run(context, file, line, 2) end
# File cli/ruby-debug/processor.rb, line 94 def interface=(interface) @mutex.synchronize do @interface.close if @interface @interface = interface end end
Return the command object to run given input string input.
# File cli/ruby-debug/processor.rb, line 219 def lookup(input) @commands.find{ |c| c.match(input) } end
Run a single command specified by string input; commands is and Array of possible debugger command objects and context is a Debugger::Context object.
# File cli/ruby-debug/processor.rb, line 226 def one_cmd(commands, context, input) if cmd = lookup(input) if context.dead? && cmd.class.need_context p cmd print "Command is unavailable\n" else cmd.execute end else unknown_cmd = commands.find{|cmd| cmd.class.unknown } if unknown_cmd unknown_cmd.execute else errmsg "Unknown command: \"#{input}\". Try \"help\".\n" end end end
Regularize or “canonicalize” file name filename. 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.
# File cli/ruby-debug/processor.rb, line 107 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
# File cli/ruby-debug/processor.rb, line 80 def initialize(interface = LocalInterface.new) @interface = interface @commands = [] @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
# File cli/ruby-debug/processor.rb, line 117 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 = "\0032\0032source #{file_line}" elsif Debugger.inside_emacs? file_line = "\0032\0032#{file_line}" end print file_line end
Create a “protected” version of method mname. A protected method handles all unhandled exceptions that would cause the program to terminate.
# File cli/ruby-debug/processor.rb, line 132 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
Generated with the Darkfish Rdoc Generator 2.