[前][次][番号順一覧][スレッド一覧]

ruby-changes:62844

From: nagachika <ko1@a...>
Date: Sun, 6 Sep 2020 11:06:05 +0900 (JST)
Subject: [ruby-changes:62844] 3fef159f81 (ruby_2_7): merge revision(s) 3e02cd518fbe4d91c2aca7fbc3c5aafa387d3cb7: [Backport #17149]

https://git.ruby-lang.org/ruby.git/commit/?id=3fef159f81

From 3fef159f81fad6ffb9af5b60f4c8ec867fdb2391 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sun, 6 Sep 2020 11:05:52 +0900
Subject: merge revision(s) 3e02cd518fbe4d91c2aca7fbc3c5aafa387d3cb7: [Backport
 #17149]

	Trace :return of builtin methods

	using opt_invokebuiltin_delegate_leave insn.

	Since Ruby 2.7, :return of methods using builtin have not been traced properly.

diff --git a/insns.def b/insns.def
index bd1bffb..71b9f44 100644
--- a/insns.def
+++ b/insns.def
@@ -1508,7 +1508,7 @@ opt_invokebuiltin_delegate_leave https://github.com/ruby/ruby/blob/trunk/insns.def#L1508
     val = vm_invoke_builtin_delegate(ec, reg_cfp, bf, (unsigned int)index);
 
     /* leave fastpath */
-    /* TracePoint/return should fallback this insn to opt_invokebuiltin_delegate */
+    /* TracePoint/return fallbacks this insn to opt_invokebuiltin_delegate */
     if (vm_pop_frame(ec, GET_CFP(), GET_EP())) {
 #if OPT_CALL_THREADED_CODE
         rb_ec_thread_ptr(ec)->retval = val;
diff --git a/iseq.c b/iseq.c
index cbf6217..9f0f5d0 100644
--- a/iseq.c
+++ b/iseq.c
@@ -3094,8 +3094,12 @@ rb_vm_encoded_insn_data_table_init(void) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3094
     encoded_insn_data = st_init_numtable_with_size(VM_INSTRUCTION_SIZE / 2);
 
     for (insn = 0; insn < VM_INSTRUCTION_SIZE/2; insn++) {
+        int traced_insn = insn;
+        if (traced_insn == BIN(opt_invokebuiltin_delegate_leave)) {
+            traced_insn = BIN(opt_invokebuiltin_delegate); // to dispatch :return from leave
+        }
         st_data_t key1 = (st_data_t)INSN_CODE(insn);
-        st_data_t key2 = (st_data_t)INSN_CODE(insn + VM_INSTRUCTION_SIZE/2);
+        st_data_t key2 = (st_data_t)INSN_CODE(traced_insn + VM_INSTRUCTION_SIZE/2);
 
         insn_data[insn].insn = (int)insn;
         insn_data[insn].insn_len = insn_len(insn);
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index ada7b75..e9e22ae 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -2279,4 +2279,18 @@ class TestSetTraceFunc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L2279
   def test_stat_exists
     assert_instance_of Hash, TracePoint.stat
   end
+
+  def test_tracepoint_opt_invokebuiltin_delegate_leave
+    code = 'puts RubyVM::InstructionSequence.of("\x00".method(:unpack)).disasm'
+    out, _err, _status = EnvUtil.invoke_ruby(['-e', code], '', true)
+    assert_match /^0000 opt_invokebuiltin_delegate_leave /, out
+
+    events = []
+    TracePoint.new(:return) do |tp|
+      events << [tp.event, tp.method_id]
+    end.enable do
+      "\x00".unpack("c")
+    end
+    assert_equal [[:return, :unpack]], events
+  end
 end
diff --git a/version.h b/version.h
index de0ba11..eb34c6d 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 120
+#define RUBY_PATCHLEVEL 121
 
 #define RUBY_RELEASE_YEAR 2020
 #define RUBY_RELEASE_MONTH 9
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]