Class: DEBUGGER__::FrameInfo
- Defined in:
- lib/debug/frame_info.rb,
lib/debug/frame_info.rb
Constant Summary collapse
- HOME =
ENV['HOME'] ? (ENV['HOME'] + '/') : nil
- BLOCK_LABL_REGEXP =
/\Ablock( \(\d+ levels\))* in (.+)\z/
Instance Attribute Summary collapse
-
#_callee ⇒ Object
Returns the value of attribute _callee.
-
#_local_variables ⇒ Object
Returns the value of attribute _local_variables.
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#class ⇒ Object
Returns the value of attribute class.
-
#dupped_binding ⇒ Object
Returns the value of attribute dupped_binding.
-
#frame_depth ⇒ Object
Returns the value of attribute frame_depth.
-
#has_raised_exception ⇒ Object
Returns the value of attribute has_raised_exception.
-
#has_return_value ⇒ Object
Returns the value of attribute has_return_value.
-
#iseq ⇒ Object
Returns the value of attribute iseq.
-
#location ⇒ Object
Returns the value of attribute location.
-
#raised_exception ⇒ Object
Returns the value of attribute raised_exception.
-
#return_value ⇒ Object
Returns the value of attribute return_value.
-
#self ⇒ Object
Returns the value of attribute self.
-
#show_line ⇒ Object
Returns the value of attribute show_line.
Class Method Summary collapse
Instance Method Summary collapse
- #block_identifier ⇒ Object
- #c_identifier ⇒ Object
- #callee ⇒ Object
- #eval_binding ⇒ Object
- #file_lines ⇒ Object
- #frame_type ⇒ Object
- #iseq_parameters_info ⇒ Object
- #local_variables ⇒ Object
- #location_str ⇒ Object
- #matchable_location ⇒ Object
- #method_identifier ⇒ Object
- #name ⇒ Object
- #other_identifier ⇒ Object
- #parameters_info ⇒ Object
- #path ⇒ Object
- #pretty_path ⇒ Object
- #realpath ⇒ Object
- #return_str ⇒ Object
Instance Attribute Details
#_callee ⇒ Object
Returns the value of attribute _callee
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def _callee @_callee end |
#_local_variables ⇒ Object
Returns the value of attribute _local_variables
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def _local_variables @_local_variables end |
#binding ⇒ Object
Returns the value of attribute binding
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def binding @binding end |
#class ⇒ Object
Returns the value of attribute class
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def class @class end |
#dupped_binding ⇒ Object
Returns the value of attribute dupped_binding
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def dupped_binding @dupped_binding end |
#frame_depth ⇒ Object
Returns the value of attribute frame_depth
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def frame_depth @frame_depth end |
#has_raised_exception ⇒ Object
Returns the value of attribute has_raised_exception
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def has_raised_exception @has_raised_exception end |
#has_return_value ⇒ Object
Returns the value of attribute has_return_value
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def has_return_value @has_return_value end |
#iseq ⇒ Object
Returns the value of attribute iseq
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def iseq @iseq end |
#location ⇒ Object
Returns the value of attribute location
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def location @location end |
#raised_exception ⇒ Object
Returns the value of attribute raised_exception
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def raised_exception @raised_exception end |
#return_value ⇒ Object
Returns the value of attribute return_value
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def return_value @return_value end |
#self ⇒ Object
Returns the value of attribute self
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def self @self end |
#show_line ⇒ Object
Returns the value of attribute show_line
4 5 6 |
# File 'lib/debug/frame_info.rb', line 4 def show_line @show_line end |
Class Method Details
.pretty_path(path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/debug/frame_info.rb', line 31 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 Method Details
#block_identifier ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/debug/frame_info.rb', line 88 def block_identifier return unless frame_type == :block re_match = location.label.match(BLOCK_LABL_REGEXP) _, level, block_loc = re_match ? re_match.to_a : [nil, nil, location.label] [level || "", block_loc] end |
#c_identifier ⇒ Object
101 102 103 104 |
# File 'lib/debug/frame_info.rb', line 101 def c_identifier return unless frame_type == :c "[C] #{klass_sig}#{location.base_label}" end |
#callee ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/debug/frame_info.rb', line 111 def callee self._callee ||= begin self.binding&.eval('__callee__') rescue NameError # BasicObject nil end end |
#eval_binding ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/debug/frame_info.rb', line 134 def eval_binding if b = self.dupped_binding b else b = self.binding || TOPLEVEL_BINDING self.dupped_binding = b.dup end end |
#file_lines ⇒ Object
68 69 70 |
# File 'lib/debug/frame_info.rb', line 68 def file_lines SESSION.source(self.iseq) end |
#frame_type ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/debug/frame_info.rb', line 72 def frame_type if self.local_variables && iseq if iseq.type == :block :block elsif callee :method else :other end else :c end end |
#iseq_parameters_info ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/debug/frame_info.rb', line 153 def iseq_parameters_info case frame_type when :block, :method parameters_info else nil end end |
#local_variables ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/debug/frame_info.rb', line 143 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 ⇒ Object
130 131 132 |
# File 'lib/debug/frame_info.rb', line 130 def location_str "#{pretty_path}:#{location.lineno}" end |
#matchable_location ⇒ Object
125 126 127 128 |
# File 'lib/debug/frame_info.rb', line 125 def matchable_location # realpath can sometimes be nil so we can't use it here "#{path}:#{location.lineno}" end |
#method_identifier ⇒ Object
96 97 98 99 |
# File 'lib/debug/frame_info.rb', line 96 def method_identifier return unless frame_type == :method "#{klass_sig}#{callee}" end |
#name ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/debug/frame_info.rb', line 53 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 ⇒ Object
106 107 108 109 |
# File 'lib/debug/frame_info.rb', line 106 def other_identifier return unless frame_type == :other location.label end |
#parameters_info ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/debug/frame_info.rb', line 162 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 ⇒ Object
23 24 25 |
# File 'lib/debug/frame_info.rb', line 23 def path location.path end |
#pretty_path ⇒ Object
49 50 51 |
# File 'lib/debug/frame_info.rb', line 49 def pretty_path FrameInfo.pretty_path path end |
#realpath ⇒ Object
27 28 29 |
# File 'lib/debug/frame_info.rb', line 27 def realpath location.absolute_path end |
#return_str ⇒ Object
119 120 121 122 123 |
# File 'lib/debug/frame_info.rb', line 119 def return_str if self.binding && iseq && has_return_value DEBUGGER__.safe_inspect(return_value, short: true) end end |