// This method unblocks the parent process
void CErrorReportExporter::UnblockParentProcess()
{
	// Notify the parent process that we have finished with minidump,
	// so the parent process is able to unblock and terminate itself.

	// Open the event the parent process had created for us
	CString sEventName;
	sEventName.Format(_T("Local\\CrashRptEvent_%s"), GetCrashInfo()->GetReport(0)->GetCrashGUID());
	HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, sEventName);
	if(hEvent!=NULL)
		SetEvent(hEvent); // Signal event
}
Example #2
0
static BOOL saveMiniDump(EXCEPTION_POINTERS* pExceptionInfos)
{
	BOOL result = FALSE;
#ifdef _M_IX86
	if (pExceptionInfos->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)  
	{  
		static char TempStack[1024 * 128];
		__asm mov eax,offset TempStack[1024 * 128];
		__asm mov esp,eax;
	}
#endif

	CrashInfo crashInfo = GetCrashInfo(pExceptionInfos->ExceptionRecord);
	vector<CallStackInfo> arrCallStackInfo = GetCallStack(pExceptionInfos->ContextRecord);
	CString dumpPath = FileMgr::GetAppPath() + _T("\\MyEcho.dmp");

	Json::Value jDump, jCrash, jCallStack;
	CHAR szObject[MAX_PATH];
	::GetModuleFileNameA(NULL, szObject, MAX_PATH);
	jCrash["Object"] = szObject;
	jCrash["ErrorCode"] = crashInfo.ErrorCode;
	jCrash["Address"] = crashInfo.Address;
	jCrash["Flags"] = crashInfo.Flags;

	for (vector<CallStackInfo>::iterator i = arrCallStackInfo.begin(); i != arrCallStackInfo.end(); ++i)
	{
		CallStackInfo callstackinfo = (*i);
		jCallStack[callstackinfo.MethodName] = std::string("[") + callstackinfo.ModuleName + std::string("] [File:") + callstackinfo.FileName + std::string(" @Line ") + callstackinfo.LineNumber + std::string("]");
		//cout << callstackinfo.MethodName << "() : [" << callstackinfo.ModuleName << "] (File: " << callstackinfo.FileName << " @Line " << callstackinfo.LineNumber << ")" << endl;  
	}

	jDump["crash"] = jCrash;
	jDump["callstack"] = jCallStack;

	// 程序崩溃时,将写入程序目录下的MyDump.dmp文件
	HANDLE hFile = ::CreateFile(dumpPath, GENERIC_WRITE,
		FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL, NULL );
	if (hFile != INVALID_HANDLE_VALUE)
	{
		/*
		MINIDUMP_EXCEPTION_INFORMATION exptInfo;
		exptInfo.ThreadId = ::GetCurrentThreadId();
		exptInfo.ExceptionPointers = pExceptionInfos;

		result = ::MiniDumpWriteDump(::GetCurrentProcess(),
			::GetCurrentProcessId(),
			hFile, MiniDumpNormal,
			&exptInfo, NULL, NULL);
		if (!result)
		{
			TCHAR temp[1024] = {0};
			_stprintf(temp, _T("GetLastError() 2 = %d"), GetLastError());
			OutputDebugString(temp);
		} */

		DWORD dwWritten = 0;
		WriteFile(hFile, jDump.toStyledString().c_str(),
			jDump.toStyledString().length(), &dwWritten, NULL);
		::CloseHandle(hFile);
	}
	else
	{
		TCHAR temp[1024] = {0};
		_stprintf(temp, _T("GetLastError() 1 = %d"), GetLastError());
		OutputDebugString(temp);
	}

	return result;
}