123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::FrameInfo

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
Defined in: lib/debug/frame_info.rb,
lib/debug/frame_info.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.pretty_path(path)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 30

def self.pretty_path path
  return '#<none>' unless path
  use_short_path = CONFIG[:use_short_path]

  case
  when use_short_path && path.start_with?(dir = RbConfig::CONFIG["rubylibdir"] + '/')
    path.sub(dir, '$(rubylibdir)/')
  when use_short_path && Gem.path.any? do |gp|
      path.start_with?(dir = gp + '/gems/')
    end
    path.sub(dir, '$(Gem)/')
  when HOME && path.start_with?(HOME)
    path.sub(HOME, '~/')
  else
    path
  end
end

Instance Attribute Details

#_callee (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#_local_variables (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#binding (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#class (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#dupped_binding (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#frame_depth (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#has_raised_exception (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#has_return_value (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#iseq (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#location (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#raised_exception (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#return_value (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#self (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

#show_line (rw)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 4

FrameInfo = Struct.new(:location, :self, :binding, :iseq, :class, :frame_depth,
  :has_return_value,     :return_value,
  :has_raised_exception, :raised_exception,
  :show_line,
  :_local_variables, :_callee, # for recorder
  :dupped_binding,
)

Instance Method Details

#block_identifier

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 87

def block_identifier
  return unless frame_type == :block
  _, level, block_loc = location.label.match(BLOCK_LABL_REGEXP).to_a
  [level || "", block_loc]
end

#c_identifier

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 98

def c_identifier
  return unless frame_type == :c
  "[C] #{klass_sig}#{location.base_label}"
end

#callee

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 108

def callee
  self._callee ||= begin
                     self.binding&.eval('__callee__')
                   rescue NameError # BasicObject
                     nil
                   end
end

#eval_binding

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 131

def eval_binding
  if b = self.dupped_binding
    b
  else
    b = self.binding || TOPLEVEL_BINDING
    self.dupped_binding = b.dup
  end
end

#file_lines

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 67

def file_lines
  SESSION.source(self.iseq)
end

#frame_type

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 71

def frame_type
  if self.local_variables && iseq
    if iseq.type == :block
      :block
    elsif callee
      :method
    else
      :other
    end
  else
    :c
  end
end

#get_singleton_class(obj) (private)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 161

private def get_singleton_class obj
  obj.singleton_class # TODO: don't use it
rescue TypeError
  nil
end

#klass_sig (private)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 171

private def klass_sig
  if self.class == get_singleton_class(self.self)
    "#{self.self}."
  else
    "#{self.class}#"
  end
end

#local_variable_get(var) (private)

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 167

private def local_variable_get var
  local_variables[var]
end

#local_variables

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 140

def local_variables
  if lvars = self._local_variables
    lvars
  elsif b = self.binding
    b.local_variables.map{|var|
      [var, b.local_variable_get(var)]
    }.to_h
  end
end

#location_str

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 127

def location_str
  "#{pretty_path}:#{location.lineno}"
end

#matchable_location

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 122

def matchable_location
  # realpath can sometimes be nil so we can't use it here
  "#{path}:#{location.lineno}"
end

#method_identifier

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 93

def method_identifier
  return unless frame_type == :method
  "#{klass_sig}#{callee}"
end

#name

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 52

def name
  # p frame_type: frame_type, self: self
  case frame_type
  when :block
    level, block_loc = block_identifier
    "block in #{block_loc}#{level}"
  when :method
    method_identifier
  when :c
    c_identifier
  when :other
    other_identifier
  end
end

#other_identifier

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 103

def other_identifier
  return unless frame_type == :other
  location.label
end

#parameters_info

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 150

def parameters_info
  vars = iseq.parameters_symbols
  vars.map{|var|
    begin
      { name: var, value: DEBUGGER__.safe_inspect(local_variable_get(var), short: true) }
    rescue NameError, TypeError
      nil
    end
  }.compact
end

#path

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 22

def path
  location.path
end

#pretty_path

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 48

def pretty_path
  FrameInfo.pretty_path path
end

#realpath

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 26

def realpath
  location.absolute_path
end

#return_str

[ GitHub ]

  
# File 'lib/debug/frame_info.rb', line 116

def return_str
  if self.binding && iseq && has_return_value
    DEBUGGER__.safe_inspect(return_value, short: true)
  end
end