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

ruby-changes:31120

From: ko1 <ko1@a...>
Date: Tue, 8 Oct 2013 21:08:30 +0900 (JST)
Subject: [ruby-changes:31120] ko1:r43199 (trunk): * vm_backtrace.c, include/ruby/debug.h: add new APIs

ko1	2013-10-08 21:08:20 +0900 (Tue, 08 Oct 2013)

  New Revision: 43199

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43199

  Log:
    * vm_backtrace.c, include/ruby/debug.h: add new APIs
    * VALUE rb_profile_frame_method_name(VALUE frame)
    * VALUE rb_profile_frame_qualified_method_name(VALUE frame)
    * iseq.c (rb_iseq_klass), internal.h: add new internal function
      rb_iseq_method_name().
    * ext/-test-/debug/profile_frames.c (profile_frames),
      test/-ext-/debug/test_profile_frames.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/ext/-test-/debug/profile_frames.c
    trunk/include/ruby/debug.h
    trunk/internal.h
    trunk/iseq.c
    trunk/test/-ext-/debug/test_profile_frames.rb
    trunk/vm_backtrace.c
Index: include/ruby/debug.h
===================================================================
--- include/ruby/debug.h	(revision 43198)
+++ include/ruby/debug.h	(revision 43199)
@@ -34,6 +34,8 @@ VALUE rb_profile_frame_base_label(VALUE https://github.com/ruby/ruby/blob/trunk/include/ruby/debug.h#L34
 VALUE rb_profile_frame_first_lineno(VALUE frame);
 VALUE rb_profile_frame_classpath(VALUE frame);
 VALUE rb_profile_frame_singleton_method_p(VALUE frame);
+VALUE rb_profile_frame_method_name(VALUE frame);
+VALUE rb_profile_frame_qualified_method_name(VALUE frame);
 
 /* debug inspector APIs */
 typedef struct rb_debug_inspector_struct rb_debug_inspector_t;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43198)
+++ ChangeLog	(revision 43199)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct  8 21:03:35 2013  Koichi Sasada  <ko1@a...>
+
+	* vm_backtrace.c, include/ruby/debug.h: add new APIs
+	  * VALUE rb_profile_frame_method_name(VALUE frame)
+	  * VALUE rb_profile_frame_qualified_method_name(VALUE frame)
+
+	* iseq.c (rb_iseq_klass), internal.h: add new internal function
+	  rb_iseq_method_name().
+
+	* ext/-test-/debug/profile_frames.c (profile_frames),
+	  test/-ext-/debug/test_profile_frames.rb: add a test.
+
 Tue Oct  8 16:11:11 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (rb_ary_uniq): use rb_hash_values(), as well as the case no
Index: iseq.c
===================================================================
--- iseq.c	(revision 43198)
+++ iseq.c	(revision 43199)
@@ -959,6 +959,20 @@ rb_iseq_klass(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L959
     return iseq->local_iseq->klass;
 }
 
+VALUE
+rb_iseq_method_name(VALUE self)
+{
+    rb_iseq_t *iseq, *local_iseq;
+    GetISeqPtr(self, iseq);
+    local_iseq = iseq->local_iseq;
+    if (local_iseq->type == ISEQ_TYPE_METHOD) {
+	return local_iseq->location.base_label;
+    }
+    else {
+	return Qnil;
+    }
+}
+
 static
 VALUE iseq_data_to_ary(rb_iseq_t *iseq);
 
Index: vm_backtrace.c
===================================================================
--- vm_backtrace.c	(revision 43198)
+++ vm_backtrace.c	(revision 43199)
@@ -1287,3 +1287,30 @@ rb_profile_frame_singleton_method_p(VALU https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L1287
 	return Qfalse;
     }
 }
