From 55df06be4369f5d8ab5eb61a5d22809255171036 Mon Sep 17 00:00:00 2001 From: Shih-wei Liao Date: Fri, 26 Aug 2011 14:39:27 -0700 Subject: Stack Trace Element with its unit test added too. The unit test passes. Change-Id: I6f6af771cae1387c60c3b511148a347fe3237345 --- src/exception_test.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/exception_test.cc') diff --git a/src/exception_test.cc b/src/exception_test.cc index 99fd9548d3..4337d7a1fe 100644 --- a/src/exception_test.cc +++ b/src/exception_test.cc @@ -73,8 +73,12 @@ class ExceptionTest : public CommonTest { ASSERT_TRUE(my_klass_ != NULL); method_f_ = my_klass_->FindVirtualMethod("f", "()I"); ASSERT_TRUE(method_f_ != NULL); + method_f_->SetFrameSizeInBytes(8); + method_f_->SetReturnPcOffsetInBytes(4); method_g_ = my_klass_->FindVirtualMethod("g", "(I)V"); ASSERT_TRUE(method_g_ != NULL); + method_g_->SetFrameSizeInBytes(8); + method_g_->SetReturnPcOffsetInBytes(4); } DexFile::CatchHandlerItem FindCatchHandlerItem(Method* method, @@ -132,4 +136,36 @@ TEST_F(ExceptionTest, FindCatchHandler) { ASSERT_EQ(true, iter.HasNext()); } +TEST_F(ExceptionTest, StackTraceElement) { + enum {STACK_SIZE = 1000}; + uint32_t top_of_stack = 0; + uintptr_t fake_stack[STACK_SIZE]; + fake_stack[top_of_stack++] = reinterpret_cast(method_g_); + fake_stack[top_of_stack++] = 3; + fake_stack[top_of_stack++] = reinterpret_cast(method_f_); + fake_stack[top_of_stack++] = 3; + + Thread* thread = Thread::Current(); + thread->SetTopOfStack(fake_stack); + + Thread::InternalStackTrace* traces = thread->GetStackTrace(2); + ObjectArray* trace_array = thread->GetStackTraceElement(2, traces); + delete[] traces; + + ASSERT_TRUE(trace_array->Get(0) != NULL); + EXPECT_STREQ("java.lang.MyClass", trace_array->Get(0)->GetDeclaringClass()->ToModifiedUtf8().c_str()); + EXPECT_STREQ("MyClass.java", trace_array->Get(0)->GetFileName()->ToModifiedUtf8().c_str()); + EXPECT_STREQ("g", trace_array->Get(0)->GetMethodName()->ToModifiedUtf8().c_str()); + EXPECT_EQ(22u, trace_array->Get(0)->GetLineNumber()); + + ASSERT_TRUE(trace_array->Get(1) != NULL); + EXPECT_STREQ("java.lang.MyClass", trace_array->Get(1)->GetDeclaringClass()->ToModifiedUtf8().c_str()); + EXPECT_STREQ("MyClass.java", trace_array->Get(1)->GetFileName()->ToModifiedUtf8().c_str()); + EXPECT_STREQ("f", trace_array->Get(1)->GetMethodName()->ToModifiedUtf8().c_str()); + EXPECT_EQ(7u, trace_array->Get(1)->GetLineNumber()); +} + +// TODO: Test with native frame: For native frame, lineno should be -2 to +// indicate it is native. That is how libcore tells from the StackTraceElement. + } // namespace art -- cgit v1.2.3-59-g8ed1b