Skip to content

Commit

Permalink
[Bug #19114] Fix for multiple calls of TracePoint#enable
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanagi authored and tenderlove committed Dec 12, 2023
1 parent 1f22245 commit 06e2fbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/ruby/test_settracefunc.rb
Expand Up @@ -2459,6 +2459,18 @@ def test_tracepoint_enable_with_target_line_two_times
assert_equal [:tp1, 1, 2, :tp2, 3], events
end

def test_multiple_enable
ary = []
trace = TracePoint.new(:call) do |tp|
ary << tp.method_id
end
trace.enable
trace.enable
foo
trace.disable
assert_equal(1, ary.count(:foo), '[Bug #19114]')
end

def test_multiple_tracepoints_same_bmethod
events = []
tp1 = TracePoint.new(:return) do |tp|
Expand Down
4 changes: 4 additions & 0 deletions vm_trace.c
Expand Up @@ -1197,6 +1197,10 @@ rb_tracepoint_enable(VALUE tpval)
rb_raise(rb_eArgError, "can't nest-enable a targeting TracePoint");
}

if (tp->tracing) {
return Qundef;
}

if (tp->target_th) {
rb_thread_add_event_hook2(tp->target_th->self, (rb_event_hook_func_t)tp_call_trace, tp->events, tpval,
RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
Expand Down

0 comments on commit 06e2fbb

Please sign in to comment.