Class: TraceTree::Point

Inherits:
Object
  • Object
show all
Includes:
TreeGraphable, TreeHtmlable
Defined in:
lib/trace_tree/point.rb,
lib/trace_tree/point.rb,
lib/trace_tree/point/omit.rb,
lib/trace_tree/point/common.rb,
lib/trace_tree/point/threadend.rb,
lib/trace_tree/point/threadbegin.rb,
lib/trace_tree/point/ccall_kernel_raise.rb,
lib/trace_tree/point/ccall_kernel_extend.rb,
lib/trace_tree/point/ccall_module_include.rb,
lib/trace_tree/point/ccall_module_prepend.rb,
lib/trace_tree/point/ccall_classthread_new.rb,
lib/trace_tree/point/ccall_thread_initialize.rb,
lib/trace_tree/point/creturn_classthread_new.rb,
lib/trace_tree/point/ccall_module_extendobject.rb,
lib/trace_tree/point/creturn_thread_initialize.rb,
lib/trace_tree/point/creturn_module_extendobject.rb

Defined Under Namespace

Classes: CcallClassthreadNew, CcallKernelExtend, CcallKernelRaise, CcallModuleExtendobject, CcallModuleInclude, CcallModulePrepend, CcallThreadInitialize, Common, CreturnClassthreadNew, CreturnModuleExtendobject, CreturnThreadInitialize, Loader, Omitted, Threadbegin, Threadend

Constant Summary collapse

Interfaces =
[:event, :defined_class, :method_id, :path, :lineno]
NativeThreadCall =
[CcallClassthreadNew,
CreturnClassthreadNew,
CcallThreadInitialize,
CreturnThreadInitialize,
Threadbegin,
Threadend]

Constants included from TreeHtmlable

TreeHtmlable::DEFAULT_JS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TreeHtmlable

#body_js_for_tree_html, #children_for_tree_html, #css_for_tree_html, #data_for_tree_html, #label_for_tree_html

Methods included from TreeGraphable

#children_for_tree_graph, #label_for_tree_graph

Constructor Details

#initialize(trace_point) ⇒ Point

Returns a new instance of Point.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/trace_tree/point.rb', line 70

def initialize trace_point
  Interfaces.each do |i|
    instance_variable_set "@#{i}", trace_point.send(i)
  end

  @return_value = trace_point.return_value if x_return?
  @thread = Thread.current

  unless thread?
    there = trace_point.binding.of_caller(3)
    @current = BindingOfCallers::Revealed.new there
    @frame_env = current.frame_env.to_sym
  end
rescue => e
  puts e
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &blk) ⇒ Object

Raises:

  • (NoMethodError)


65
66
67
68
# File 'lib/trace_tree/point.rb', line 65

def method_missing method_id, *args, &blk
  raise NoMethodError, "NoMethodError: undefined method `#{method_id}' "\
    "for #<#{self.class.proto or self.class.name}#{inspect}>"
end

Class Attribute Details

.protoObject (readonly)

Returns the value of attribute proto.



49
50
51
# File 'lib/trace_tree/point.rb', line 49

def proto
  @proto
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/trace_tree/point.rb', line 11

def config
  @config
end

#currentObject (readonly)

Returns the value of attribute current.



10
11
12
# File 'lib/trace_tree/point.rb', line 10

def current
  @current
end

#frame_envObject (readonly)

Returns the value of attribute frame_env.



10
11
12
# File 'lib/trace_tree/point.rb', line 10

def frame_env
  @frame_env
end

#terminalObject

Returns the value of attribute terminal.



11
12
13
# File 'lib/trace_tree/point.rb', line 11

def terminal
  @terminal
end

#threadObject (readonly)

Returns the value of attribute thread.



10
11
12
# File 'lib/trace_tree/point.rb', line 10

def thread
  @thread
end

Class Method Details

.basesObject



21
22
23
# File 'lib/trace_tree/point.rb', line 21

def bases
  @bases ||= []
end

.cache_event_class_method!Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/trace_tree/point.rb', line 51

def cache_event_class_method!
  bases.each do |base|
    base.class_eval <<-EOM
      class << self
        alias_method :_event_class_method, :event_class_method
        def self.event_class_method
          @ecm ||= _event_class_method.freeze
        end
      end
EOM
  end
end

.class_of?(point) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/trace_tree/point.rb', line 38

def class_of? point
  e, c, m = event_class_method
  point.method_id == m && point.event == e && point.defined_class == c
end

.hashify(point) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/trace_tree/point.rb', line 25

