Bug #7668

set_trace_func and TracePoint don't handle exception in finish frame

Added by Koichi Sasada over 1 year ago. Updated over 1 year ago.

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

Description

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 == :creturn # if tp.event == :breturn
}

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
#
#
#
...

It is a bug.

This patch solve this issue:

Index: vm_trace.c

--- vmtrace.c (revision 38718)
+++ vm
trace.c (working copy)
@@ -316,7 +316,12 @@ rbthreadptrexeceventhooksorig(rbtr
th->vm->trace_running--;

if (state) {
  • if (popp) th->cfp = RUBYVMPREVIOUSCONTROL_FRAME(th->cfp);
  • if (pop_p) {
  • if (VMFRAMETYPEFINISHP(th->cfp)) {
  • th->tag = th->tag->prev;
  • }
  • th->cfp = RUBYVMPREVIOUSCONTROLFRAME(th->cfp);
  • } THJUMPTAG(th, state); } th->state = outer_state;

Output:
#TracePoint:b_call@../trunk/test.rb:15
#TracePoint:b_return@../trunk/test.rb:15
:ok

Associated revisions

Revision 38721
Added by Koichi Sasada over 1 year ago

  • vmtrace.c (rbthreadptrexeceventhooksorig): pop tag before JUMP_TAG() if frame is `finish' frame. Without this patch, there is an inconsistency between control frame stack and tags stack. [Bug #7668]
  • test/ruby/test_settracefunc.rb: add a test for above.

History

#1 Updated by Koichi Sasada over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38721.
Koichi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vmtrace.c (rbthreadptrexeceventhooksorig): pop tag before JUMP_TAG() if frame is `finish' frame. Without this patch, there is an inconsistency between control frame stack and tags stack. [Bug #7668]
  • test/ruby/test_settracefunc.rb: add a test for above.

Also available in: Atom PDF