Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / base / profiler / win32_stack_frame_unwinder.h
bloba45d5778097755a22100f4717c63148a2499ceb0
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_
8 #include <windows.h>
10 #include "base/base_export.h"
11 #include "base/macros.h"
13 namespace base {
15 #if !defined(_WIN64)
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 {
24 public:
25 // Interface for Win32 unwind-related functionality this class depends
26 // on. Provides a seam for testing.
27 class BASE_EXPORT UnwindFunctions {
28 public:
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;
37 protected:
38 UnwindFunctions();
40 private:
41 DISALLOW_COPY_AND_ASSIGN(UnwindFunctions);
44 class BASE_EXPORT Win32UnwindFunctions : public UnwindFunctions {
45 public:
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;
56 private:
57 DISALLOW_COPY_AND_ASSIGN(Win32UnwindFunctions);
60 Win32StackFrameUnwinder();
61 ~Win32StackFrameUnwinder();
63 bool TryUnwind(CONTEXT* context);
65 private:
66 // This function is for test purposes only.
67 Win32StackFrameUnwinder(UnwindFunctions* unwind_functions);
68 friend class Win32StackFrameUnwinderTest;
70 // State associated with each stack unwinding.
71 bool at_top_frame_;
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);
81 } // namespace base
83 #endif // BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_