def hashify point
  h = {}
  h[:event] = point.event
  h[:defined_class] = point.defined_class
  h[:method_id] = point.method_id
  h[:frame_env] = point.frame_env unless point.thread?
  h[:path] = point.path
  h[:lineno] = point.lineno
  h[:thread] = point.thread
  h[:return_value] = point.return_value if point.event =~ /return/
  h
end

.inherited(base) ⇒ Object



17
18
19
# File 'lib/trace_tree/point.rb', line 17

def inherited base
  bases << base
end

.initialize_clone(proto) ⇒ Object



43
44
45
46
47
# File 'lib/trace_tree/point.rb', line 43

def initialize_clone proto
  super.tap do
    instance_variable_set :@proto, proto
  end
end

Instance Method Details

#<<(node) ⇒ Object



145
146
147
# File 'lib/trace_tree/point.rb', line 145

def << node
  callees << node
end

#_class_and_methodObject



157
158
159
# File 'lib/trace_tree/point.rb', line 157

def _class_and_method
  @km ||= "#{class_name}#{call_symbol}#{method_name}"
end

#argObject



181
182
183
# File 'lib/trace_tree/point.rb', line 181

def arg
  respond_to?(:parameters) ? "(#{parameters})" : nil
end

#argumentsObject



114
115
116
117
118
119
120
121
# File 'lib/trace_tree/point.rb', line 114

def arguments
  {}.tap do |args|
    if event == :call
      defined_class.instance_method(method_id).parameters.
        each{ |role, name| args[name] = current.lv(name) unless name.nil? && role == :rest }
    end
  end
end

#b_call?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/trace_tree/point.rb', line 87

def b_call?
  event == :b_call
end

#c_call?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/trace_tree/point.rb', line 91

def c_call?
  event == :c_call
end

#call_symbolObject



173
174
175
# File 'lib/trace_tree/point.rb', line 173

def call_symbol
  c_call? ? '#' : current.call_symbol
end

#calleesObject



149
150
151
# File 'lib/trace_tree/point.rb', line 149

def callees
  @callees ||= []
end

#class?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/trace_tree/point.rb', line 95

def class?
  event == :class
end

#class_and_methodObject



153
154
155
# File 'lib/trace_tree/point.rb', line 153

def class_and_method
  "#{_class_and_method}#{arg}"
end

#class_nameObject



161
162
163
164
165
# File 'lib/trace_tree/point.rb', line 161

def class_name
  c_call? ? defined_class : current.klass
rescue
  puts event
end

#end_of_trace?Boolean

Returns:

  • (Boolean)


107
108
109
110
111
112
# File 'lib/trace_tree/point.rb', line 107

def end_of_trace?
  MainFile == path && (
    (:c_return == event && :instance_eval == method_id) ||
      (:c_call == event && :disable == method_id)
  )
end

#inspectObject



127
128
129
# File 'lib/trace_tree/point.rb', line 127

def inspect
  to_h.inspect
end

#method_defined_by_define_method?Boolean

Returns:

  • (Boolean)


252
253
254
255
# File 'lib/trace_tree/point.rb', line 252

def method_defined_by_define_method?
  (event == :call || event == :return) &&
    method_id != frame_env
end

#method_nameObject



167
168
169
170
171
# File 'lib/trace_tree/point.rb', line 167

def method_name
  return method_id if c_call?
  return frame_env if b_call? || class?
  (method_id == frame_env) ? method_id : "#{method_id} -> #{frame_env}"
end

#return_valueObject



123
124
125
# File 'lib/trace_tree/point.rb', line 123

def return_value
  x_return? ? @return_value : (terminal.nil? ? nil : terminal.return_value)
end

#source_locationObject



177
178
179
# File 'lib/trace_tree/point.rb', line 177

def source_location
  "#{path}:#{lineno}"
end

#terminate?(point) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
141
142
143
# File 'lib/trace_tree/point.rb', line 135

def terminate? point
  (point.defined_class == defined_class && point.method_id == method_id) && (
    (event == :return && point.event == :call) ||
    (event == :b_return && point.event == :b_call) ||
    (event == :c_return && point.event == :c_call) ||
    (event == :end && point.event == :class) ||
    (event == :thread_end && point.event == :thread_begin)
  )
end

#thread?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/trace_tree/point.rb', line 103

def thread?
  event =~ /thread/
end

#thread_relative?Boolean

Returns:

  • (Boolean)


247
248
249
250
# File 'lib/trace_tree/point.rb', line 247

def thread_relative?
  NativeThreadCall.any?{ |k| k.class_of? self } ||
    Thread == defined_class
end

#to_hObject



131
132
133
# File 'lib/trace_tree/point.rb', line 131

def to_h
  self.class.hashify(self)
end

#x_return?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/trace_tree/point.rb', line 99

def x_return?
  event =~ /return/
end