@@ -71,11 +71,7 @@ class MaxStepsException < RuntimeError
7171pg_tracer = TracePoint . new ( :line , :class , :end , :call , :return , :raise , :b_call , :b_return ) do |tp |
7272 next if tp . path != '(eval)' # 'next' is a 'return' from a block
7373
74- # instruction_limit_reached - if you want to cap execution at a
75- # certain limit (e.g., 300 executed steps), issue this special event
76- # at the end. fill in the exception_msg field to say something like
77- # "(stopped after N steps to prevent possible infinite loop)"
78- raise MaxStepsException if n_steps >= MAX_STEPS
74+ raise MaxStepsException if n_steps > MAX_STEPS
7975
8076 STDERR . puts '---'
8177 STDERR . puts [ tp . event , tp . lineno , tp . path , tp . defined_class , tp . method_id ] . inspect
@@ -227,7 +223,7 @@ def self.iseq_local_variables iseq
227223 STDERR . puts
228224
229225 # massage the topmost stack entry
230- if stack
226+ if stack . length > 0
231227 stack [ 0 ] [ 'is_highlighted' ] = true
232228 if tp . event == :return || tp . event == :b_return
233229 stack [ 0 ] [ 'ordered_varnames' ] << '__return__'
@@ -290,7 +286,13 @@ def self.iseq_local_variables iseq
290286 # figure out what's a more desirable behavior here.)"
291287rescue MaxStepsException
292288 $stdout = STDOUT
289+
293290 puts "MaxStepsException -- OOOOOOOOOOOOOOOOOOOOOOOOOHHHHHHH!!!"
291+ # take the final trace entry & make it into a instruction_limit_reached event
292+ if cur_trace . length > 0
293+ cur_trace [ -1 ] [ 'event' ] = 'instruction_limit_reached'
294+ cur_trace [ -1 ] [ 'exception_msg' ] = "(stopped after %d steps to prevent possible infinite loop)" % MAX_STEPS
295+ end
294296rescue
295297 $stdout = STDOUT
296298 puts "other exception -- EEEEEEEE!!!"
0 commit comments