16,472
社区成员
发帖
与我相关
我的任务
分享
void CreateMiniDump(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
HMODULE hModule = ::LoadLibrary(".\\dbghelp.dll");
if( NULL == hModule )
return;
MiniDumpWriteDump_PTR pfnMiniDumpWriteDump = (MiniDumpWriteDump_PTR)GetProcAddress(hModule, "MiniDumpWriteDump");
if( NULL == pfnMiniDumpWriteDump )
{
FreeLibrary(hModule);
return;
}
char szFile[MAX_PATH+1] = {0};
_snprintf(szFile, MAX_PATH, ".\\cc_%u.dmp", time(NULL));
HANDLE hFile = CreateFile(szFile, GENERIC_ALL, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if( INVALID_HANDLE_VALUE == hFile )
{
FreeLibrary(hModule);
return;
}
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ClientPointers = TRUE;
mei.ExceptionPointers = ExceptionInfo;
// (*pfnMiniDumpWriteDump)(GetCurrentProcess(), GetCurrentProcessId(), hFile,
// MiniDumpWithFullMemory,
// &mei, NULL, NULL);
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
MiniDumpWithFullMemory,
&mei, NULL, NULL);
CloseHandle(hFile);
FreeLibrary(hModule);
}
struct _EXCEPTION_POINTERS gEx;
DWORD FilterFunction(struct _EXCEPTION_POINTERS* ex)
{
memcpy(&gEx,ex,sizeof(_EXCEPTION_POINTERS));
return 1;
}
void Dmp()
{
__try
{
// try block
throw 12;
}
__except ( FilterFunction(GetExceptionInformation()) )
{
// exception handler block
CreateMiniDump(&gEx);
}
}
#include <cstdio>
#include "client/windows/handler/exception_handler.h"
namespace {
static bool callback(const wchar_t *dump_path, const wchar_t *id,
void *context, EXCEPTION_POINTERS *exinfo,
MDRawAssertionInfo *assertion,
bool succeeded) {
if (succeeded) {
printf("dump guid is %ws\n", id);
} else {
printf("dump failed\n");
}
fflush(stdout);
return succeeded;
}
static void CrashFunction() {
int *i = reinterpret_cast<int*>(0x45);
*i = 5; // crash!
}
} // namespace
int main(int argc, char **argv) {
google_breakpad::ExceptionHandler eh(
L".", NULL, callback, NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL);
CrashFunction();
printf("did not crash?\n");
return 0;
}