Class: Argtrace::CallStack
- Inherits:
-
Object
- Object
- Argtrace::CallStack
- Defined in:
- lib/argtrace/tracer.rb
Overview
call stack of tracing targets
Instance Method Summary collapse
-
#find_by_block_location(path, lineno) ⇒ Object
find callinfo which use specific block.
-
#initialize ⇒ CallStack
constructor
A new instance of CallStack.
- #pop_callstack(tp) ⇒ Object
- #push_callstack(callinfo) ⇒ Object
Constructor Details
#initialize ⇒ CallStack
Returns a new instance of CallStack.
15 16 17 18 |
# File 'lib/argtrace/tracer.rb', line 15 def initialize # thread.object_id => stack @stack = Hash.new{|h,k| h[k] = []} end |
Instance Method Details
#find_by_block_location(path, lineno) ⇒ Object
find callinfo which use specific block
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/argtrace/tracer.rb', line 52 def find_by_block_location(path, lineno) id = Thread.current.object_id ret = [] @stack[id].each do |info| if info.block_proc && info.block_proc.source_location == [path, lineno] ret << info end end return ret end |
#pop_callstack(tp) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/argtrace/tracer.rb', line 28 def pop_callstack(tp) id = Thread.current.object_id ent = @stack[id].pop if ent # DEBUG: # p "[#{id}]<<" + " "*@stack[id].size*2 + ent.signature.to_s if tp.method_id != ent.signature.method_id raise <<~EOF callstack is broken returning by tracepoint: #{tp.defined_class}::#{tp.method_id} top of stack: #{ent.signature.to_s} rest of stack: #{@stack[id].map{|x| x.signature.to_s}.join("\n ")} EOF end type = TypeUnion.new type.add(Type.new_with_value(tp.return_value)) ent.signature.return_type = type end return ent end |
#push_callstack(callinfo) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/argtrace/tracer.rb', line 20 def push_callstack(callinfo) id = Thread.current.object_id # DEBUG: # p "[#{id}]>>" + " "*@stack[id].size*2 + callinfo.signature.to_s @stack[id].push callinfo end |