class Byebug::Command
def commands
def commands @commands ||= [] end
def confirm(msg)
def confirm(msg) @state.confirm(msg) == 'y' end
def debug_eval(str, b = get_binding)
def debug_eval(str, b = get_binding) begin val = eval(str, b) rescue StandardError, ScriptError => e if Command.settings[:stack_trace_on_error] at = eval("caller(1)", b) print "%s:%s\n", at.shift, e.to_s.sub(/\(eval\):1:(in `.*?':)?/, '') for i in at print "\tfrom %s\n", i end else print "#{e.class} Exception: #{e.message}\n" end throw :debug_error end end
def debug_silent_eval(str)
def debug_silent_eval(str) begin eval(str, get_binding) rescue StandardError, ScriptError nil end end
def debug_warning_eval(str, b = get_binding)
def debug_warning_eval(str, b = get_binding) begin debug_eval(str, b) rescue :debug_error => e print "#{e.class} Exception: #{e.message}\n" end end
def get_binding
def get_binding @state.context ? @state.context.frame_binding(@state.frame_pos) : TOPLEVEL_BINDING end
def help(args)
def help(args) output = description.split("\n").map{|l| l.gsub(/^ +/, '')} output.shift if output.first && output.first.empty? output.pop if output.last && output.last.empty? output.join("\n") + "\n" end
def inherited(klass)
def inherited(klass) DEF_OPTIONS.each do |o, v| klass.options[o] = v if klass.options[o].nil? end commands << klass end
def initialize(state)
def initialize(state) @state = state end
def load_commands
def load_commands Dir[File.join(Byebug.const_get(:BYEBUG_DIR), 'commands', '*')].each { |file| require file if file =~ /\.rb$/ } Byebug.constants.grep(/Functions$/).map { |name| Byebug.const_get(name) }.each { |mod| include mod } end
def match(input)
def match(input) @match = regexp.match(input) end
def method_missing(meth, *args, &block)
def method_missing(meth, *args, &block) if meth.to_s =~ /^(.+?)=$/ @options[$1.intern] = args.first else if @options.has_key?(meth) @options[meth] else super end end end
def options
def options @options ||= {} end
def register_setting_get(name, &block)
def register_setting_get(name, &block) settings_map[name] ||= {} settings_map[name][:getter] = block end
def register_setting_set(name, &block)
def register_setting_set(name, &block) settings_map[name] ||= {} settings_map[name][:setter] = block end
def register_setting_var(name, default)
def register_setting_var(name, default) var_name = "@@#{name}" class_variable_set(var_name, default) register_setting_get(name) { class_variable_get(var_name) } register_setting_set(name) { |value| class_variable_set(var_name, value) } end
def settings
def settings unless defined? @settings and @settings @settings = Object.new map = settings_map c = class << @settings; self end c.send(:define_method, :[]) do |name| raise "No such setting #{name}" unless map.has_key?(name) map[name][:getter].call end c = class << @settings; self end c.send(:define_method, :[]=) do |name, value| raise "No such setting #{name}" unless map.has_key?(name) map[name][:setter].call(value) end end @settings end
def settings_map
def settings_map @@settings_map ||= {} end