# frozen_string_literal: false
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
class FrameOverflow < StandardError
class FrameUnderflow < StandardError
# Default number of stack frames
# Default number of frames offset
# Creates a new stack frame
@frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
# Used by Kernel#set_trace_func to register each event in the call stack
def trace_func(event, file, line, id, binding)
# Returns the +n+ number of frames on the call stack from the last frame
# Raises FrameUnderflow if there are no frames in the given stack range.
bind = @frames[-(n + CALL_STACK_OFFSET)]
fail FrameUnderflow unless bind
# Returns the +n+ number of frames on the call stack from the first frame
# Raises FrameOverflow if there are no frames in the given stack range.
fail FrameOverflow unless bind
# Convenience method for Frame#bottom
# Convenience method for Frame#top
# Returns the binding context of the caller from the last frame initialized
eval "self", @backtrace.top
set_trace_func proc{|event, file, line, id, binding, klass|
@backtrace.trace_func(event, file, line, id, binding)