Skip to content

Fire compiled :line events every time with a :line-only TracePoint - #10101

Open
sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:tracepoint-line-sites
Open

sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:tracepoint-line-sites

Conversation

@sampokuokkanen

Copy link
Copy Markdown
Contributor

With --debug, a TracePoint that listens only to :line fires once per line in compiled code. That includes the main script, which is compiled when it is loaded even with the JIT disabled, and anything the JIT has compiled. A loop body, or a method that runs again, fires no more :line events. Debuggers built on TracePoint, like ruby/debug, miss breakpoints in loops because of this (ruby/debug#1120).

lines = []
tp = TracePoint.new(:line) { |t| lines << t.lineno if t.path == __FILE__ }
tp.enable
3.times do |i|
  i
end
tp.disable
p lines
$ jruby --debug loop.rb        # before
[4, 5, 7]
$ jruby --debug -X-C loop.rb   # interpreter, and CRuby
[4, 5, 5, 5, 7]

After its first run, a compiled trace point goes through one of four call sites in TraceEventManager. :call, :class, :end and :line share one, but it was only turned on for hooks that listen to :call or :return. :b_call and :b_return turned on both block sites together. Each site is now turned on for the events that use it, following JVMVisitor#TraceInstr, and all of them are turned off when the last hook is removed.

:class and :end were affected too. This isn't specced, because code loaded by mspec isn't compiled like a main script.

A second commit removes a fails: tag on TracePoint#lineno returns the line number of the event. A bulk tag run without --debug had added it, and the spec passes in both debug jobs.

With --debug, a TracePoint listening only to :line fired once per line
in compiled code, such as the main script, which is compiled when it
is loaded, and anything the JIT compiled. A loop body or a method that
ran again fired no more :line events, so debuggers missed breakpoints.

A compiled trace point runs through a call site of the trace event
manager after its first run. :call, :class, :end and :line share one
site, but the manager only enabled it for hooks that listen to :call
or :return. The block sites had the same problem, enabled only by
:b_call or :b_return together. Each site is now enabled for the events
that use it, and all are disabled when the last hook goes away.
The spec was tagged as failing in a bulk tag run made without --debug,
where TracePoint does not see line events. It was already tagged debug,
which keeps it out of those runs, and it passes in spec:ruby:debug and
spec:ruby:debug:jit.
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