OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // crash_report.h : Declarations for crash reporting. | 5 // crash_report.h : Declarations for crash reporting. |
6 | 6 |
7 #ifndef CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ | 7 #ifndef CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ |
8 #define CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ | 8 #define CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/logging.h" | |
12 #include "breakpad/src/client/windows/handler/exception_handler.h" | 13 #include "breakpad/src/client/windows/handler/exception_handler.h" |
14 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" | |
15 | |
16 extern google_breakpad::ExceptionHandler* g_breakpad; | |
17 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
13 | 18 |
14 bool InitializeVectoredCrashReporting( | 19 bool InitializeVectoredCrashReporting( |
15 bool full_dump, | 20 bool full_dump, |
16 const wchar_t* user_sid, | 21 const wchar_t* user_sid, |
17 const std::wstring& dump_path, | 22 const std::wstring& dump_path, |
18 google_breakpad::CustomClientInfo* client_info); | 23 google_breakpad::CustomClientInfo* client_info); |
19 | 24 |
20 bool InitializeVectoredCrashReportingWithPipeName( | 25 bool InitializeVectoredCrashReportingWithPipeName( |
21 bool full_dump, | 26 bool full_dump, |
22 const wchar_t* pipe_name, | 27 const wchar_t* pipe_name, |
23 const std::wstring& dump_path, | 28 const std::wstring& dump_path, |
24 google_breakpad::CustomClientInfo* client_info); | 29 google_breakpad::CustomClientInfo* client_info); |
25 | 30 |
26 bool ShutdownVectoredCrashReporting(); | 31 bool ShutdownVectoredCrashReporting(); |
27 | 32 |
33 namespace { | |
34 __declspec(naked) | |
35 static EXCEPTION_REGISTRATION_RECORD* InternalRtlpGetExceptionList() { | |
36 __asm { | |
37 mov eax, fs:0 | |
38 ret | |
39 } | |
40 } | |
41 } // end of namespace | |
42 | |
43 // Class which methods simply forwards to Win32 API and uses breakpad to write | |
44 // a minidump. Used as template (external interface) of VectoredHandlerT<E>. | |
45 class Win32VEHTraits : public VEHTraitsBase { | |
46 public: | |
47 static inline void* Register(PVECTORED_EXCEPTION_HANDLER func, | |
48 const void* module_start, const void* module_end) { | |
49 InitializeIgnoredBlocks(); | |
50 VEHTraitsBase::SetModule(module_start, module_end); | |
51 return ::AddVectoredExceptionHandler(1, func); | |
52 } | |
53 | |
54 static inline ULONG Unregister(void* handle) { | |
55 return ::RemoveVectoredExceptionHandler(handle); | |
56 } | |
57 | |
58 static inline bool WriteDump(EXCEPTION_POINTERS* p) { | |
59 return g_breakpad->WriteMinidumpForException(p); | |
60 } | |
61 | |
62 static inline EXCEPTION_REGISTRATION_RECORD* RtlpGetExceptionList() { | |
63 return InternalRtlpGetExceptionList(); | |
64 } | |
65 | |
66 static inline WORD RtlCaptureStackBackTrace(DWORD FramesToSkip, | |
67 DWORD FramesToCapture, void** BackTrace, DWORD* BackTraceHash) { | |
68 return ::RtlCaptureStackBackTrace(FramesToSkip, FramesToCapture, | |
69 BackTrace, BackTraceHash); | |
70 } | |
71 | |
72 static bool ShouldIgnoreException(const EXCEPTION_POINTERS* exceptionInfo) { | |
73 const void* address = exceptionInfo->ExceptionRecord->ExceptionAddress; | |
74 for (int i = 0; i < kIgnoreEntries; i++) { | |
75 const CodeBlock& code_block = IgnoreExceptions[i]; | |
76 if (code_block.code && | |
77 (CodeOffset(code_block.code, code_block.begin_offset) < address) && | |
stoyan
2010/01/15 20:23:01
<= address?
| |
78 (address < CodeOffset(code_block.code, code_block.end_offset))) { | |
79 return true; | |
80 } | |
81 } | |
82 | |
83 return false; | |
84 } | |
85 | |
86 static inline void InitializeIgnoredBlocks() { | |
87 // Initialize ignored exception list | |
88 for (int i = 0; i < kIgnoreEntries; i++) { | |
89 CodeBlock& code_block = IgnoreExceptions[i]; | |
90 if (!code_block.code) { | |
91 HMODULE module = GetModuleHandleA(code_block.module); | |
92 DCHECK(module) << "GetModuleHandle error: " << GetLastError(); | |
93 code_block.code = GetProcAddress(module, code_block.function); | |
94 DCHECK(code_block.code) << "GetProcAddress error: "<< GetLastError(); | |
95 } | |
96 } | |
97 } | |
98 | |
99 static inline const void* CodeOffset(const void* code, int offset) { | |
100 return reinterpret_cast<const char*>(code) + offset; | |
101 } | |
102 | |
103 private: | |
104 // Block of code to be ignored for exceptions | |
105 struct CodeBlock { | |
106 char* module; | |
107 char* function; | |
108 int begin_offset; | |
109 int end_offset; | |
110 const void* code; | |
111 }; | |
112 | |
113 static const int kIgnoreEntries = 4; | |
114 static CodeBlock IgnoreExceptions[kIgnoreEntries]; | |
115 }; | |
116 | |
117 | |
28 #endif // CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ | 118 #endif // CHROME_FRAME_CRASH_REPORTING_CRASH_REPORT_H_ |
OLD | NEW |