Forum: Ruby-core [ruby-trunk - Bug #7668][Assigned] set_trace_func and TracePoint don't handle exception in finish fr

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-01-07 07:01
(Received via mailing list)
Issue #7668 has been reported by ko1 (Koichi Sasada).

----------------------------------------
Bug #7668: set_trace_func and TracePoint don't handle exception in
finish frame
https://bugs.ruby-lang.org/issues/7668

Author: ko1 (Koichi Sasada)
Status: Assigned
Priority: Urgent
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2013-01-07 trunk 38719) [i686-linux]



The following code should trap exception correctly (should output
":ok"):

####
def m
  a = 1
  b = 2
  c = 3
  raise
end

trace = TracePoint.new{|tp|
  p tp
  raise # if tp.event == :c_return # if tp.event == :b_return
}

begin
  trace.enable{
    m
  }
rescue => e
  p :ok
end
####

But it outputs same event hook infinite:

#<TracePoint:b_call@/home/ko1/src/ruby/trunk/test.rb:15>
#<TracePoint:b_return@/home/ko1/src/ruby/trunk/test.rb:15>
#<TracePoint:c_return `enable'@/home/ko1/src/ruby/trunk/test.rb:15>
#<TracePoint:c_return `enable'@/home/ko1/src/ruby/trunk/test.rb:15>
#<TracePoint:c_return `enable'@/home/ko1/src/ruby/trunk/test.rb:15>
...

It is a bug.

This patch solve this issue:

Index: vm_trace.c
===================================================================
--- vm_trace.c  (revision 38718)
+++ vm_trace.c  (working copy)
@@ -316,7 +316,12 @@ rb_threadptr_exec_event_hooks_orig(rb_tr
   th->vm->trace_running--;

   if (state) {
-      if (pop_p) th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
+      if (pop_p) {
+    if (VM_FRAME_TYPE_FINISH_P(th->cfp)) {
+        th->tag = th->tag->prev;
+    }
+    th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
+      }
       TH_JUMP_TAG(th, state);
   }
   th->state = outer_state;


Output:
#<TracePoint:b_call@../trunk/test.rb:15>
#<TracePoint:b_return@../trunk/test.rb:15>
:ok
This topic is locked and can not be replied to.