Bug 2252100 - Ruby's method:::* dtrace probes are not firing without TracePoint enabled
Summary: Ruby's method:::* dtrace probes are not firing without TracePoint enabled
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: ruby
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Vít Ondruch
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-11-29 14:01 UTC by Jarek Prokop
Modified: 2025-08-25 08:15 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:
jprokop: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker FC-2050 0 None None None 2025-08-25 08:15:16 UTC
Ruby 14582 0 None None None 2024-07-15 17:34:41 UTC

Description Jarek Prokop 2023-11-29 14:01:17 UTC
Ruby 2.5 introduced a change [0] that removed trace instructions from Ruby VM, this also lead to the dtrace probes of `ruby:::method-entry` and `ruby:::method-return` not firing by default. The TracePoint has to be enabled before the expected code block like so: `TracePoint.new{}.enable`.

These 2 probes are responsible for catching method call and return for Ruby-only methods. The `ruby:::cmethod*` probes are unaffected and are firing by default without needing to call anything extra as expected.

This is easily reproducible with Ruby 3.3 and Integer#times. To test with earlier rubies, other ruby-level method has to be found. Ruby 3.3 is easier to test this with because Integer#times was promoted to Ruby from C level [1], which exposed this problem.

Ruby 3.2 can use Integer#succ in place of Integer#times call.

[0] https://bugs.ruby-lang.org/issues/14104
[1] https://github.com/ruby/ruby/pull/8388

Reproducible: Always

Steps to Reproduce:
As root:
1. dnf install ruby ruby-doc ruby-libs systemtap
2. stap-prep
3. stap -s 100 -v /usr/share/doc/ruby-doc/ruby-exercise.stp  >ruby.log &
4. sleep 120 # wait for systemtap to be ready
5. ruby --disable-gems -e "5.times { printf \"Ruby!\n\" }'"

See ruby.log for results.

I verified reproduction works with at most Fedora 39, Fedora Rawhide fails on systemtap compilation at the moment.
Actual Results:  
Integer::times does not appear in logs.

Expected Results:  
`Integer::times` appears in log exactly twice. Once for entry and once on return. `Integer#succ` appears in between the `Integer::times` entry and return.

Workaround is to use TracePoint before code we want probes to fire for.
Like this: `ruby --disable-gems -e "TracePoint.new{}.enable; 5.times { printf \"Ruby!\n\" }'"`
This achieves expected results, but ideally should not be needed.

A patch was proposed:
~~~
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 9f9d0fcfd8..ee0a77e9fb 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -6489,7 +6489,6 @@ vm_trace_hook(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VAL
     if (event & global_hooks->events) {
         /* increment PC because source line is calculated with PC-1 */
         reg_cfp->pc++;
-        vm_dtrace(event, ec);
         rb_exec_event_hook_orig(ec, global_hooks, event, self, 0, 0, 0 , val, 0);
         reg_cfp->pc--;
     }
@@ -6622,6 +6621,8 @@ vm_trace(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)
                 vm_trace_hook(ec, reg_cfp, pc, RUBY_EVENT_RETURN, RUBY_EVENT_RETURN, global_hooks, bmethod_local_hooks_ptr, TOPN(0));
             }
 
+            vm_dtrace(pc_events & RUBY_EVENT_CALL, ec);
+
             // Pin the iseq since `local_hooks_ptr` points inside the iseq's slot on the GC heap.
             // We need the pointer to stay valid in case compaction happens in a trace hook.
             //
~~~
It does not seem to help.

I have 2 set of snippets to further illustrate the issue. One is using the tracepoint workaround, the other is executed without it. If there is "default" in filename it is Ruby without the patch, and if there is "patched" in the filename, the Ruby used has the patch applied.

Without using tracepoint, executed as as in reproducer: https://gitlab.com/-/snippets/3625897
With tracepoint, Ruby command is like in the workaround: https://gitlab.com/-/snippets/3625366

Comment 1 Aoife Moloney 2024-02-15 23:06:24 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 2 Vít Ondruch 2024-07-15 17:18:08 UTC
@jprokop Was this reported upstream?

Comment 3 Jarek Prokop 2024-07-15 17:24:03 UTC
We didn't report it ourselves as we later found a similar issue https://bugs.ruby-lang.org/issues/14582 (at least I think that's why there isn't a new entry from us), which is also where the patch in this issue was posted.

Comment 4 Aoife Moloney 2025-04-25 10:11:26 UTC
This message is a reminder that Fedora Linux 40 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 40 on 2025-05-13.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '40'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 40 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.


Note You need to log in before you can comment on or make changes to this bug.