summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-08-16 10:27:28 -0400
committerPeter Zhu <[email protected]>2024-08-16 16:12:49 -0400
commit2fe6a4f84d2bcf97d3be9bffa5f3232604201f55 (patch)
treea02da513d5d29943754f95ead308b32a45970af0
parent77ac853c15ef64bfc663e4b91a0707b549b940eb (diff)
Fix assertion error when TracePoint has incompatible events
TracePoints with incompatible events (i.e. events not in ISEQ_TRACE_EVENTS) with a method target will fail an assertion error because it does not filter for the supported events. For example, the following lines will cause an assertion error: def foo; end # No arguments passed into TracePoint.new enables all ISEQ_TRACE_EVENTS TracePoint.new {}.enable(target: method(:foo)) # Raise is not supported with a target TracePoint.new(:raise, :return) {}.enable(target: method(:foo)) foo Crashes with: Assertion Failed: vm_insnhelper.c:7026:vm_trace:(iseq_local_events & ~(0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010| 0x0020| 0x0040 | 0x0100 | 0x0200 | 0x4000 | 0x010000| 0x020000)) == 0
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11390
-rw-r--r--test/ruby/test_settracefunc.rb24
-rw-r--r--vm_trace.c2
2 files changed, 17 insertions, 9 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 3480ef2d4a..1ad86744ef 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -2307,7 +2307,7 @@ CODE
_c = a + b
end
- def check_with_events *trace_events
+ def check_with_events(trace_point_events, expected_events = trace_point_events)
all_events = [[:call, :method_for_enable_target1],
[:line, :method_for_enable_target1],
[:line, :method_for_enable_target1],
@@ -2329,7 +2329,7 @@ CODE
[:return, :method_for_enable_target1],
]
events = []
- TracePoint.new(*trace_events) do |tp|
+ TracePoint.new(*trace_point_events) do |tp|
next unless target_thread?
events << [tp.event, tp.method_id]
end.enable(target: method(:method_for_enable_target1)) do
@@ -2337,15 +2337,23 @@ CODE
method_for_enable_target2
method_for_enable_target1
end
- assert_equal all_events.find_all{|(ev)| trace_events.include? ev}, events
+
+ exp_events = all_events
+ assert_equal all_events.keep_if { |(ev)| expected_events.include? ev }, events
end
def test_tracepoint_enable_target
- check_with_events :line
- check_with_events :call, :return
- check_with_events :line, :call, :return
- check_with_events :call, :return, :b_call, :b_return
- check_with_events :line, :call, :return, :b_call, :b_return
+ check_with_events([:line])
+ check_with_events([:call, :return])
+ check_with_events([:line, :call, :return])
+ check_with_events([:call, :return, :b_call, :b_return])
+ check_with_events([:line, :call, :return, :b_call, :b_return])
+
+ # No arguments passed into TracePoint.new enables all ISEQ_TRACE_EVENTS
+ check_with_events([], [:line, :class, :end, :call, :return, :c_call, :c_return, :b_call, :b_return, :rescue])
+
+ # Raise event should be ignored
+ check_with_events([:line, :raise])
end
def test_tracepoint_nested_enabled_with_target
diff --git a/vm_trace.c b/vm_trace.c
index 0f99e34e7b..7f3f3cd6f4 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -1342,7 +1342,7 @@ void
rb_hook_list_connect_tracepoint(VALUE target, rb_hook_list_t *list, VALUE tpval, unsigned int target_line)
{
rb_tp_t *tp = tpptr(tpval);
- rb_event_hook_t *hook = alloc_event_hook((rb_event_hook_func_t)tp_call_trace, tp->events, tpval,
+ rb_event_hook_t *hook = alloc_event_hook((rb_event_hook_func_t)tp_call_trace, tp->events & ISEQ_TRACE_EVENTS, tpval,
RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
hook->filter.target_line = target_line;
hook_list_connect(target, list, hook, FALSE);