Skip to content

Report the end line at TracePoint :return and :b_return events - #10103

Open
sampokuokkanen wants to merge 1 commit into
jruby:masterfrom
sampokuokkanen:tracepoint-return-lines
Open

sampokuokkanen wants to merge 1 commit into
jruby:masterfrom
sampokuokkanen:tracepoint-return-lines

Conversation

@sampokuokkanen

Copy link
Copy Markdown
Contributor

With --debug, the :return event at the end of a method reports the line before its end. The :b_return event reports the right line, but during the hook the block is still at its last expression in the backtrace. CRuby reports the end line in both places. Debuggers built on TracePoint, like ruby/debug, show the backtrace line, so they disagree with the event (ruby/debug#1120).

def m
  :m
end
tp = TracePoint.new(:return, :b_return) do |t|
  p [t.event, t.lineno, caller_locations(1, 1)[0].lineno]
end
tp.enable
m
[1].each { |x|
  x
}
tp.disable
$ jruby --debug return_lines.rb   # before
[:return, 2, 3]
[:b_return, 11, 10]
$ jruby --debug return_lines.rb   # after, and CRuby
[:return, 3, 3]
[:b_return, 11, 11]

The :return trace got the 0-based end line, while the other events get a 1-based line. Blocks and lambdas now set their end line before :b_return, as methods already did before :return.

With --debug, the :return event at the end of a method reported the
line before its end, because the end line was passed to the trace
without converting it to a 1-based line as the other events do. The
:b_return event reported the right line, but the block was still at
the line of its last expression in the backtrace, so a debugger showed
a different line than the event. A block or lambda is now at its end
line while the hook runs, as a method already was for :return.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant