2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-10-07 03:35:21 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require '-test-/debug'
|
|
|
|
|
2013-10-07 03:51:16 -04:00
|
|
|
class SampleClassForTestProfileFrames
|
2013-10-08 08:08:20 -04:00
|
|
|
class Sample2
|
|
|
|
def baz(block)
|
2013-10-27 15:17:24 -04:00
|
|
|
instance_eval "def zab(block) block.call end"
|
|
|
|
[self, zab(block)]
|
2013-10-08 08:08:20 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-08 09:50:50 -04:00
|
|
|
|
2013-10-07 03:35:21 -04:00
|
|
|
def self.bar(block)
|
2013-10-08 08:08:20 -04:00
|
|
|
Sample2.new.baz(block)
|
2013-10-07 03:35:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def foo(block)
|
|
|
|
self.class.bar(block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestProfileFrames < Test::Unit::TestCase
|
|
|
|
def test_profile_frames
|
2013-10-27 15:17:24 -04:00
|
|
|
obj, frames = Fiber.new{
|
2013-10-07 03:51:16 -04:00
|
|
|
Fiber.yield SampleClassForTestProfileFrames.new.foo(lambda{ Bug::Debug.profile_frames(0, 10) })
|
2013-10-07 03:35:21 -04:00
|
|
|
}.resume
|
|
|
|
|
|
|
|
labels = [
|
2015-07-06 14:44:54 -04:00
|
|
|
"test_profile_frames",
|
2013-10-27 15:17:24 -04:00
|
|
|
"zab",
|
2013-10-08 08:08:20 -04:00
|
|
|
"baz",
|
2013-10-07 03:35:21 -04:00
|
|
|
"bar",
|
|
|
|
"foo",
|
2015-07-06 14:44:54 -04:00
|
|
|
"test_profile_frames",
|
2013-10-07 03:35:21 -04:00
|
|
|
]
|
|
|
|
base_labels = [
|
|
|
|
"test_profile_frames",
|
2013-10-27 15:17:24 -04:00
|
|
|
"zab",
|
2013-10-08 08:08:20 -04:00
|
|
|
"baz",
|
2013-10-07 03:35:21 -04:00
|
|
|
"bar",
|
|
|
|
"foo",
|
|
|
|
"test_profile_frames",
|
|
|
|
]
|
2013-10-08 20:21:51 -04:00
|
|
|
full_labels = [
|
2015-07-06 14:44:54 -04:00
|
|
|
"TestProfileFrames#test_profile_frames",
|
2013-10-27 15:17:24 -04:00
|
|
|
"#{obj.inspect}.zab",
|
2013-10-08 20:21:51 -04:00
|
|
|
"SampleClassForTestProfileFrames::Sample2#baz",
|
|
|
|
"SampleClassForTestProfileFrames.bar",
|
|
|
|
"SampleClassForTestProfileFrames#foo",
|
2015-07-06 14:44:54 -04:00
|
|
|
"TestProfileFrames#test_profile_frames",
|
2013-10-08 20:21:51 -04:00
|
|
|
]
|
2013-10-07 03:35:21 -04:00
|
|
|
classes = [
|
|
|
|
TestProfileFrames,
|
2013-10-27 15:17:24 -04:00
|
|
|
obj,
|
2013-10-08 08:08:20 -04:00
|
|
|
SampleClassForTestProfileFrames::Sample2,
|
2013-10-07 03:51:16 -04:00
|
|
|
SampleClassForTestProfileFrames, # singleton method
|
|
|
|
SampleClassForTestProfileFrames,
|
2013-10-07 03:35:21 -04:00
|
|
|
TestProfileFrames,
|
|
|
|
]
|
|
|
|
singleton_method_p = [
|
2013-10-27 15:17:24 -04:00
|
|
|
false, true, false, true, false, false, false,
|
2013-10-07 03:35:21 -04:00
|
|
|
]
|
2013-10-14 15:14:17 -04:00
|
|
|
method_names = [
|
2013-10-08 08:08:20 -04:00
|
|
|
"test_profile_frames",
|
2013-10-27 15:17:24 -04:00
|
|
|
"zab",
|
2013-10-08 08:08:20 -04:00
|
|
|
"baz",
|
|
|
|
"bar",
|
|
|
|
"foo",
|
|
|
|
"test_profile_frames",
|
|
|
|
]
|
|
|
|
qualified_method_names = [
|
|
|
|
"TestProfileFrames#test_profile_frames",
|
2013-10-27 15:17:24 -04:00
|
|
|
"#{obj.inspect}.zab",
|
2013-10-08 08:08:20 -04:00
|
|
|
"SampleClassForTestProfileFrames::Sample2#baz",
|
|
|
|
"SampleClassForTestProfileFrames.bar",
|
|
|
|
"SampleClassForTestProfileFrames#foo",
|
|
|
|
"TestProfileFrames#test_profile_frames",
|
|
|
|
]
|
2013-10-27 15:17:24 -04:00
|
|
|
paths = [ file=__FILE__, "(eval)", file, file, file, file ]
|
|
|
|
absolute_paths = [ file, nil, file, file, file, file ]
|
2013-10-08 08:08:20 -04:00
|
|
|
|
2013-10-08 20:21:51 -04:00
|
|
|
# pp frames
|
|
|
|
|
2013-10-08 08:08:20 -04:00
|
|
|
assert_equal(labels.size, frames.size)
|
2013-10-07 03:35:21 -04:00
|
|
|
|
2013-10-08 20:21:51 -04:00
|
|
|
frames.each.with_index{|(path, absolute_path, label, base_label, full_label, first_lineno,
|
2013-10-08 08:08:20 -04:00
|
|
|
classpath, singleton_p, method_name, qualified_method_name), i|
|
2013-10-07 03:35:21 -04:00
|
|
|
err_msg = "#{i}th frame"
|
2013-10-27 15:17:24 -04:00
|
|
|
assert_equal(paths[i], path, err_msg)
|
|
|
|
assert_equal(absolute_paths[i], absolute_path, err_msg)
|
2013-10-07 03:35:21 -04:00
|
|
|
assert_equal(labels[i], label, err_msg)
|
|
|
|
assert_equal(base_labels[i], base_label, err_msg)
|
|
|
|
assert_equal(singleton_method_p[i], singleton_p, err_msg)
|
2013-10-14 15:14:17 -04:00
|
|
|
assert_equal(method_names[i], method_name, err_msg)
|
2013-10-27 15:17:24 -04:00
|
|
|
assert_match(qualified_method_names[i], qualified_method_name, err_msg)
|
|
|
|
assert_match(full_labels[i], full_label, err_msg)
|
|
|
|
assert_match(classes[i].inspect, classpath, err_msg)
|
2013-10-14 15:14:20 -04:00
|
|
|
if label == method_name
|
|
|
|
c = classes[i]
|
|
|
|
m = singleton_p ? c.method(method_name) : c.instance_method(method_name)
|
|
|
|
assert_equal(m.source_location[1], first_lineno, err_msg)
|
|
|
|
end
|
2013-10-07 03:35:21 -04:00
|
|
|
}
|
|
|
|
end
|
2015-12-20 20:18:48 -05:00
|
|
|
|
|
|
|
def test_ifunc_frame
|
|
|
|
bug11851 = '[ruby-core:72409] [Bug #11851]'
|
|
|
|
assert_ruby_status([], <<~'end;', bug11851) # do
|
|
|
|
require '-test-/debug'
|
|
|
|
class A
|
|
|
|
include Bug::Debug
|
|
|
|
def x
|
|
|
|
profile_frames(0, 10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def a
|
|
|
|
[A.new].each(&:x)
|
|
|
|
end
|
|
|
|
a
|
|
|
|
end;
|
|
|
|
end
|
2013-10-07 03:35:21 -04:00
|
|
|
end
|