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.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/trace_tree/point.rb', line 72

def initialize trace_point
  assign_trace_point_values(trace_point)

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

  if event == :c_call || event == :c_return
    @call_symbol = '#'
    @frame_env = method_id
    @class_name = defined_class
    return
  end

  there = trace_point.binding.of_caller(3)
  current = BindingOfCallers::Revealed.new there
  @call_symbol = current.call_symbol
  @frame_env = current.frame_env.to_sym
  @class_name = current.klass
rescue => e
  puts e.message
  puts(Interfaces.each_with_object({}){|attr, h| h[attr] = send(attr)})
  puts e.backtrace
  raise e
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Raises:

  • (NoMethodError)


67
68
69
70
# File 'lib/trace_tree/point.rb', line 67

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.



51
52
53
# File 'lib/trace_tree/point.rb', line 51

def proto
  @proto
end

Instance Attribute Details

#call_symbolObject (readonly)

Returns the value of attribute call_symbol.



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

def call_symbol
  @call_symbol
end

#class_nameObject (readonly)

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

#configObject

Returns the value of attribute config.



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

def config
  @config
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.



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

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



23
24
25
# File 'lib/trace_tree/point.rb', line 23

def bases
  @bases ||= []
end

.cache_event_class_method!Object



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

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)


40
41
42
43
# File 'lib/trace_tree/point.rb', line 40

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



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

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



19
20
21
# File 'lib/trace_tree/point.rb', line 19

def inherited base
  bases << base
end

.initialize_clone(proto) ⇒ Object



45
46
47
48
49
# File 'lib/trace_tree/point.rb', line 45

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

Instance Method Details

#<<(node) ⇒ Object



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

def << node
  callees << node
end

#_class_and_methodObject



164
165
166
# File 'lib/trace_tree/point.rb', line 164

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

#argObject



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

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

#argumentsObject



121
122
123
124
125
126
127
128
# File 'lib/trace_tree/point.rb', line 121

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)


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

def b_call?
  event == :b_call
end

#calleesObject



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

def callees
  @callees ||= []
end

#class?Boolean

Returns:

  • (Boolean)


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

def class?
  event == :class
end

#class_and_methodObject



160
161
162
# File 'lib/trace_tree/point.rb', line 160

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

#end_of_trace?Boolean

Returns:

  • (Boolean)


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

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

#inspectObject



134
135
136
# File 'lib/trace_tree/point.rb', line 134

def inspect
  to_h.inspect
end

#method_defined_by_define_method?Boolean

Returns:

  • (Boolean)


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

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

#method_nameObject



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

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

#return_valueObject



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

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

#source_locationObject



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

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

#terminate?(point) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
145
146
147
148
149
150
# File 'lib/trace_tree/point.rb', line 142

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)


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

def thread?
  event =~ /thread/
end

#thread_relative?Boolean

Returns:

  • (Boolean)


243
244
245
246
# File 'lib/trace_tree/point.rb', line 243

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

#to_hObject



138
139
140
# File 'lib/trace_tree/point.rb', line 138

def to_h
  self.class.hashify(self)
end

#x_return?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/trace_tree/point.rb', line 106

def x_return?
  event =~ /return/
end