Remove dependency on ole32 on Windows (#132). Patch by Sorin Jianu <sorinj>, r=me.

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@237 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2008-01-28 20:02:01 +00:00
parent b801cd6d0f
commit 469580e2df
3 changed files with 33 additions and 12 deletions

View File

@ -62,6 +62,8 @@ ExceptionHandler::ExceptionHandler(const wstring &dump_path,
next_minidump_path_c_(NULL), next_minidump_path_c_(NULL),
dbghelp_module_(NULL), dbghelp_module_(NULL),
minidump_write_dump_(NULL), minidump_write_dump_(NULL),
rpcrt4_module_(NULL),
uuid_create_(NULL),
handler_types_(handler_types), handler_types_(handler_types),
previous_filter_(NULL), previous_filter_(NULL),
previous_pch_(NULL), previous_pch_(NULL),
@ -78,10 +80,6 @@ ExceptionHandler::ExceptionHandler(const wstring &dump_path,
previous_iph_ = NULL; previous_iph_ = NULL;
#endif // _MSC_VER >= 1400 #endif // _MSC_VER >= 1400
// set_dump_path calls UpdateNextID. This sets up all of the path and id
// strings, and their equivalent c_str pointers.
set_dump_path(dump_path);
// Set synchronization primitives and the handler thread. Each // Set synchronization primitives and the handler thread. Each
// ExceptionHandler object gets its own handler thread because that's the // ExceptionHandler object gets its own handler thread because that's the
// only way to reliably guarantee sufficient stack space in an exception, // only way to reliably guarantee sufficient stack space in an exception,
@ -105,6 +103,19 @@ ExceptionHandler::ExceptionHandler(const wstring &dump_path,
GetProcAddress(dbghelp_module_, "MiniDumpWriteDump")); GetProcAddress(dbghelp_module_, "MiniDumpWriteDump"));
} }
// Load this library dynamically to not affect existing projects. Most
// projects don't link against this directly, it's usually dynamically
// loaded by dependent code.
rpcrt4_module_ = LoadLibrary(L"rpcrt4.dll");
if (rpcrt4_module_) {
uuid_create_ = reinterpret_cast<UuidCreate_type>(
GetProcAddress(rpcrt4_module_, "UuidCreate"));
}
// set_dump_path calls UpdateNextID. This sets up all of the path and id
// strings, and their equivalent c_str pointers.
set_dump_path(dump_path);
if (handler_types != HANDLER_NONE) { if (handler_types != HANDLER_NONE) {
if (!handler_stack_critical_section_initialized_) { if (!handler_stack_critical_section_initialized_) {
InitializeCriticalSection(&handler_stack_critical_section_); InitializeCriticalSection(&handler_stack_critical_section_);
@ -140,6 +151,10 @@ ExceptionHandler::~ExceptionHandler() {
FreeLibrary(dbghelp_module_); FreeLibrary(dbghelp_module_);
} }
if (rpcrt4_module_) {
FreeLibrary(rpcrt4_module_);
}
if (handler_types_ != HANDLER_NONE) { if (handler_types_ != HANDLER_NONE) {
EnterCriticalSection(&handler_stack_critical_section_); EnterCriticalSection(&handler_stack_critical_section_);
@ -518,8 +533,11 @@ bool ExceptionHandler::WriteMinidumpWithException(
} }
void ExceptionHandler::UpdateNextID() { void ExceptionHandler::UpdateNextID() {
GUID id; assert(uuid_create_);
CoCreateGuid(&id); UUID id = {0};
if (uuid_create_) {
uuid_create_(&id);
}
next_minidump_id_ = GUIDString::GUIDToWString(&id); next_minidump_id_ = GUIDString::GUIDToWString(&id);
next_minidump_id_c_ = next_minidump_id_.c_str(); next_minidump_id_c_ = next_minidump_id_.c_str();

View File

@ -52,9 +52,6 @@
// ExceptionHandler *f = new ExceptionHandler(...); // ExceptionHandler *f = new ExceptionHandler(...);
// delete e; // delete e;
// This will put the exception filter stack into an inconsistent state. // This will put the exception filter stack into an inconsistent state.
//
// To use this library in your project, you will need to link against
// ole32.lib.
#ifndef CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__ #ifndef CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__
#define CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__ #define CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__
@ -62,6 +59,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <Windows.h> #include <Windows.h>
#include <DbgHelp.h> #include <DbgHelp.h>
#include <rpc.h>
#pragma warning( push ) #pragma warning( push )
// Disable exception handler warnings. // Disable exception handler warnings.
@ -195,6 +193,9 @@ class ExceptionHandler {
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
// Function pointer type for UuidCreate, which is looked up dynamically.
typedef RPC_STATUS (RPC_ENTRY *UuidCreate_type)(UUID *Uuid);
// Runs the main loop for the exception handler thread. // Runs the main loop for the exception handler thread.
static DWORD WINAPI ExceptionHandlerThreadMain(void *lpParameter); static DWORD WINAPI ExceptionHandlerThreadMain(void *lpParameter);
@ -272,6 +273,9 @@ class ExceptionHandler {
HMODULE dbghelp_module_; HMODULE dbghelp_module_;
MiniDumpWriteDump_type minidump_write_dump_; MiniDumpWriteDump_type minidump_write_dump_;
HMODULE rpcrt4_module_;
UuidCreate_type uuid_create_;
// Tracks the handler types that were installed according to the // Tracks the handler types that were installed according to the
// handler_types constructor argument. // handler_types constructor argument.
int handler_types_; int handler_types_;

View File

@ -29,8 +29,7 @@
// This file is used to generate minidump2.dmp and minidump2.sym. // This file is used to generate minidump2.dmp and minidump2.sym.
// cl /Zi test_app.cc /Fetest_app.exe /I google_breakpad/src \ // cl /Zi test_app.cc /Fetest_app.exe /I google_breakpad/src \
// google_breakpad/src/client/windows/releasestaticcrt/exception_handler.lib \ // google_breakpad/src/client/windows/releasestaticcrt/exception_handler.lib
// ole32.lib
// Then run test_app to generate a dump, and dump_syms to create the .sym file. // Then run test_app to generate a dump, and dump_syms to create the .sym file.
#include <cstdio> #include <cstdio>