module DEBUGGER__
$VERBOSE = true
Constants
- CONFIG
- CONFIG_MAP
- CONFIG_SET
- FrameInfo
- LOG_LEVELS
- METHOD_ADDED_TRACKER
- PresetCommand
- SHORT_INSPECT_LENGTH
- VERSION
Public Class Methods
add_catch_breakpoint(pat)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 1871 def self.add_catch_breakpoint pat ::DEBUGGER__::SESSION.add_catch_breakpoint pat end
add_line_breakpoint(file, line, **kw)
click to toggle source
manual configuration methods
# File debug-1.4.0/lib/debug/session.rb, line 1867 def self.add_line_breakpoint file, line, **kw ::DEBUGGER__::SESSION.add_line_breakpoint file, line, **kw end
commands()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 477 def self.commands (defined?(@commands) && @commands) || (parse_help; @commands) end
create_unix_domain_socket_name(base_dir = unix_domain_socket_dir)
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 435 def self.create_unix_domain_socket_name(base_dir = unix_domain_socket_dir) create_unix_domain_socket_name_prefix(base_dir) + "-#{Process.pid}" end
create_unix_domain_socket_name_prefix(base_dir = unix_domain_socket_dir)
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 430 def self.create_unix_domain_socket_name_prefix(base_dir = unix_domain_socket_dir) user = ENV['USER'] || 'ruby-debug' File.join(base_dir, "ruby-debug-#{user}") end
help()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 481 def self.help r = [] self.helps.each{|cat, cmds| r << "### #{cat}" r << '' cmds.each{|_, desc| r << desc } r << '' } r.join("\n") end
helps()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 473 def self.helps (defined?(@helps) && @helps) || parse_help end
info(msg)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2030 def self.info msg log :INFO, msg end
load_rc()
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 1969 def self.load_rc [[File.expand_path('~/.rdbgrc'), true], [File.expand_path('~/.rdbgrc.rb'), true], # ['./.rdbgrc', true], # disable because of security concern [CONFIG[:init_script], false], ].each{|(path, rc)| next unless path next if rc && CONFIG[:no_rc] # ignore rc if File.file? path if path.end_with?('.rb') load path else ::DEBUGGER__::SESSION.add_preset_commands path, File.readlines(path) end elsif !rc warn "Not found: #{path}" end } # given debug commands if CONFIG[:commands] cmds = CONFIG[:commands].split(';;') ::DEBUGGER__::SESSION.add_preset_commands "commands", cmds, kick: false, continue: false end end
log(level, msg)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2034 def self.log level, msg @logfile = STDERR unless defined? @logfile lv = LOG_LEVELS[level] config_lv = LOG_LEVELS[CONFIG[:log_level] || :WARN] if defined? SESSION pi = SESSION.process_info process_info = pi ? "[#{pi}]" : nil end if lv <= config_lv if level == :WARN # :WARN on debugger is general information @logfile.puts "DEBUGGER#{process_info}: #{msg}" @logfile.flush else @logfile.puts "DEBUGGER#{process_info} (#{level}): #{msg}" @logfile.flush end end end
method_added(tp)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2002 def self.method_added tp begin SESSION.method_added tp rescue Exception => e p e end end
open(host: nil, port: CONFIG[:port], sock_path: nil, sock_dir: nil, nonstop: false, **kw)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 1905 def self.open host: nil, port: CONFIG[:port], sock_path: nil, sock_dir: nil, nonstop: false, **kw CONFIG.set_config(**kw) if port || CONFIG[:open_frontend] == 'chrome' open_tcp host: host, port: (port || 0), nonstop: nonstop else open_unix sock_path: sock_path, sock_dir: sock_dir, nonstop: nonstop end end
open_tcp(host: nil, port:, nonstop: false, **kw)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 1915 def self.open_tcp host: nil, port:, nonstop: false, **kw CONFIG.set_config(**kw) require_relative 'server' if defined? SESSION SESSION.reset_ui UI_TcpServer.new(host: host, port: port) else initialize_session UI_TcpServer.new(host: host, port: port) end setup_initial_suspend unless nonstop end
open_unix(sock_path: nil, sock_dir: nil, nonstop: false, **kw)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 1928 def self.open_unix sock_path: nil, sock_dir: nil, nonstop: false, **kw CONFIG.set_config(**kw) require_relative 'server' if defined? SESSION SESSION.reset_ui UI_UnixDomainServer.new(sock_dir: sock_dir, sock_path: sock_path) else initialize_session UI_UnixDomainServer.new(sock_dir: sock_dir, sock_path: sock_path) end setup_initial_suspend unless nonstop end
parse_help()
click to toggle source
Help
# File debug-1.4.0/lib/debug/config.rb, line 441 def self.parse_help helps = Hash.new{|h, k| h[k] = []} desc = cat = nil cmds = Hash.new File.read(File.join(__dir__, 'session.rb'), encoding: Encoding::UTF_8).each_line do |line| case line when /\A\s*### (.+)/ cat = $1 break if $1 == 'END' when /\A when (.+)/ next unless cat next unless desc ws = $1.split(/,\s*/).map{|e| e.gsub('\'', '')} helps[cat] << [ws, desc] desc = nil max_w = ws.max_by{|w| w.length} ws.each{|w| cmds[w] = max_w } when /\A\s+# (\s*\*.+)/ if desc desc << "\n" + $1 else desc = $1 end end end @commands = cmds @helps = helps end
require_location()
click to toggle source
String for requiring location nil for -r
# File debug-1.4.0/lib/debug/session.rb, line 1877 def self.require_location locs = caller_locations dir_prefix = /#{__dir__}/ locs.each do |loc| case loc.absolute_path when dir_prefix when %r{rubygems/core_ext/kernel_require\.rb} else return loc if loc.absolute_path end end nil end
safe_inspect(obj, max_length: SHORT_INSPECT_LENGTH, short: false)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2014 def self.safe_inspect obj, max_length: SHORT_INSPECT_LENGTH, short: false str = obj.inspect if short && str.length > max_length str[0...max_length] + '...' else str end rescue Exception => e str = "<#inspect raises #{e.inspect}>" end
setup_initial_suspend()
click to toggle source
boot utilities
# File debug-1.4.0/lib/debug/session.rb, line 1943 def self.setup_initial_suspend if !CONFIG[:nonstop] case when CONFIG[:stop_at_load] add_line_breakpoint __FILE__, __LINE__ + 1, oneshot: true, hook_call: false nil # stop here when path = ENV['RUBY_DEBUG_INITIAL_SUSPEND_PATH'] add_line_breakpoint path, 0, oneshot: true, hook_call: false when loc = ::DEBUGGER__.require_location # require 'debug/start' or 'debug' add_line_breakpoint loc.absolute_path, loc.lineno + 1, oneshot: true, hook_call: false else # -r add_line_breakpoint $0, 0, oneshot: true, hook_call: false end end end
start(nonstop: false, **kw)
click to toggle source
start methods
# File debug-1.4.0/lib/debug/session.rb, line 1894 def self.start nonstop: false, **kw CONFIG.set_config(**kw) unless defined? SESSION require_relative 'local' initialize_session UI_LocalConsole.new end setup_initial_suspend unless nonstop end
step_in() { || ... }
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2057 def self.step_in &b if defined?(SESSION) && SESSION.active? SESSION.add_iseq_breakpoint RubyVM::InstructionSequence.of(b), oneshot: true end yield end
unix_domain_socket_dir()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 417 def self.unix_domain_socket_dir case when path = CONFIG[:sock_dir] when path = ENV['XDG_RUNTIME_DIR'] when path = unix_domain_socket_tmpdir when path = unix_domain_socket_homedir else raise 'specify RUBY_DEBUG_SOCK_DIR environment variable.' end path end
unix_domain_socket_homedir()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 405 def self.unix_domain_socket_homedir if home = ENV['HOME'] path = File.join(home, '.ruby-debug-sock') unless File.exist?(path) Dir.mkdir(path, 0700) end check_dir_authority(path) end end
unix_domain_socket_tmpdir()
click to toggle source
# File debug-1.4.0/lib/debug/config.rb, line 390 def self.unix_domain_socket_tmpdir require 'tmpdir' if tmpdir = Dir.tmpdir path = File.join(tmpdir, "ruby-debug-sock-#{Process.uid}") unless File.exist?(path) d = Dir.mktmpdir File.rename(d, path) end check_dir_authority(path) end end
warn(msg)
click to toggle source
# File debug-1.4.0/lib/debug/session.rb, line 2026 def self.warn msg log :WARN, msg end