Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions core/src/main/java/org/jruby/runtime/TraceEventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,29 @@ public synchronized void removeEventHook(EventHook hook) {
if (newHooks.length == 0) {
hasEventHooks = false;

disableTraceSites(hook);
disableTraceSites();
}
}

// Compiled trace sites bind to these call sites after their first run (CallTraceSite.traceBootstrap).
// The event to site mapping follows JVMVisitor#TraceInstr: CALL, CLASS, END and LINE share callTrace,
// RETURN uses returnValueTrace, B_CALL uses bcallTrace and B_RETURN uses bReturnValueTrace.
private void enableTraceSites(EventHook hook) {
if (hook.isInterestedInEvent(RubyEvent.CALL) || hook.isInterestedInEvent(RubyEvent.RETURN)) {
if (hook.isInterestedInEvent(RubyEvent.CALL) || hook.isInterestedInEvent(RubyEvent.CLASS) ||
hook.isInterestedInEvent(RubyEvent.END) || hook.isInterestedInEvent(RubyEvent.LINE)) {
callTrace.setTarget(TRACE_ON);
returnValueTrace.setTarget(VALUE_TRACE_ON);
}

if (hook.isInterestedInEvent(RubyEvent.B_CALL) || hook.isInterestedInEvent(RubyEvent.B_RETURN)) {
bcallTrace.setTarget(B_TRACE_ON);
bReturnValueTrace.setTarget(B_VALUE_TRACE_ON);
if (hook.isInterestedInEvent(RubyEvent.RETURN)) {
returnValueTrace.setTarget(VALUE_TRACE_ON);
}
}

private void disableTraceSites(EventHook hook) {
if (hook.isInterestedInEvent(RubyEvent.CALL) || hook.isInterestedInEvent(RubyEvent.RETURN)) {
callTrace.setTarget(TRACE_OFF);
returnValueTrace.setTarget(VALUE_TRACE_OFF);
if (hook.isInterestedInEvent(RubyEvent.B_CALL)) {
bcallTrace.setTarget(B_TRACE_ON);
}

if (hook.isInterestedInEvent(RubyEvent.B_CALL) || hook.isInterestedInEvent(RubyEvent.B_RETURN)) {
bcallTrace.setTarget(B_TRACE_OFF);
bReturnValueTrace.setTarget(B_VALUE_TRACE_OFF);
if (hook.isInterestedInEvent(RubyEvent.B_RETURN)) {
bReturnValueTrace.setTarget(B_VALUE_TRACE_ON);
}
}

Expand Down
14 changes: 14 additions & 0 deletions spec/ruby/core/tracepoint/lineno_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
lineno.should == __LINE__ - 2
end

it 'is reported each time a line runs again' do
lines = []
tp = TracePoint.new(:line) { |t|
next unless TracePointSpec.target_thread?
lines << t.lineno if t.path == __FILE__
}
tp.enable do
3.times do
line_event = true
end
end
lines.should == [__LINE__ - 4, __LINE__ - 3, __LINE__ - 3, __LINE__ - 3]
end

it 'raises RuntimeError if accessed from outside' do
tp = TracePoint.new(:line) {}
-> { tp.lineno }.should.raise(RuntimeError, 'access from outside')
Expand Down
2 changes: 1 addition & 1 deletion spec/tags/ruby/core/tracepoint/lineno_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
debug:TracePoint#lineno returns the line number of the event
fails:TracePoint#lineno returns the line number of the event
debug:TracePoint#lineno is reported each time a line runs again
Loading