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
3 // found in the LICENSE file.
5 #ifndef BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_
6 #define BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_
10 #include "base/base_export.h"
11 #include "base/macros.h"
16 // Allows code to compile for x86. Actual support for x86 will require either
17 // refactoring these interfaces or separate architecture-specific interfaces.
18 using PRUNTIME_FUNCTION
= void*;
19 #endif // !defined(_WIN64)
21 // Instances of this class are expected to be created and destroyed for each
22 // stack unwinding, outside of SuspendThread/ResumeThread.
23 class BASE_EXPORT Win32StackFrameUnwinder
{
25 // Interface for Win32 unwind-related functionality this class depends
26 // on. Provides a seam for testing.
27 class BASE_EXPORT UnwindFunctions
{
29 virtual ~UnwindFunctions();
31 virtual PRUNTIME_FUNCTION
LookupFunctionEntry(DWORD64 program_counter
,
32 PDWORD64 image_base
) = 0;
33 virtual void VirtualUnwind(DWORD64 image_base
,
34 DWORD64 program_counter
,
35 PRUNTIME_FUNCTION runtime_function
,
36 CONTEXT
* context
) = 0;
41 DISALLOW_COPY_AND_ASSIGN(UnwindFunctions
);
44 class BASE_EXPORT Win32UnwindFunctions
: public UnwindFunctions
{
46 Win32UnwindFunctions();
48 PRUNTIME_FUNCTION
LookupFunctionEntry(DWORD64 program_counter
,
49 PDWORD64 image_base
) override
;
51 void VirtualUnwind(DWORD64 image_base
,
52 DWORD64 program_counter
,
53 PRUNTIME_FUNCTION runtime_function
,
54 CONTEXT
* context
) override
;
57 DISALLOW_COPY_AND_ASSIGN(Win32UnwindFunctions
);
60 Win32StackFrameUnwinder();
61 ~Win32StackFrameUnwinder();
63 bool TryUnwind(CONTEXT
* context
);
66 // This function is for test purposes only.
67 Win32StackFrameUnwinder(UnwindFunctions
* unwind_functions
);
68 friend class Win32StackFrameUnwinderTest
;
70 // State associated with each stack unwinding.
72 bool unwind_info_present_for_all_frames_
;
73 const void* pending_blacklisted_module_
;
75 Win32UnwindFunctions win32_unwind_functions_
;
76 UnwindFunctions
* const unwind_functions_
;
78 DISALLOW_COPY_AND_ASSIGN(Win32StackFrameUnwinder
);
83 #endif // BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_