mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm.c: refactoring backtrace related funcitons.
(1) unify similar functions (rb_backtrace_each() and backtrace_object()). backtrace_each() is a unified function. variation: a) backtrace_object(): create backtrace object. b) vm_backtrace_str_ary(): create bt as an array of string. c) vm_backtrace_print(): print backtrace to specified file. d) rb_backtrace_print_as_bugreport(): print backtrace on bugreport style. (2) remove rb_backtrace_each(). Use backtrace_each() instead. (3) chang the type of lev parameter to size_t. a) lev == 0 means current frame (exception, etc use it). b) lev == 1 means upper frame (caller(0) use it). * vm_core.h, vm_dump.c, vm_eval.c: ditto. * vm.c (backtrace_object(), vm_backtrace_str_ary()): fix to return a correct size of caller(lev) array. Let n be a "caller(0).size" then ln as caller(lev).size should be (n - lev). However, the previous implementation returns a wrong size array (ln > n - lev). [ruby-dev:45673] * test/ruby/test_backtrace.rb: add tests for backtrace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
26f96fe1ce
commit
1f3142a447
6 changed files with 344 additions and 171 deletions
57
test/ruby/test_backtrace.rb
Normal file
57
test/ruby/test_backtrace.rb
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
require 'test/unit'
|
||||
|
||||
class TestBacktrace < Test::Unit::TestCase
|
||||
def test_exception
|
||||
bt = Fiber.new{
|
||||
begin
|
||||
raise
|
||||
rescue => e
|
||||
e.backtrace
|
||||
end
|
||||
}.resume
|
||||
assert_equal(1, bt.size)
|
||||
assert_match(/.+:\d+:.+/, bt[0])
|
||||
end
|
||||
|
||||
def test_caller_lev
|
||||
cs = []
|
||||
Fiber.new{
|
||||
Proc.new{
|
||||
cs << caller(0)
|
||||
cs << caller(1)
|
||||
cs << caller(2)
|
||||
cs << caller(3)
|
||||
cs << caller(4)
|
||||
cs << caller(5)
|
||||
}.call
|
||||
}.resume
|
||||
assert_equal(3, cs[0].size)
|
||||
assert_equal(2, cs[1].size)
|
||||
assert_equal(1, cs[2].size)
|
||||
assert_equal(0, cs[3].size)
|
||||
assert_equal(nil, cs[4])
|
||||
|
||||
#
|
||||
max = 20
|
||||
rec = lambda{|n|
|
||||
if n > 0
|
||||
1.times{
|
||||
rec[n-1]
|
||||
}
|
||||
else
|
||||
max.times{|i|
|
||||
total_size = caller(0).size
|
||||
c = caller(i)
|
||||
if c
|
||||
assert_equal(total_size - i, caller(i).size, "[ruby-dev:45673]")
|
||||
end
|
||||
}
|
||||
end
|
||||
}
|
||||
bt = Fiber.new{
|
||||
rec[max]
|
||||
}.resume
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue