Method: Debugger.post_mortem

Defined in:
lib/ruby-debug.rb

.post_mortemObject

Activates the post-mortem mode. There are two ways of using it:

Global post-mortem mode

By calling Debugger.post_mortem method without a block, you install at_exit hook that intercepts any unhandled by your script exceptions and enables post-mortem mode.

Local post-mortem mode

If you know that a particular block of code raises an exception you can enable post-mortem mode by wrapping this block with Debugger.post_mortem, e.g.

def offender
   raise 'error'
end
Debugger.post_mortem do
   ...
   offender
   ...
end


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/ruby-debug.rb', line 242

def post_mortem
  raise "Post-mortem is already activated" if self.post_mortem?
  self.post_mortem = true
  if block_given?
    begin
      yield
    rescue Exception => exp
      handle_post_mortem(exp)
      raise
    ensure
      self.post_mortem = false
    end
  else
    debug_at_exit do
      handle_post_mortem($!) if $! && post_mortem?
    end
  end
end