Class: Byebug::Frame

Inherits:
Object
  • Object
show all
Includes:
Helpers::FileHelper
Defined in:
lib/byebug/frame.rb

Overview

Represents a frame in the stack trace

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Constructor Details

#initialize(context, pos) ⇒ Frame

Returns a new instance of Frame.



14
15
16
17
# File 'lib/byebug/frame.rb', line 14

def initialize(context, pos)
  @context = context
  @pos = pos
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos.



12
13
14
# File 'lib/byebug/frame.rb', line 12

def pos
  @pos
end

Instance Method Details

#_bindingObject



31
32
33
# File 'lib/byebug/frame.rb', line 31

def _binding
  @context.frame_binding(pos)
end

#_classObject



35
36
37
# File 'lib/byebug/frame.rb', line 35

def _class
  @context.frame_class(pos)
end

#_methodObject



39
40
41
# File 'lib/byebug/frame.rb', line 39

def _method
  @context.frame_method(pos)
end

#_selfObject



27
28
29
# File 'lib/byebug/frame.rb', line 27

def _self
  @context.frame_self(pos)
end

#argsObject

Gets current method arguments for the frame.



62
63
64
65
66
# File 'lib/byebug/frame.rb', line 62

def args
  return c_args unless _binding

  ruby_args
end

#c_frame?Boolean

Checks whether the frame is a c-frame

Returns:

  • (Boolean)


141
142
143
# File 'lib/byebug/frame.rb', line 141

def c_frame?
  _binding.nil?
end

#current?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/byebug/frame.rb', line 43

def current?
  @context.frame.pos == pos
end

#deco_argsObject

Builds a string containing all available args in the frame number, in a verbose or non verbose way according to the value of the callstyle setting



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/byebug/frame.rb', line 89

def deco_args
  return "" if args.empty?

  my_args = args.map do |arg|
    prefix, default = prefix_and_default(arg[0])

    kls = use_short_style?(arg) ? "" : "##{locals[arg[1]].class}"

    "#{prefix}#{arg[1] || default}#{kls}"
  end

  "(#{my_args.join(', ')})"
end

#deco_blockObject



76
77
78
# File 'lib/byebug/frame.rb', line 76

def deco_block
  _method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || ""
end

#deco_callObject

Builds a formatted string containing information about current method call



106
107
108
# File 'lib/byebug/frame.rb', line 106

def deco_call
  deco_block + deco_class + deco_method + deco_args
end

#deco_classObject

Returns the current class in the frame or an empty string if the current callstyle setting is ‘short’



72
73
74
# File 'lib/byebug/frame.rb', line 72

def deco_class
  Setting[:callstyle] == "short" || _class.to_s.empty? ? "" : "#{_class}."
end

#deco_fileObject

Formatted filename in frame



113
114
115
# File 'lib/byebug/frame.rb', line 113

def deco_file
  Setting[:fullpath] ? File.expand_path(file) : shortpath(file)
end

#deco_methodObject



80
81
82
# File 'lib/byebug/frame.rb', line 80

def deco_method
  _method[/((?:block(?: \(\d+ levels\))?|rescue) in )?(.*)/]
end

#deco_posObject

Properly formatted frame number of frame



120
121
122
# File 'lib/byebug/frame.rb', line 120

def deco_pos
  format("%-2<pos>d", pos: pos)
end

#fileObject



19
20
21
# File 'lib/byebug/frame.rb', line 19

def file
  @context.frame_file(pos)
end

#lineObject



23
24
25
# File 'lib/byebug/frame.rb', line 23

def line
  @context.frame_line(pos)
end

#localsObject

Gets local variables for the frame.



50
51
52
53
54
55
56
57
# File 'lib/byebug/frame.rb', line 50

def locals
  return [] unless _binding

  _binding.local_variables.each_with_object({}) do |e, a|
    a[e] = _binding.local_variable_get(e)
    a
  end
end

#markObject

Formatted mark for the frame.

–> marks the current frame ͱ– marks c-frames

marks regular frames


131
132
133
134
135
136
# File 'lib/byebug/frame.rb', line 131

def mark
  return "-->" if current?
  return "    ͱ--" if c_frame?

  "   "
end

#to_hashObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/byebug/frame.rb', line 145

def to_hash
  {
    mark: mark,
    pos: deco_pos,
    call: deco_call,
    file: deco_file,
    line: line,
    full_path: File.expand_path(deco_file)
  }
end