aboutsummaryrefslogtreecommitdiffstats
path: root/vm_trace.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-12-27 14:08:59 -0800
committerJeremy Evans <code@jeremyevans.net>2022-03-29 18:14:33 -0700
commit3c6a0033e3dc7da2898232a2efc7367ae6fc536a (patch)
tree0c640243614fa10e282eaab401b9a9ff9b94c0e3 /vm_trace.c
parent9c1d32a7ada794ecd0356d56f7be3cdf3982d8ac (diff)
downloadruby-3c6a0033e3dc7da2898232a2efc7367ae6fc536a.tar.gz
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.
Diffstat (limited to 'vm_trace.c')
-rw-r--r--vm_trace.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/vm_trace.c b/vm_trace.c
index b9ba6de73e..a9074c338e 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -34,6 +34,8 @@
#include "builtin.h"
+static VALUE sym_default;
+
/* (1) trace mechanisms */
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);
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 */
if (RTEST(target_thread)) {
if (tp->target_th) {
@@ -1563,6 +1574,8 @@ tracepoint_allow_reentry(rb_execution_context_t *ec, VALUE self)
void
Init_vm_trace(void)
{
+ sym_default = ID2SYM(rb_intern_const("default"));
+
/* trace_func */
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);