Avoid trace events in implementation of TracePoint#enable
This is more backwards compatible, and should fix issues with power_assert. Unfortunately, it requires using a sentinel value as the default value of target_thread, instead of the more natural expression used in the original approach.
This commit is contained in:
parent
9c1d32a7ad
commit
3c6a0033e3
Notes:
git
2022-03-30 10:15:03 +09:00
@ -2290,7 +2290,7 @@ CODE
|
|||||||
events << :___
|
events << :___
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_equal [:tp1, :tp1, :tp1, :tp1, :tp1, :tp2, :tp1, :___], events
|
assert_equal [:tp1, :tp1, :tp1, :tp1, :tp2, :tp1, :___], events
|
||||||
|
|
||||||
# success with two tracepoints (targeting/global)
|
# success with two tracepoints (targeting/global)
|
||||||
events = []
|
events = []
|
||||||
|
@ -153,7 +153,7 @@ class TracePoint
|
|||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# trace.enable(target: nil, target_line: nil, target_thread: nil) -> true or false
|
# trace.enable(target: nil, target_line: nil, target_thread: nil) -> true or false
|
||||||
# trace.enable(target: nil, target_line: nil, target_thread: Thread.current) { block } -> obj
|
# trace.enable(target: nil, target_line: nil, target_thread: :default) { block } -> obj
|
||||||
#
|
#
|
||||||
# Activates the trace.
|
# Activates the trace.
|
||||||
#
|
#
|
||||||
@ -209,7 +209,7 @@ class TracePoint
|
|||||||
# trace.enable { p tp.lineno }
|
# trace.enable { p tp.lineno }
|
||||||
# #=> RuntimeError: access from outside
|
# #=> RuntimeError: access from outside
|
||||||
#
|
#
|
||||||
def enable(target: nil, target_line: nil, target_thread: (Thread.current if target.nil? && target_line.nil? && defined?(yield)))
|
def enable(target: nil, target_line: nil, target_thread: :default)
|
||||||
Primitive.tracepoint_enable_m(target, target_line, target_thread)
|
Primitive.tracepoint_enable_m(target, target_line, target_thread)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
vm_trace.c
13
vm_trace.c
@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
|
|
||||||
|
static VALUE sym_default;
|
||||||
|
|
||||||
/* (1) trace mechanisms */
|
/* (1) trace mechanisms */
|
||||||
|
|
||||||
typedef struct rb_event_hook_struct {
|
typedef struct rb_event_hook_struct {
|
||||||
@ -1334,6 +1336,15 @@ tracepoint_enable_m(rb_execution_context_t *ec, VALUE tpval, VALUE target, VALUE
|
|||||||
rb_tp_t *tp = tpptr(tpval);
|
rb_tp_t *tp = tpptr(tpval);
|
||||||
int previous_tracing = tp->tracing;
|
int previous_tracing = tp->tracing;
|
||||||
|
|
||||||
|
if (target_thread == sym_default) {
|
||||||
|
if (rb_block_given_p() && NIL_P(target) && NIL_P(target_line)) {
|
||||||
|
target_thread = rb_thread_current();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
target_thread = Qnil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* check target_thread */
|
/* check target_thread */
|
||||||
if (RTEST(target_thread)) {
|
if (RTEST(target_thread)) {
|
||||||
if (tp->target_th) {
|
if (tp->target_th) {
|
||||||
@ -1563,6 +1574,8 @@ tracepoint_allow_reentry(rb_execution_context_t *ec, VALUE self)
|
|||||||
void
|
void
|
||||||
Init_vm_trace(void)
|
Init_vm_trace(void)
|
||||||
{
|
{
|
||||||
|
sym_default = ID2SYM(rb_intern_const("default"));
|
||||||
|
|
||||||
/* trace_func */
|
/* trace_func */
|
||||||
rb_define_global_function("set_trace_func", set_trace_func, 1);
|
rb_define_global_function("set_trace_func", set_trace_func, 1);
|
||||||
rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1);
|
rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user