Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: base/profiler/win32_stack_frame_unwinder.h

Issue 1423583002: Stack sampling profiler: handle unloaded and unloading modules (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: fix gcc compile Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/profiler/test_support_library.cc ('k') | base/profiler/win32_stack_frame_unwinder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_ 5 #ifndef BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_
6 #define BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_ 6 #define BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/win/scoped_handle.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 #if !defined(_WIN64) 17 #if !defined(_WIN64)
17 // Allows code to compile for x86. Actual support for x86 will require either 18 // Allows code to compile for x86. Actual support for x86 will require either
18 // refactoring these interfaces or separate architecture-specific interfaces. 19 // refactoring these interfaces or separate architecture-specific interfaces.
19 struct RUNTIME_FUNCTION { 20 struct RUNTIME_FUNCTION {
20 DWORD BeginAddress; 21 DWORD BeginAddress;
21 DWORD EndAddress; 22 DWORD EndAddress;
22 }; 23 };
23 using PRUNTIME_FUNCTION = RUNTIME_FUNCTION*; 24 using PRUNTIME_FUNCTION = RUNTIME_FUNCTION*;
24 #endif // !defined(_WIN64) 25 #endif // !defined(_WIN64)
25 26
27 // Traits class to adapt GenericScopedHandle for HMODULES.
28 class ModuleHandleTraits : public win::HandleTraits {
29 public:
30 using Handle = HMODULE;
31
32 static bool BASE_EXPORT CloseHandle(HMODULE handle);
33 static bool BASE_EXPORT IsHandleValid(HMODULE handle);
34 static HMODULE BASE_EXPORT NullHandle();
35
36 BASE_EXPORT static const HMODULE kNonNullModuleForTesting;
37
38 private:
39 DISALLOW_IMPLICIT_CONSTRUCTORS(ModuleHandleTraits);
40 };
41
42 // HMODULE is not really a handle, and has reference count semantics, so the
43 // standard VerifierTraits does not apply.
44 using ScopedModuleHandle =
45 win::GenericScopedHandle<ModuleHandleTraits, win::DummyVerifierTraits>;
46
26 // Instances of this class are expected to be created and destroyed for each 47 // Instances of this class are expected to be created and destroyed for each
27 // stack unwinding. This class is not used while the target thread is suspended, 48 // stack unwinding. This class is not used while the target thread is suspended,
28 // so may allocate from the default heap. 49 // so may allocate from the default heap.
29 class BASE_EXPORT Win32StackFrameUnwinder { 50 class BASE_EXPORT Win32StackFrameUnwinder {
30 public: 51 public:
31 // Interface for Win32 unwind-related functionality this class depends 52 // Interface for Win32 unwind-related functionality this class depends
32 // on. Provides a seam for testing. 53 // on. Provides a seam for testing.
33 class BASE_EXPORT UnwindFunctions { 54 class BASE_EXPORT UnwindFunctions {
34 public: 55 public:
35 virtual ~UnwindFunctions(); 56 virtual ~UnwindFunctions();
36 57
37 virtual PRUNTIME_FUNCTION LookupFunctionEntry(DWORD64 program_counter, 58 virtual PRUNTIME_FUNCTION LookupFunctionEntry(DWORD64 program_counter,
38 PDWORD64 image_base) = 0; 59 PDWORD64 image_base) = 0;
39 virtual void VirtualUnwind(DWORD64 image_base, 60 virtual void VirtualUnwind(DWORD64 image_base,
40 DWORD64 program_counter, 61 DWORD64 program_counter,
41 PRUNTIME_FUNCTION runtime_function, 62 PRUNTIME_FUNCTION runtime_function,
42 CONTEXT* context) = 0; 63 CONTEXT* context) = 0;
64
65 // Returns the module containing |program_counter|. Can return null if the
66 // module has been unloaded.
67 virtual ScopedModuleHandle GetModuleForProgramCounter(
68 DWORD64 program_counter) = 0;
69
43 protected: 70 protected:
44 UnwindFunctions(); 71 UnwindFunctions();
45 72
46 private: 73 private:
47 DISALLOW_COPY_AND_ASSIGN(UnwindFunctions); 74 DISALLOW_COPY_AND_ASSIGN(UnwindFunctions);
48 }; 75 };
49 76
50 Win32StackFrameUnwinder(); 77 Win32StackFrameUnwinder();
51 ~Win32StackFrameUnwinder(); 78 ~Win32StackFrameUnwinder();
52 79
53 bool TryUnwind(CONTEXT* context); 80 // Attempts to unwind the frame represented by the stack and instruction
81 // pointers in |context|. If successful, updates |context| and provides the
82 // module associated with the frame in |module|.
83 bool TryUnwind(CONTEXT* context, ScopedModuleHandle* module);
54 84
55 private: 85 private:
56 // This function is for internal and test purposes only. 86 // This function is for internal and test purposes only.
57 Win32StackFrameUnwinder(scoped_ptr<UnwindFunctions> unwind_functions); 87 Win32StackFrameUnwinder(scoped_ptr<UnwindFunctions> unwind_functions);
58 friend class Win32StackFrameUnwinderTest; 88 friend class Win32StackFrameUnwinderTest;
59 89
60 // State associated with each stack unwinding. 90 // State associated with each stack unwinding.
61 bool at_top_frame_; 91 bool at_top_frame_;
62 bool unwind_info_present_for_all_frames_; 92 bool unwind_info_present_for_all_frames_;
63 93
64 scoped_ptr<UnwindFunctions> unwind_functions_; 94 scoped_ptr<UnwindFunctions> unwind_functions_;
65 95
66 DISALLOW_COPY_AND_ASSIGN(Win32StackFrameUnwinder); 96 DISALLOW_COPY_AND_ASSIGN(Win32StackFrameUnwinder);
67 }; 97 };
68 98
69 } // namespace base 99 } // namespace base
70 100
71 #endif // BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_ 101 #endif // BASE_PROFILER_WIN32_STACK_FRAME_UNWINDER_H_
OLDNEW
« no previous file with comments | « base/profiler/test_support_library.cc ('k') | base/profiler/win32_stack_frame_unwinder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698