Project

General

Profile

Actions

Bug #8886

closed

TracePoint API inconsistence when raise used

Added by deivid (David Rodríguez) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
[ruby-core:57109]

Description

=begin
When raise command is used, the TracePoint API triggers the following events in the following order

1. RUBY_EVENT_C_CALL to the `raise` method
2. RUBY_EVENT_RAISE
3. RUBY_EVENT_C_RETURN

But what ruby actually does is

1. Push frame into the stack when calling the `raise` c method.
2. Pop frame from the stack
3. And after popping the frame, raise the exception.

As you can see, 2 and 3 are reversed and this messes up byebug and (I guess) other users of the API.

To illustrate I use a similar program as I used in (invalid) #8538

tp = TracePoint.trace do |tp|
  warn "%-8s %-11p" % [tp.event, tp.method_id]
end
raise "bang"

Actual output

c_return :trace     
line     nil        
c_call   :raise     
c_call   :new       
c_call   :initialize
c_return :initialize
c_return :new       
c_call   :backtrace 
c_return :backtrace 
raise    nil        
c_return :raise     
test_bug.rb:4:in `<main>': bang (RuntimeError)

Expected output

c_return :trace     
line     nil        
c_call   :raise     
c_call   :new       
c_call   :initialize
c_return :initialize
c_return :new
c_return :raise     
c_call   :backtrace 
c_return :backtrace 
raise    nil        
test_bug.rb:4:in `<main>': bang (RuntimeError)

I've made a patch that solves the issue and, as a result, the problems byebug is having. Please review and excuse me if I'm not being able to properly explain myself.

Thanks a lot!
=end


Files

tracepoint_raise.patch (2.44 KB) tracepoint_raise.patch deivid (David Rodríguez), 09/10/2013 08:03 PM
raise_exception_inside_raise_method.patch (3.83 KB) raise_exception_inside_raise_method.patch deivid (David Rodríguez), 10/11/2013 10:42 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0