Skip to content

Commit 93d13d3

Browse files
committed
bah
1 parent 633e218 commit 93d13d3

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

‎v4-cokapi/backends/ruby/pg_logger.rb‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
# - render exception events properly
1212
# - limit execution to N steps -- use instruction_limit_reached event type
1313
# - catch the execution of the LAST line in a user's script
14+
# - display TRUE global $variables rather than just locals of the top-most frame
15+
# - support recursive calls with function ids
1416
#
15-
# Limitation: no support for (lexical) environment pointers, since MRI
16-
# doesn't seem to expose them. We can see only the current (dynamic) stack.
17+
# Limitations:
18+
# - no support for (lexical) environment pointers, since MRI doesn't seem to
19+
# expose them. We can see only the current (dynamic) stack backtrace
20+
# with debug_inspector.
1721

1822
# style guide: https://github.com/styleguide/ruby
1923

24+
2025
require 'json'
2126
require 'debug_inspector' # gem install debug_inspector, use on Ruby 2.X
2227

@@ -28,9 +33,18 @@
2833
cur_trace = []
2934
res = {'code' => cod, 'trace' => cur_trace}
3035

36+
cur_frame_id = 1
37+
3138
pg_tracer = TracePoint.new(:line,:class,:end,:call,:return,:raise,:b_call,:b_return) do |tp|
3239
next if tp.path != '(eval)' # 'next' is a 'return' from a block
3340

41+
puts '---'
42+
43+
# inject a frame_id variable into the function's frame
44+
if tp.event == :call || tp.event == :b_call
45+
puts 'CALLLL'
46+
end
47+
3448
p [tp.event, tp.lineno, tp.path, tp.defined_class, tp.method_id]
3549
# TODO: look into tp.defined_class and tp.method_id attrs
3650
# TODO: look into tp.raised_exception and tp.return_value attrs
@@ -64,14 +78,14 @@ def self.iseq_local_variables iseq
6478
end
6579

6680
# adapted from https://github.com/ko1/pretty_backtrace/blob/master/lib/pretty_backtrace.rb
67-
RubyVM::DebugInspector.open{|dc|
81+
RubyVM::DebugInspector.open do |dc|
6882
locs = dc.backtrace_locations
6983

70-
effective_lines = locs.size - 2
71-
72-
pretty_backtrace = locs.map.with_index{|loc, i|
84+
locs.each.with_index do |loc, i|
85+
# ignore first two boilerplate frames
7386
next if i < 2
74-
next loc.to_s unless (effective_lines -= 1) >= 0
87+
# and totally punt as soon as you hit the 'eval' frame
88+
break if /in `eval'/ =~ loc.to_s
7589

7690
iseq = dc.frame_iseq(i)
7791

@@ -92,14 +106,11 @@ def self.iseq_local_variables iseq
92106
end
93107

94108
#modify_trace_line loc, loc.absolute_path, loc.lineno, lvs_val
95-
if loc.lineno == 113 # HACKY STENT FOR FILTERING!
96-
puts
97-
else
98-
print loc, ' ', lvs_val
99-
puts
100-
end
101-
}.compact
102-
}
109+
110+
print '>>> ', loc, ' ', lvs_val
111+
puts
112+
end
113+
end
103114

104115
puts
105116

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# generic recursive factorial to test support for recursive calls
2+
3+
def fact n
4+
if n <= 1
5+
n
6+
else
7+
n * fact(n-1)
8+
end
9+
end
10+
11+
puts fact 5

0 commit comments

Comments
 (0)