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

ruby-changes:31126

From: ko1 <ko1@a...>
Date: Wed, 9 Oct 2013 09:22:00 +0900 (JST)
Subject: [ruby-changes:31126] ko1:r43205 (trunk): * include/ruby/debug.h,

ko1	2013-10-09 09:21:51 +0900 (Wed, 09 Oct 2013)

  New Revision: 43205

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

  Log:
    * include/ruby/debug.h,
      vm_backtrace.c (rb_profile_frame_full_label): add new C API
      rb_profile_frame_full_label() which returns label with
      qualified method name.
      Note that in future version of Ruby label() may return
      same return value of full_label().
    * ext/-test-/debug/profile_frames.c,
      test/-ext-/debug/test_profile_frames.rb: fix a test for this change.

  Modified files:
    trunk/ChangeLog
    trunk/ext/-test-/debug/profile_frames.c
    trunk/include/ruby/debug.h
    trunk/test/-ext-/debug/test_profile_frames.rb
    trunk/vm_backtrace.c
Index: include/ruby/debug.h
===================================================================
--- include/ruby/debug.h	(revision 43204)
+++ include/ruby/debug.h	(revision 43205)
@@ -31,6 +31,7 @@ VALUE rb_profile_frame_path(VALUE frame) https://github.com/ruby/ruby/blob/trunk/include/ruby/debug.h#L31
 VALUE rb_profile_frame_absolute_path(VALUE frame);
 VALUE rb_profile_frame_label(VALUE frame);
 VALUE rb_profile_frame_base_label(VALUE frame);
+VALUE rb_profile_frame_full_label(VALUE frame);
 VALUE rb_profile_frame_first_lineno(VALUE frame);
 VALUE rb_profile_frame_classpath(VALUE frame);
 VALUE rb_profile_frame_singleton_method_p(VALUE frame);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43204)
+++ ChangeLog	(revision 43205)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct  9 09:18:14 2013  Koichi Sasada  <ko1@a...>
+
+	* include/ruby/debug.h,
+	  vm_backtrace.c (rb_profile_frame_full_label): add new C API
+	  rb_profile_frame_full_label() which returns label with
+	  qualified method name.
+	  Note that in future version of Ruby label() may return
+	  same return value of full_label().
+
+	* ext/-test-/debug/profile_frames.c,
+	  test/-ext-/debug/test_profile_frames.rb: fix a test for this change.
+
+
 Wed Oct  9 00:55:51 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* load.c (load_lock): display backtrace to $stderr at circular
Index: vm_backtrace.c
===================================================================
--- vm_backtrace.c	(revision 43204)
+++ vm_backtrace.c	(revision 43205)
@@ -1343,3 +1343,22 @@ rb_profile_frame_qualified_method_name(V https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L1343
 	return Qnil;
     }
 }
+
+VALUE
+rb_profile_frame_full_label(VALUE frame)
+{
+    VALUE label = rb_profile_frame_label(frame);
+    VALUE base_label = rb_profile_frame_base_label(frame);
+    VALUE qualified_method_name = rb_profile_frame_qualified_method_name(frame);
+
+    if (NIL_P(qualified_method_name) || base_label == qualified_method_name) {
+	return label;
+    }
+    else {
+	long label_length = RSTRING_LEN(label);
+	long base_label_length = RSTRING_LEN(base_label);
+	VALUE prefix = rb_str_new(RSTRING_PTR(label), label_length - base_label_length);
+
+	return rb_sprintf("%"PRIsVALUE"%"PRIsVALUE, prefix, qualified_method_name);
+    }
+}
Index: ext/-test-/debug/profile_frames.c
===================================================================
--- ext/-test-/debug/profile_frames.c	(revision 43204)
+++ ext/-test-/debug/profile_frames.c	(revision 43205)
@@ -23,6 +23,7 @@ profile_frames(VALUE self, VALUE start_v https://github.com/ruby/ruby/blob/trunk/ext/-test-/debug/profile_frames.c#L23
 	rb_ary_push(ary, rb_profile_frame_absolute_path(buff[i]));
 	rb_ary_push(ary, rb_profile_frame_label(buff[i]));
 	rb_ary_push(ary, rb_profile_frame_base_label(buff[i]));
+	rb_ary_push(ary, rb_profile_frame_full_label(buff[i]));
 	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]));
Index: test/-ext-/debug/test_profile_frames.rb
===================================================================
--- test/-ext-/debug/test_profile_frames.rb	(revision 43204)
+++ test/-ext-/debug/test_profile_frames.rb	(revision 43205)
@@ -37,6 +37,13 @@ class TestProfileFrames < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/debug/test_profile_frames.rb#L37
       "foo",
       "test_profile_frames",
     ]
+    full_labels = [
+      "block (2 levels) in TestProfileFrames#test_profile_frames",
+      "SampleClassForTestProfileFrames::Sample2#baz",
+      "SampleClassForTestProfileFrames.bar",
+      "SampleClassForTestProfileFrames#foo",
+      "block in TestProfileFrames#test_profile_frames",
+    ]
     classes = [
       TestProfileFrames,
       SampleClassForTestProfileFrames::Sample2,
@@ -62,15 +69,18 @@ class TestProfileFrames < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/-ext-/debug/test_profile_frames.rb#L69
       "TestProfileFrames#test_profile_frames",
     ]
 
+    # pp frames
+
     assert_equal(labels.size, frames.size)
 
-    frames.each.with_index{|(path, absolute_path, label, base_label, first_lineno,
+    frames.each.with_index{|(path, absolute_path, label, base_label, full_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)
       assert_equal(labels[i], label, err_msg)
       assert_equal(base_labels[i], base_label, err_msg)
+      assert_equal(full_labels[i], full_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)

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

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