Bug #9759

[TracePoint API] return event missing when raising exception

Added by David Rodríguez about 1 year ago. Updated 6 months ago.

[ruby-core:62096]
Status:Assigned
Priority:Normal
Assignee:Koichi Sasada
ruby -v:https://github.com/thoughtbot/factory_girl/blob/master/lib/factory_girl/strategy_syntax_method_registrar.rb Backport:2.0.0: REQUIRED, 2.1: DONE

Description

I think I found another bug in the TracePoint API, which seems related to #9321. In this case, the failing event is a return event from a method inside of which the exception was generated.

I wrote a failing test case, adapting the code from factory_girl, which is where I first found the strange behaviour.

Thanks a lot in advance!

tracepoint_missing_return_bug.rb Magnifier (1.37 KB) David Rodríguez, 04/19/2014 12:08 PM

Associated revisions

Revision 45758
Added by Koichi Sasada about 1 year ago

  • vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record it is bmethod frame.
  • vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame is VM_FRAME_FLAG_BMETHOD. [Bug #9759]
  • test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
  • vm_core.h: renmae rb_thread_t::passed_me to rb_thread_t::passed_bmethod_me to clarify the usage.
  • vm_insnhelper.c (vm_call_bmethod_body): use renamed member.

Revision 45758
Added by Koichi Sasada about 1 year ago

  • vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record it is bmethod frame.
  • vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame is VM_FRAME_FLAG_BMETHOD. [Bug #9759]
  • test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
  • vm_core.h: renmae rb_thread_t::passed_me to rb_thread_t::passed_bmethod_me to clarify the usage.
  • vm_insnhelper.c (vm_call_bmethod_body): use renamed member.

Revision 45928
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) r45758,r45759: [Backport #9759]

* vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record
  it is bmethod frame.

* vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame
  is VM_FRAME_FLAG_BMETHOD.
  [Bug #9759]

* test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.

* vm_core.h: rename rb_thread_t::passed_me to
  rb_thread_t::passed_bmethod_me to clarify the usage.

* vm_insnhelper.c (vm_call_bmethod_body): use renamed member.

History

#1 Updated by David Rodríguez about 1 year ago

Also, I'm not sure whether those [:b_call, :create] and [:b_return, :create] events should be emitted at all. The block is run when defining the method, not when running it... Right?

#2 Updated by David Rodríguez about 1 year ago

Bump, @ko1?

#3 Updated by Koichi Sasada about 1 year ago

  • Category set to core
  • Assignee set to Koichi Sasada

#4 Updated by Koichi Sasada about 1 year ago

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

Applied in changeset r45758.


  • vm.c (invoke_block_from_c): add VM_FRAME_FLAG_BMETHOD to record it is bmethod frame.
  • vm.c (vm_exec): invoke RUBY_EVENT_RETURN event if rollbacked frame is VM_FRAME_FLAG_BMETHOD. [Bug #9759]
  • test/ruby/test_settracefunc.rb: add a test for TracePoint/set_trace_func.
  • vm_core.h: renmae rb_thread_t::passed_me to rb_thread_t::passed_bmethod_me to clarify the usage.
  • vm_insnhelper.c (vm_call_bmethod_body): use renamed member.

#5 Updated by Koichi Sasada about 1 year ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: UNKNOWN, 2.1: REQUIRED

It can be reproduced by the following code:

  class C9759
    define_method(:foo){
      raise
    }
  end

  events = []
  obj = C9759.new
  TracePoint.new(:call, :return){|tp|
    events << [tp.event, tp.method_id]
  }.enable{
    obj.foo rescue nil
  }
  p events

I hope this fix will be applied to 2.1.

#6 Updated by David Rodríguez about 1 year ago

Thanks!! So happy that this got fixed!! I hope it'll be added to 2.1 too.

#7 Updated by Tomoyuki Chikanaga about 1 year ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: REQUIRED to 2.0.0: UNKNOWN, 2.1: DONE

r45758 and r45759 were backported into ruby_2_1 branch at r45928.

#8 Updated by David Rodríguez about 1 year ago

Hi @Tomoyuki, thanks a lot for backporting this. May I ask for backdport of r44535 as well? It's a related fix and it would really improve byebug's quality and other programs using the tracepoint api.

Furthermore, both revisions would also be needed in the 2.0 branch.

Thanks a lot!!

#9 Updated by Tomoyuki Chikanaga 11 months ago

Hello, David.

Sorry for late response.
I'll handle about r44535 at #9321.
Thank you for your notice!

#10 Updated by David Rodríguez 11 months ago

Hi Tomoyuki! I´ll follow up at #9321 then. What about backports to 2.0 branch?

Thanks a lot!

#11 Updated by Usaku NAKAMURA 11 months ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: DONE to 2.0.0: REQUIRED, 2.1: DONE

r45758 is not enough to resolve this problem for ruby_2_0_0.
But I cannot find what is missing.
ko1, do you have any idea?

#12 Updated by David Rodríguez 10 months ago

Yes, maybe he is aware of this because he only asked for backport to the 2.1 branch. Can you help us, ko1?

#13 Updated by Usaku NAKAMURA 9 months ago

  • Status changed from Closed to Assigned

(reminder)

#14 Updated by David Rodríguez 6 months ago

Did you get the chance to have a look at this, ko1? Thanks!

Also available in: Atom PDF