| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/profiler/win32_stack_frame_unwinder.h" | 5 #include "base/profiler/win32_stack_frame_unwinder.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 module_is_loaded_ = false; | 103 module_is_loaded_ = false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void TestUnwindFunctions::SetHasRuntimeFunction(CONTEXT* context) { | 106 void TestUnwindFunctions::SetHasRuntimeFunction(CONTEXT* context) { |
| 107 RUNTIME_FUNCTION runtime_function = {}; | 107 RUNTIME_FUNCTION runtime_function = {}; |
| 108 runtime_function.BeginAddress = 16; | 108 runtime_function.BeginAddress = 16; |
| 109 runtime_function.EndAddress = runtime_function.BeginAddress + 256; | 109 runtime_function.EndAddress = runtime_function.BeginAddress + 256; |
| 110 runtime_functions_.push_back(runtime_function); | 110 runtime_functions_.push_back(runtime_function); |
| 111 next_runtime_function_ = &runtime_functions_.back(); | 111 next_runtime_function_ = &runtime_functions_.back(); |
| 112 | 112 |
| 113 expected_program_counter_ = context->Rip = | 113 expected_program_counter_ = context->Eip = |
| 114 next_image_base_ + runtime_function.BeginAddress + 8; | 114 next_image_base_ + runtime_function.BeginAddress + 8; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void TestUnwindFunctions::SetNoRuntimeFunction(CONTEXT* context) { | 117 void TestUnwindFunctions::SetNoRuntimeFunction(CONTEXT* context) { |
| 118 expected_program_counter_ = context->Rip = 100; | 118 expected_program_counter_ = context->Eip = 100; |
| 119 next_runtime_function_ = nullptr; | 119 next_runtime_function_ = nullptr; |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace | 122 } // namespace |
| 123 | 123 |
| 124 class Win32StackFrameUnwinderTest : public testing::Test { | 124 class Win32StackFrameUnwinderTest : public testing::Test { |
| 125 protected: | 125 protected: |
| 126 Win32StackFrameUnwinderTest() {} | 126 Win32StackFrameUnwinderTest() {} |
| 127 | 127 |
| 128 // This exists so that Win32StackFrameUnwinder's constructor can be private | 128 // This exists so that Win32StackFrameUnwinder's constructor can be private |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Checks that the CONTEXT's stack pointer gets popped when the top frame has no | 179 // Checks that the CONTEXT's stack pointer gets popped when the top frame has no |
| 180 // unwind information. | 180 // unwind information. |
| 181 TEST_F(Win32StackFrameUnwinderTest, FrameAtTopWithoutUnwindInfo) { | 181 TEST_F(Win32StackFrameUnwinderTest, FrameAtTopWithoutUnwindInfo) { |
| 182 std::unique_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | 182 std::unique_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); |
| 183 CONTEXT context = {0}; | 183 CONTEXT context = {0}; |
| 184 ScopedModuleHandle module; | 184 ScopedModuleHandle module; |
| 185 DWORD64 next_ip = 0x0123456789abcdef; | 185 DWORD64 next_ip = 0x0123456789abcdef; |
| 186 DWORD64 original_rsp = reinterpret_cast<DWORD64>(&next_ip); | 186 DWORD64 original_rsp = reinterpret_cast<DWORD64>(&next_ip); |
| 187 context.Rsp = original_rsp; | 187 context.Esp = original_rsp; |
| 188 | 188 |
| 189 unwind_functions_->SetNoRuntimeFunction(&context); | 189 unwind_functions_->SetNoRuntimeFunction(&context); |
| 190 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | 190 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); |
| 191 EXPECT_EQ(next_ip, context.Rip); | 191 EXPECT_EQ(next_ip, context.Eip); |
| 192 EXPECT_EQ(original_rsp + 8, context.Rsp); | 192 EXPECT_EQ(original_rsp + 8, context.Esp); |
| 193 EXPECT_TRUE(module.IsValid()); | 193 EXPECT_TRUE(module.IsValid()); |
| 194 | 194 |
| 195 unwind_functions_->SetHasRuntimeFunction(&context); | 195 unwind_functions_->SetHasRuntimeFunction(&context); |
| 196 module.Set(nullptr); | 196 module.Set(nullptr); |
| 197 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | 197 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); |
| 198 EXPECT_TRUE(module.IsValid()); | 198 EXPECT_TRUE(module.IsValid()); |
| 199 | 199 |
| 200 unwind_functions_->SetHasRuntimeFunction(&context); | 200 unwind_functions_->SetHasRuntimeFunction(&context); |
| 201 module.Set(nullptr); | 201 module.Set(nullptr); |
| 202 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | 202 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 214 unwind_functions_->SetHasRuntimeFunction(&context); | 214 unwind_functions_->SetHasRuntimeFunction(&context); |
| 215 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | 215 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); |
| 216 EXPECT_TRUE(module.IsValid()); | 216 EXPECT_TRUE(module.IsValid()); |
| 217 | 217 |
| 218 unwind_functions_->SetNoRuntimeFunction(&context); | 218 unwind_functions_->SetNoRuntimeFunction(&context); |
| 219 EXPECT_FALSE(unwinder->TryUnwind(&context, &module)); | 219 EXPECT_FALSE(unwinder->TryUnwind(&context, &module)); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace base | 223 } // namespace base |
| OLD | NEW |