module DEBUGGER__
$VERBOSE = true
Constants
- CONFIG
- CONFIG_MAP
- CONFIG_SET
- FrameInfo
- LOG_LEVELS
- M_CLASS
- M_INSTANCE_VARIABLES
- M_INSTANCE_VARIABLE_GET
- M_KIND_OF_P
- M_METHOD
- M_NAME
- M_OBJECT_ID
- M_RESPOND_TO_P
- M_SINGLETON_CLASS
- PresetCommands
- SHORT_INSPECT_LENGTH
-
Inspector
- SessionCommand
- VERSION
Public Class Methods
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2186 def self.add_catch_breakpoint pat ::DEBUGGER__::SESSION.add_catch_breakpoint pat end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2182 def self.add_line_breakpoint file, line, **kw ::DEBUGGER__::SESSION.add_line_breakpoint file, line, **kw end
manual configuration methods
Source
# File bundled-src/irb-1.16.0/lib/irb/debug.rb, line 49 def DEBUGGER__.capture_frames(*args) frames = capture_frames_without_irb(*args) frames.reject! do |frame| frame.realpath&.start_with?(IRB_DIR) || frame.path.start_with?("<internal:") end frames end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2395 def self.check_loglevel level lv = LOG_LEVELS[level] config_lv = LOG_LEVELS[CONFIG[:log_level]] lv <= config_lv end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 576 def self.commands (defined?(@commands) && @commands) || (parse_help; @commands) end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2441 def self.compare_path(a, b) a&.downcase == b&.downcase end
For case insensitive file system (like Windows) Note that this check is not enough because case sensitive/insensitive is depend on the file system. So this check is only roughly estimation.
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 527 def self.create_unix_domain_socket_name(base_dir = unix_domain_socket_dir) suffix = "-#{Process.pid}" name = CONFIG[:session_name] suffix << "-#{name}" if name create_unix_domain_socket_name_prefix(base_dir) + suffix end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 523 def self.create_unix_domain_socket_name_prefix(base_dir = unix_domain_socket_dir) File.join(base_dir, "rdbg") end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2401 def self.debug(&b) if check_loglevel :DEBUG log :DEBUG, b.call end end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 580 def self.help r = [] self.helps.each{|cat, cmds| r << "### #{cat}" r << '' cmds.each{|_, desc| r << desc } r << '' } r.join("\n") end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 572 def self.helps (defined?(@helps) && @helps) || parse_help end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2391 def self.info msg log :INFO, msg end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2302 def self.load_rc rc_file_paths = [ [File.expand_path('~/.rdbgrc'), true], [File.expand_path('~/.rdbgrc.rb'), true], # ['./.rdbgrc', true], # disable because of security concern ] if (xdg_home = ENV["XDG_CONFIG_HOME"]) rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config")), true] rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config.rb")), true] end rc_file_paths << [CONFIG[:init_script], false] rc_file_paths.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
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2407 def self.log level, msg if check_loglevel level @logfile = STDERR unless defined? @logfile return if @logfile.closed? if defined? SESSION pi = SESSION.process_info process_info = pi ? "[#{pi}]" : nil end 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
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2224 def self.open host: nil, port: CONFIG[:port], sock_path: nil, sock_dir: nil, nonstop: false, **kw CONFIG.set_config(**kw) require_relative 'server' if port || CONFIG[:open] == 'chrome' || (!::Addrinfo.respond_to?(:unix)) open_tcp host: host, port: (port || 0), nonstop: nonstop else open_unix sock_path: sock_path, sock_dir: sock_dir, nonstop: nonstop end end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2235 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
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2248 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
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 536 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 register_command (.+)/ next unless cat next unless desc ws = [] $1.gsub(/'([a-z]+)'/){|w| ws << $1 } 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
Help
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2192 def self.require_location locs = caller_locations dir_prefix = /#{Regexp.escape(__dir__)}/ locs.each do |loc| case loc.absolute_path when dir_prefix when %r{rubygems/core_ext/kernel_require\.rb} when %r{bundled_gems\.rb} else return loc if loc.absolute_path end end nil end
String for requiring location nil for -r
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2369 def self.safe_inspect obj, max_length: SHORT_INSPECT_LENGTH, short: false if short LimitedPP.pp(obj, max_length) else obj.inspect end rescue NoMethodError => e klass, oid = M_CLASS.bind_call(obj), M_OBJECT_ID.bind_call(obj) if obj == (r = e.receiver) "<\##{klass.name}#{oid} does not have \#inspect>" else rklass, roid = M_CLASS.bind_call(r), M_OBJECT_ID.bind_call(r) "<\##{klass.name}:#{roid} contains <\##{rklass}:#{roid} and it does not have #inspect>" end rescue Exception => e "<#inspect raises #{e.inspect}>" end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2263 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
boot utilities
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2297 def skip? @skip_all end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2293 def skip_all @skip_all = true end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2210 def self.start nonstop: false, **kw CONFIG.set_config(**kw) if CONFIG[:open] open nonstop: nonstop, **kw else unless defined? SESSION require_relative 'local' initialize_session{ UI_LocalConsole.new } end setup_initial_suspend unless nonstop end end
start methods
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2428 def self.step_in &b if defined?(SESSION) && SESSION.active? SESSION.add_iseq_breakpoint RubyVM::InstructionSequence.of(b), oneshot: true end yield end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 510 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
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 498 def self.unix_domain_socket_homedir if home = ENV['HOME'] path = File.join(home, '.rdbg-sock') unless File.exist?(path) Dir.mkdir(path, 0700) end check_dir_authority(path) end end
Source
# File bundled-src/debug-1.11.1/lib/debug/config.rb, line 483 def self.unix_domain_socket_tmpdir require 'tmpdir' if tmpdir = Dir.tmpdir path = File.join(tmpdir, "rdbg-#{Process.uid}") unless File.exist?(path) d = Dir.mktmpdir File.rename(d, path) end check_dir_authority(path) end end
Source
# File bundled-src/debug-1.11.1/lib/debug/session.rb, line 2387 def self.warn msg log :WARN, msg end