blob: 2cacdc382f25f22f7890d7f6ff305396e1eaa029 [file] [log] [blame]
bryner1217c1f2006-09-27 01:00:32 +00001// Copyright (c) 2006, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// ExceptionHandler can write a minidump file when an exception occurs,
31// or when WriteMinidump() is called explicitly by your program.
32//
33// To have the exception handler write minidumps when an uncaught exception
34// (crash) occurs, you should create an instance early in the execution
35// of your program, and keep it around for the entire time you want to
36// have crash handling active (typically, until shutdown).
37//
38// If you want to write minidumps without installing the exception handler,
39// you can create an ExceptionHandler with install_handler set to false,
40// then call WriteMinidump. You can also use this technique if you want to
41// use different minidump callbacks for different call sites.
42//
43// In either case, a callback function is called when a minidump is written,
44// which receives the unqiue id of the minidump. The caller can use this
45// id to collect and write additional application state, and to launch an
46// external crash-reporting application.
47//
48// It is important that creation and destruction of ExceptionHandler objects
49// be nested cleanly, when using install_handler = true.
50// Avoid the following pattern:
51// ExceptionHandler *e = new ExceptionHandler(...);
52// ExceptionHandler *f = new ExceptionHandler(...);
53// delete e;
54// This will put the exception filter stack into an inconsistent state.
bryner1217c1f2006-09-27 01:00:32 +000055
56#ifndef CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__
57#define CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__
58
mmentovaibaff9382007-02-07 20:20:10 +000059#include <stdlib.h>
mmentovai29401d22006-10-26 18:06:43 +000060#include <Windows.h>
61#include <DbgHelp.h>
mmentovai469580e2008-01-28 20:02:01 +000062#include <rpc.h>
bryner1217c1f2006-09-27 01:00:32 +000063
mmentovai12a52452006-10-27 19:47:21 +000064#pragma warning( push )
65// Disable exception handler warnings.
mmentovai469580e2008-01-28 20:02:01 +000066#pragma warning( disable : 4530 )
mmentovai12a52452006-10-27 19:47:21 +000067
bryner1217c1f2006-09-27 01:00:32 +000068#include <string>
mmentovai283fd392006-12-07 20:46:54 +000069#include <vector>
bryner1217c1f2006-09-27 01:00:32 +000070
doshimun0ded3d72008-05-05 20:03:56 +000071#include "client/windows/common/ipc_protocol.h"
doshimun@gmail.comc79141e2008-03-08 00:02:40 +000072#include "client/windows/crash_generation/crash_generation_client.h"
mmentovaie5dc6082007-02-14 19:51:05 +000073#include "google_breakpad/common/minidump_format.h"
doshimun@gmail.comc79141e2008-03-08 00:02:40 +000074#include "processor/scoped_ptr.h"
mmentovaibaff9382007-02-07 20:20:10 +000075
mmentovaie5dc6082007-02-14 19:51:05 +000076namespace google_breakpad {
bryner1217c1f2006-09-27 01:00:32 +000077
mmentovai283fd392006-12-07 20:46:54 +000078using std::vector;
bryner1217c1f2006-09-27 01:00:32 +000079using std::wstring;
80
81class ExceptionHandler {
82 public:
mmentovaie5dc6082007-02-14 19:51:05 +000083 // A callback function to run before Breakpad performs any substantial
mmentovai283fd392006-12-07 20:46:54 +000084 // processing of an exception. A FilterCallback is called before writing
85 // a minidump. context is the parameter supplied by the user as
mmentovaif614cb92007-01-12 16:54:10 +000086 // callback_context when the handler was created. exinfo points to the
mmentovaibaff9382007-02-07 20:20:10 +000087 // exception record, if any; assertion points to assertion information,
88 // if any.
mmentovai283fd392006-12-07 20:46:54 +000089 //
mmentovaie5dc6082007-02-14 19:51:05 +000090 // If a FilterCallback returns true, Breakpad will continue processing,
91 // attempting to write a minidump. If a FilterCallback returns false, Breakpad
mmentovai283fd392006-12-07 20:46:54 +000092 // will immediately report the exception as unhandled without writing a
93 // minidump, allowing another handler the opportunity to handle it.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +000094 typedef bool (*FilterCallback)(void* context, EXCEPTION_POINTERS* exinfo,
95 MDRawAssertionInfo* assertion);
mmentovai283fd392006-12-07 20:46:54 +000096
bryner1217c1f2006-09-27 01:00:32 +000097 // A callback function to run after the minidump has been written.
98 // minidump_id is a unique id for the dump, so the minidump
mmentovai283fd392006-12-07 20:46:54 +000099 // file is <dump_path>\<minidump_id>.dmp. context is the parameter supplied
mmentovaif614cb92007-01-12 16:54:10 +0000100 // by the user as callback_context when the handler was created. exinfo
101 // points to the exception record, or NULL if no exception occurred.
102 // succeeded indicates whether a minidump file was successfully written.
mmentovaibaff9382007-02-07 20:20:10 +0000103 // assertion points to information about an assertion if the handler was
104 // invoked by an assertion.
mmentovai283fd392006-12-07 20:46:54 +0000105 //
mmentovaie5dc6082007-02-14 19:51:05 +0000106 // If an exception occurred and the callback returns true, Breakpad will treat
mmentovai283fd392006-12-07 20:46:54 +0000107 // the exception as fully-handled, suppressing any other handlers from being
mmentovaie5dc6082007-02-14 19:51:05 +0000108 // notified of the exception. If the callback returns false, Breakpad will
mmentovai283fd392006-12-07 20:46:54 +0000109 // treat the exception as unhandled, and allow another handler to handle it.
mmentovaie5dc6082007-02-14 19:51:05 +0000110 // If there are no other handlers, Breakpad will report the exception to the
mmentovai283fd392006-12-07 20:46:54 +0000111 // system as unhandled, allowing a debugger or native crash dialog the
112 // opportunity to handle the exception. Most callback implementations
113 // should normally return the value of |succeeded|, or when they wish to
114 // not report an exception of handled, false. Callbacks will rarely want to
115 // return true directly (unless |succeeded| is true).
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000116 //
117 // For out-of-process dump generation, dump path and minidump ID will always
118 // be NULL. In case of out-of-process dump generation, the dump path and
119 // minidump id are controlled by the server process and are not communicated
120 // back to the crashing process.
121 typedef bool (*MinidumpCallback)(const wchar_t* dump_path,
122 const wchar_t* minidump_id,
123 void* context,
124 EXCEPTION_POINTERS* exinfo,
125 MDRawAssertionInfo* assertion,
mmentovai283fd392006-12-07 20:46:54 +0000126 bool succeeded);
bryner1217c1f2006-09-27 01:00:32 +0000127
mmentovai6a844b12007-07-02 19:41:05 +0000128 // HandlerType specifies which types of handlers should be installed, if
129 // any. Use HANDLER_NONE for an ExceptionHandler that remains idle,
130 // without catching any failures on its own. This type of handler may
131 // still be triggered by calling WriteMinidump. Otherwise, use a
132 // combination of the other HANDLER_ values, or HANDLER_ALL to install
133 // all handlers.
134 enum HandlerType {
135 HANDLER_NONE = 0,
136 HANDLER_EXCEPTION = 1 << 0, // SetUnhandledExceptionFilter
137 HANDLER_INVALID_PARAMETER = 1 << 1, // _set_invalid_parameter_handler
138 HANDLER_PURECALL = 1 << 2, // _set_purecall_handler
139 HANDLER_ALL = HANDLER_EXCEPTION |
140 HANDLER_INVALID_PARAMETER |
141 HANDLER_PURECALL
142 };
143
bryner1217c1f2006-09-27 01:00:32 +0000144 // Creates a new ExceptionHandler instance to handle writing minidumps.
mmentovai283fd392006-12-07 20:46:54 +0000145 // Before writing a minidump, the optional filter callback will be called.
mmentovai6a844b12007-07-02 19:41:05 +0000146 // Its return value determines whether or not Breakpad should write a
147 // minidump. Minidump files will be written to dump_path, and the optional
148 // callback is called after writing the dump file, as described above.
149 // handler_types specifies the types of handlers that should be installed.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000150 ExceptionHandler(const wstring& dump_path,
mmentovai6a844b12007-07-02 19:41:05 +0000151 FilterCallback filter,
152 MinidumpCallback callback,
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000153 void* callback_context,
mmentovai3c07b282007-07-02 20:41:30 +0000154 int handler_types);
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000155
156 // Creates a new ExcetpionHandler instance that can attempt to perform
157 // out-of-process dump generation if pipe_name is not NULL. If pipe_name is
158 // NULL, or if out-of-process dump generation registration step fails,
159 // in-process dump generation will be used. This also allows specifying
160 // the dump type to generate.
161 ExceptionHandler(const wstring& dump_path,
162 FilterCallback filter,
163 MinidumpCallback callback,
164 void* callback_context,
165 int handler_types,
166 MINIDUMP_TYPE dump_type,
doshimun0ded3d72008-05-05 20:03:56 +0000167 const wchar_t* pipe_name,
168 const CustomClientInfo* custom_info);
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000169
bryner1217c1f2006-09-27 01:00:32 +0000170 ~ExceptionHandler();
171
mmentovai1bff57e2006-10-27 16:10:55 +0000172 // Get and set the minidump path.
173 wstring dump_path() const { return dump_path_; }
mmentovaied61ae02006-11-28 19:47:44 +0000174 void set_dump_path(const wstring &dump_path) {
175 dump_path_ = dump_path;
mmentovai283fd392006-12-07 20:46:54 +0000176 dump_path_c_ = dump_path_.c_str();
mmentovaied61ae02006-11-28 19:47:44 +0000177 UpdateNextID(); // Necessary to put dump_path_ in next_minidump_path_.
178 }
mmentovai1bff57e2006-10-27 16:10:55 +0000179
bryner1217c1f2006-09-27 01:00:32 +0000180 // Writes a minidump immediately. This can be used to capture the
181 // execution state independently of a crash. Returns true on success.
182 bool WriteMinidump();
183
mmentovaifb6be7c2007-07-02 15:36:56 +0000184 // Writes a minidump immediately, with the user-supplied exception
185 // information.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000186 bool WriteMinidumpForException(EXCEPTION_POINTERS* exinfo);
mmentovaifb6be7c2007-07-02 15:36:56 +0000187
bryner1217c1f2006-09-27 01:00:32 +0000188 // Convenience form of WriteMinidump which does not require an
189 // ExceptionHandler instance.
190 static bool WriteMinidump(const wstring &dump_path,
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000191 MinidumpCallback callback, void* callback_context);
bryner1217c1f2006-09-27 01:00:32 +0000192
mmentovai6a3f8792007-08-17 19:42:18 +0000193 // Get the thread ID of the thread requesting the dump (either the exception
194 // thread or any other thread that called WriteMinidump directly). This
195 // may be useful if you want to include additional thread state in your
196 // dumps.
197 DWORD get_requesting_thread_id() const { return requesting_thread_id_; }
198
mmentovaif4021f02007-10-18 20:54:20 +0000199 // Controls behavior of EXCEPTION_BREAKPOINT and EXCEPTION_SINGLE_STEP.
200 bool get_handle_debug_exceptions() const { return handle_debug_exceptions_; }
201 void set_handle_debug_exceptions(bool handle_debug_exceptions) {
202 handle_debug_exceptions_ = handle_debug_exceptions;
203 }
204
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000205 // Returns whether out-of-process dump generation is used or not.
206 bool IsOutOfProcess() const { return crash_generation_client_.get() != NULL; }
207
bryner1217c1f2006-09-27 01:00:32 +0000208 private:
mmentovaibaff9382007-02-07 20:20:10 +0000209 friend class AutoExceptionHandler;
210
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000211 // Initializes the instance with given values.
212 void Initialize(const wstring& dump_path,
213 FilterCallback filter,
214 MinidumpCallback callback,
215 void* callback_context,
216 int handler_types,
217 MINIDUMP_TYPE dump_type,
doshimun0ded3d72008-05-05 20:03:56 +0000218 const wchar_t* pipe_name,
219 const CustomClientInfo* custom_info);
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000220
bryner1217c1f2006-09-27 01:00:32 +0000221 // Function pointer type for MiniDumpWriteDump, which is looked up
222 // dynamically.
223 typedef BOOL (WINAPI *MiniDumpWriteDump_type)(
224 HANDLE hProcess,
225 DWORD dwPid,
226 HANDLE hFile,
227 MINIDUMP_TYPE DumpType,
228 CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
229 CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
230 CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
231
mmentovai469580e2008-01-28 20:02:01 +0000232 // Function pointer type for UuidCreate, which is looked up dynamically.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000233 typedef RPC_STATUS (RPC_ENTRY *UuidCreate_type)(UUID* Uuid);
mmentovai469580e2008-01-28 20:02:01 +0000234
mmentovaib2610192006-10-31 16:49:38 +0000235 // Runs the main loop for the exception handler thread.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000236 static DWORD WINAPI ExceptionHandlerThreadMain(void* lpParameter);
bryner1217c1f2006-09-27 01:00:32 +0000237
mmentovaib2610192006-10-31 16:49:38 +0000238 // Called on the exception thread when an unhandled exception occurs.
239 // Signals the exception handler thread to handle the exception.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000240 static LONG WINAPI HandleException(EXCEPTION_POINTERS* exinfo);
bryner1217c1f2006-09-27 01:00:32 +0000241
mmentovaibaff9382007-02-07 20:20:10 +0000242#if _MSC_VER >= 1400 // MSVC 2005/8
243 // This function will be called by some CRT functions when they detect
244 // that they were passed an invalid parameter. Note that in _DEBUG builds,
245 // the CRT may display an assertion dialog before calling this function,
246 // and the function will not be called unless the assertion dialog is
247 // dismissed by clicking "Ignore."
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000248 static void HandleInvalidParameter(const wchar_t* expression,
249 const wchar_t* function,
250 const wchar_t* file,
mmentovaibaff9382007-02-07 20:20:10 +0000251 unsigned int line,
252 uintptr_t reserved);
253#endif // _MSC_VER >= 1400
254
ted.mielczarekb86e7ec2007-05-10 17:12:14 +0000255 // This function will be called by the CRT when a pure virtual
256 // function is called.
257 static void HandlePureVirtualCall();
258
mmentovaib2610192006-10-31 16:49:38 +0000259 // This is called on the exception thread or on another thread that
260 // the user wishes to produce a dump from. It calls
261 // WriteMinidumpWithException on the handler thread, avoiding stack
262 // overflows and inconsistent dumps due to writing the dump from
263 // the exception thread. If the dump is requested as a result of an
264 // exception, exinfo contains exception information, otherwise, it
mmentovaibaff9382007-02-07 20:20:10 +0000265 // is NULL. If the dump is requested as a result of an assertion
266 // (such as an invalid parameter being passed to a CRT function),
267 // assertion contains data about the assertion, otherwise, it is NULL.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000268 bool WriteMinidumpOnHandlerThread(EXCEPTION_POINTERS* exinfo,
269 MDRawAssertionInfo* assertion);
mmentovaib2610192006-10-31 16:49:38 +0000270
271 // This function does the actual writing of a minidump. It is called
272 // on the handler thread. requesting_thread_id is the ID of the thread
273 // that requested the dump. If the dump is requested as a result of
274 // an exception, exinfo contains exception information, otherwise,
275 // it is NULL.
276 bool WriteMinidumpWithException(DWORD requesting_thread_id,
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000277 EXCEPTION_POINTERS* exinfo,
278 MDRawAssertionInfo* assertion);
mmentovaib2610192006-10-31 16:49:38 +0000279
mmentovaied61ae02006-11-28 19:47:44 +0000280 // Generates a new ID and stores it in next_minidump_id_, and stores the
281 // path of the next minidump to be written in next_minidump_path_.
bryner1217c1f2006-09-27 01:00:32 +0000282 void UpdateNextID();
283
mmentovai283fd392006-12-07 20:46:54 +0000284 FilterCallback filter_;
bryner1217c1f2006-09-27 01:00:32 +0000285 MinidumpCallback callback_;
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000286 void* callback_context_;
287
288 scoped_ptr<CrashGenerationClient> crash_generation_client_;
bryner1217c1f2006-09-27 01:00:32 +0000289
mmentovai283fd392006-12-07 20:46:54 +0000290 // The directory in which a minidump will be written, set by the dump_path
291 // argument to the constructor, or set_dump_path.
bryner1217c1f2006-09-27 01:00:32 +0000292 wstring dump_path_;
mmentovai283fd392006-12-07 20:46:54 +0000293
294 // The basename of the next minidump to be written, without the extension.
mmentovai29401d22006-10-26 18:06:43 +0000295 wstring next_minidump_id_;
mmentovai283fd392006-12-07 20:46:54 +0000296
297 // The full pathname of the next minidump to be written, including the file
298 // extension.
mmentovaied61ae02006-11-28 19:47:44 +0000299 wstring next_minidump_path_;
bryner1217c1f2006-09-27 01:00:32 +0000300
mmentovai283fd392006-12-07 20:46:54 +0000301 // Pointers to C-string representations of the above. These are set when
302 // the above wstring versions are set in order to avoid calling c_str during
303 // an exception, as c_str may attempt to allocate heap memory. These
304 // pointers are not owned by the ExceptionHandler object, but their lifetimes
305 // should be equivalent to the lifetimes of the associated wstring, provided
306 // that the wstrings are not altered.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000307 const wchar_t* dump_path_c_;
308 const wchar_t* next_minidump_id_c_;
309 const wchar_t* next_minidump_path_c_;
mmentovai283fd392006-12-07 20:46:54 +0000310
bryner1217c1f2006-09-27 01:00:32 +0000311 HMODULE dbghelp_module_;
312 MiniDumpWriteDump_type minidump_write_dump_;
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000313 MINIDUMP_TYPE dump_type_;
bryner1217c1f2006-09-27 01:00:32 +0000314
mmentovai469580e2008-01-28 20:02:01 +0000315 HMODULE rpcrt4_module_;
316 UuidCreate_type uuid_create_;
317
mmentovai6a844b12007-07-02 19:41:05 +0000318 // Tracks the handler types that were installed according to the
319 // handler_types constructor argument.
mmentovai3c07b282007-07-02 20:41:30 +0000320 int handler_types_;
mmentovai65dbfcc2006-12-08 22:49:07 +0000321
322 // When installed_handler_ is true, previous_filter_ is the unhandled
323 // exception filter that was set prior to installing ExceptionHandler as
324 // the unhandled exception filter and pointing it to |this|. NULL indicates
325 // that there is no previous unhandled exception filter.
bryner1217c1f2006-09-27 01:00:32 +0000326 LPTOP_LEVEL_EXCEPTION_FILTER previous_filter_;
mmentovai65dbfcc2006-12-08 22:49:07 +0000327
mmentovaibaff9382007-02-07 20:20:10 +0000328#if _MSC_VER >= 1400 // MSVC 2005/8
329 // Beginning in VC 8, the CRT provides an invalid parameter handler that will
330 // be called when some CRT functions are passed invalid parameters. In
331 // earlier CRTs, the same conditions would cause unexpected behavior or
332 // crashes.
333 _invalid_parameter_handler previous_iph_;
334#endif // _MSC_VER >= 1400
335
ted.mielczarekb86e7ec2007-05-10 17:12:14 +0000336 // The CRT allows you to override the default handler for pure
337 // virtual function calls.
338 _purecall_handler previous_pch_;
339
mmentovai283fd392006-12-07 20:46:54 +0000340 // The exception handler thread.
341 HANDLE handler_thread_;
mmentovaib2610192006-10-31 16:49:38 +0000342
doshimuna6f58a12009-01-14 20:51:51 +0000343 // True if the exception handler is being destroyed.
344 // Starting with MSVC 2005, Visual C has stronger guarantees on volatile vars.
345 // It has release semantics on write and acquire semantics on reads.
346 // See the msdn documentation.
347 volatile bool is_shutdown_;
348
mmentovaib2610192006-10-31 16:49:38 +0000349 // The critical section enforcing the requirement that only one exception be
mmentovai283fd392006-12-07 20:46:54 +0000350 // handled by a handler at a time.
351 CRITICAL_SECTION handler_critical_section_;
mmentovaib2610192006-10-31 16:49:38 +0000352
353 // Semaphores used to move exception handling between the exception thread
354 // and the handler thread. handler_start_semaphore_ is signalled by the
355 // exception thread to wake up the handler thread when an exception occurs.
356 // handler_finish_semaphore_ is signalled by the handler thread to wake up
357 // the exception thread when handling is complete.
mmentovai283fd392006-12-07 20:46:54 +0000358 HANDLE handler_start_semaphore_;
359 HANDLE handler_finish_semaphore_;
mmentovaib2610192006-10-31 16:49:38 +0000360
mmentovai283fd392006-12-07 20:46:54 +0000361 // The next 2 fields contain data passed from the requesting thread to
mmentovaib2610192006-10-31 16:49:38 +0000362 // the handler thread.
363
mmentovaib2610192006-10-31 16:49:38 +0000364 // The thread ID of the thread requesting the dump (either the exception
365 // thread or any other thread that called WriteMinidump directly).
mmentovai283fd392006-12-07 20:46:54 +0000366 DWORD requesting_thread_id_;
mmentovaib2610192006-10-31 16:49:38 +0000367
368 // The exception info passed to the exception handler on the exception
369 // thread, if an exception occurred. NULL for user-requested dumps.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000370 EXCEPTION_POINTERS* exception_info_;
mmentovaib2610192006-10-31 16:49:38 +0000371
mmentovaibaff9382007-02-07 20:20:10 +0000372 // If the handler is invoked due to an assertion, this will contain a
373 // pointer to the assertion information. It is NULL at other times.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000374 MDRawAssertionInfo* assertion_;
mmentovaibaff9382007-02-07 20:20:10 +0000375
mmentovaib2610192006-10-31 16:49:38 +0000376 // The return value of the handler, passed from the handler thread back to
377 // the requesting thread.
mmentovai283fd392006-12-07 20:46:54 +0000378 bool handler_return_value_;
379
mmentovaif4021f02007-10-18 20:54:20 +0000380 // If true, the handler will intercept EXCEPTION_BREAKPOINT and
381 // EXCEPTION_SINGLE_STEP exceptions. Leave this false (the default)
382 // to not interfere with debuggers.
383 bool handle_debug_exceptions_;
384
mmentovai65dbfcc2006-12-08 22:49:07 +0000385 // A stack of ExceptionHandler objects that have installed unhandled
386 // exception filters. This vector is used by HandleException to determine
387 // which ExceptionHandler object to route an exception to. When an
388 // ExceptionHandler is created with install_handler true, it will append
389 // itself to this list.
doshimun@gmail.comc79141e2008-03-08 00:02:40 +0000390 static vector<ExceptionHandler*>* handler_stack_;
mmentovai65dbfcc2006-12-08 22:49:07 +0000391
392 // The index of the ExceptionHandler in handler_stack_ that will handle the
393 // next exception. Note that 0 means the last entry in handler_stack_, 1
394 // means the next-to-last entry, and so on. This is used by HandleException
mmentovaie5dc6082007-02-14 19:51:05 +0000395 // to support multiple stacked Breakpad handlers.
mmentovai65dbfcc2006-12-08 22:49:07 +0000396 static LONG handler_stack_index_;
397
398 // handler_stack_critical_section_ guards operations on handler_stack_ and
doshimuna6f58a12009-01-14 20:51:51 +0000399 // handler_stack_index_. The critical section is initialized by the
400 // first instance of the class and destroyed by the last instance of it.
mmentovai283fd392006-12-07 20:46:54 +0000401 static CRITICAL_SECTION handler_stack_critical_section_;
402
doshimuna6f58a12009-01-14 20:51:51 +0000403 // The number of instances of this class.
404 volatile static LONG instance_count_;
mmentovaib2610192006-10-31 16:49:38 +0000405
bryner1217c1f2006-09-27 01:00:32 +0000406 // disallow copy ctor and operator=
407 explicit ExceptionHandler(const ExceptionHandler &);
408 void operator=(const ExceptionHandler &);
409};
410
mmentovaie5dc6082007-02-14 19:51:05 +0000411} // namespace google_breakpad
bryner1217c1f2006-09-27 01:00:32 +0000412
mmentovai12a52452006-10-27 19:47:21 +0000413#pragma warning( pop )
414
bryner1217c1f2006-09-27 01:00:32 +0000415#endif // CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__