1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* thread.c, vm_eval.c: add Thread.backtrace.

* test/ruby/test_thread.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2009-06-14 05:59:23 +00:00
parent d3027870ee
commit 63bd8a74e8
4 changed files with 44 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Sun Jun 14 14:57:57 2009 Koichi Sasada <ko1@atdot.net>
* thread.c, vm_eval.c: add Thread.backtrace.
* test/ruby/test_thread.rb: add a test.
Sun Jun 14 13:58:32 2009 Koichi Sasada <ko1@atdot.net> Sun Jun 14 13:58:32 2009 Koichi Sasada <ko1@atdot.net>
* transcode.c (transcode_restartable0): revert last commit because * transcode.c (transcode_restartable0): revert last commit because

View file

@ -516,4 +516,14 @@ class TestThreadGroup < Test::Unit::TestCase
c.class_eval { def initialize; end } c.class_eval { def initialize; end }
assert_raise(ThreadError) { c.new.start } assert_raise(ThreadError) { c.new.start }
end end
def test_backtrace
Thread.new{
assert_equal(Array, Thread.main.backtrace.class)
}.join
t = Thread.new{}
t.join
assert_equal(nil, t.backtrace)
end
end end

View file

@ -3817,6 +3817,14 @@ ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
return result; return result;
} }
VALUE rb_thread_backtrace(VALUE thval);
static VALUE
rb_thread_backtrace_m(VALUE thval)
{
return rb_thread_backtrace(thval);
}
/* /*
* +Thread+ encapsulates the behavior of a thread of * +Thread+ encapsulates the behavior of a thread of
* execution, including the main thread of the Ruby script. * execution, including the main thread of the Ruby script.
@ -3873,6 +3881,7 @@ Init_Thread(void)
rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1); rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0); rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
rb_define_method(rb_cThread, "group", rb_thread_group, 0); rb_define_method(rb_cThread, "group", rb_thread_group, 0);
rb_define_method(rb_cThread, "backtrace", rb_thread_backtrace_m, 0);
rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0); rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);

View file

@ -1347,6 +1347,25 @@ rb_make_backtrace(void)
return vm_backtrace(GET_THREAD(), -1); return vm_backtrace(GET_THREAD(), -1);
} }
VALUE
rb_thread_backtrace(VALUE thval)
{
rb_thread_t *th;
GetThreadPtr(thval, th);
switch (th->status) {
case THREAD_RUNNABLE:
case THREAD_STOPPED:
case THREAD_STOPPED_FOREVER:
break;
case THREAD_TO_KILL:
case THREAD_KILLED:
return Qnil;
}
return vm_backtrace(th, 0);
}
VALUE VALUE
rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg) rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg)
{ {