+
+VALUE
+rb_profile_frame_method_name(VALUE frame)
+{
+    return rb_iseq_method_name(frame2iseq(frame));
+}
+
+VALUE
+rb_profile_frame_qualified_method_name(VALUE frame)
+{
+    VALUE method_name = rb_iseq_method_name(frame2iseq(frame));
+    if (method_name != Qnil) {
+	VALUE classpath = rb_profile_frame_classpath(frame);
+	VALUE singleton_p = rb_profile_frame_singleton_method_p(frame);
+
+	if (classpath != Qnil) {
+	    return rb_sprintf("%"PRIsVALUE"%s%"PRIsVALUE,
+			      classpath, singleton_p == Qtrue ? "." : "#", method_name);
+	}
+	else {
+	    return method_name;
+	}
+    }
+    else {
+	return Qnil;
+    }
+}
Index: ext/-test-/debug/profile_frames.c
===================================================================
--- ext/-test-/debug/profile_frames.c	(revision 43198)
+++ ext/-test-/debug/profile_frames.c	(revision 43199)
@@ -26,6 +26,8 @@ profile_frames(VALUE self, VALUE start_v https://github.com/ruby/ruby/blob/trunk/ext/-test-/debug/profile_frames.c#L26
 	rb_ary_push(ary, rb_profile_frame_first_lineno(buff[i]));
 	rb_ary_push(ary, rb_profile_frame_classpath(buff[i]));
 	rb_ary_push(ary, rb_profile_frame_singleton_method_p(buff[i]));
+	rb_ary_push(ary, rb_profile_frame_method_name(buff[i]));
+	rb_ary_push(ary, rb_profile_frame_qualified_method_name(buff[i]));
 
 	rb_ary_push(result, ary);
     }
Index: internal.h
===================================================================
--- internal.h	(revision 43198)
+++ internal.h	(revision 43199)
@@ -457,6 +457,7 @@ VALUE rb_iseq_label(VALUE iseqval); https://github.com/ruby/ruby/blob/trunk/internal.h#L457
 VALUE rb_iseq_base_label(VALUE iseqval);
 VALUE rb_iseq_first_lineno(VALUE iseqval);
 VALUE rb_iseq_klass(VALUE iseqval); /* completely temporary fucntion */
+VALUE rb_iseq_method_name(VALUE self);
 
 /* load.c */
 VALUE rb_get_load_path(void);
Index: test/-ext-/debug/test_profile_frames.rb
===================================================================
--- test/-ext-/debug/test_profile_frames.rb	(revision 43198)
+++ test/-ext-/debug/test_profile_frames.rb	(revision 43199)
@@ -2,8 +2,14 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/-ext-/debug/test_profile_frames.rb#L2
 require '-test-/debug'
 
 class SampleClassForTestProfileFrames
+  class Sample2
+    def baz(block)
+      block.call
+    end
+  end
+  
   def self.bar(block)
-    block.call
+    Sample2.new.baz(block)
   end
 
   def foo(block)
@@ -17,31 +23,49 @@ class TestProfileFrames < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/debug/test_profile_frames.rb#L23
       Fiber.yield SampleClassForTestProfileFrames.new.foo(lambda{ Bug::Debug.profile_frames(0, 10) })
     }.resume
 
-    assert_equal(4, frames.size)
-
     labels = [
       "block (2 levels) in test_profile_frames",
+      "baz",
       "bar",
       "foo",
       "block in test_profile_frames",
     ]
     base_labels = [
       "test_profile_frames",
+      "baz",
       "bar",
       "foo",
       "test_profile_frames",
     ]
     classes = [
       TestProfileFrames,
+      SampleClassForTestProfileFrames::Sample2,
       SampleClassForTestProfileFrames, # singleton method
       SampleClassForTestProfileFrames,
       TestProfileFrames,
     ]
     singleton_method_p = [
-      false, true, false, false, false,
+      false, false, true, false, false, false,
     ]
+    methdo_names = [
+      "test_profile_frames",
+      "baz",
+      "bar",
+      "foo",
+      "test_profile_frames",
+    ]
+    qualified_method_names = [
+      "TestProfileFrames#test_profile_frames",
+      "SampleClassForTestProfileFrames::Sample2#baz",
+      "SampleClassForTestProfileFrames.bar",
+      "SampleClassForTestProfileFrames#foo",
+      "TestProfileFrames#test_profile_frames",
+    ]
+
+    assert_equal(labels.size, frames.size)
 
-    frames.each.with_index{|(path, absolute_path, label, base_label, first_lineno, classpath, singleton_p), i|
+    frames.each.with_index{|(path, absolute_path, label, base_label, first_lineno,
+                            classpath, singleton_p, method_name, qualified_method_name), i|
       err_msg = "#{i}th frame"
       assert_equal(__FILE__, path, err_msg)
       assert_equal(__FILE__, absolute_path, err_msg)
@@ -49,6 +73,8 @@ class TestProfileFrames < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/debug/test_profile_frames.rb#L73
       assert_equal(base_labels[i], base_label, err_msg)
       assert_equal(classes[i].to_s, classpath, err_msg)
       assert_equal(singleton_method_p[i], singleton_p, err_msg)
+      assert_equal(methdo_names[i], method_name, err_msg)
+      assert_equal(qualified_method_names[i], qualified_method_name, err_msg)
     }
   end
 end

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

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