To require and use:
require 'debug/prelude'
# Then to use...
debuggerSimply requiring debug only instead of debug/prelude will invoke the debugger immediately, and cause the following error message:
/usr/local/lib/ruby/2.6.0/aarch64-linux/continuation.so: warning: callcc is obsolete; use Fiber instead
Debug.rb
Emacs support available.
/usr/local/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:164: if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
(rdb:1) exit
/usr/local/lib/ruby/2.6.0/debug.rb:245:in `synchronize': deadlock; recursive locking (ThreadError)
from /usr/local/lib/ruby/2.6.0/debug.rb:245:in `check_suspend'
from /usr/local/lib/ruby/2.6.0/debug.rb:843:in `trace_func'
from /usr/local/lib/ruby/2.6.0/debug.rb:1109:in `block in <class:DEBUGGER__>'
from /usr/local/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:167:in `require'
from bin/process-env:13:in `<main>'
Compared to the others:
require "debug"- Stops immediately at program startrequire "debug/prelude"- Enables both thedebuggerkeyword as well asbinding.breakrequire "debug/open"- Only enablesdebuggerkeywordrequire "debug/open_nonstop"- Enablesdebuggerbut doesn't stop
debug/prelude is particularly useful when you want the flexibility of using either debugger or binding.break methods. The binding.break method is more Ruby-like and can be useful in situations where you want to pass additional options:
require "debug/prelude"
def some_method
binding.break(pre: "puts 'Stopping!'") # can include commands to run when breaking
binding.break(do: "p local_variables") # can inspect state
endTo debug on raised exceptions:
require 'debug/prelude'
Exception.install_debug_handler # This will break on any unhandled exception