Crash dump进程信息

  linux下 比较简单,这里不在说明,
  
  windows下 相对复杂一点,用SetUnhandledExceptionFilter 来捕获 MiniDumpWriteDump 来写dmp文件,这种方法还不够完全,一些错误 一样无法捕获 比如 多次 delete ,可修改注册表  crash自动生成dmp 而不用代码去控制   结合代码控制 一起使用
  
  #if _WIN32
  
  #include
  
  #include
  
  #pragma comment(lib, "dbghelp.lib")
  
  void myInvalidParameterHandler(const wchar_t* expression,
  
  const wchar_t* function,
  
  const wchar_t* file,
  
  unsigned int line,
  
  uintptr_t pReserved)
  
  {
  
  throw 1;
  
  }
  
  LONG CustomCrashHandledExceptionFilter(_EXCEPTION_POINTERS *ExceptionInfo)
  
  {
  
  CHAR strDumpFile[MAX_PATH] = { 0 };
  
  SYSTEMTIME tm;
  
  HANDLE hFile = NULL;
  
  time_t rawtime;
  
  struct tm * t;
  
  time(&rawtime);
  
  t = localtime(&rawtime);
  
  sprintf(strDumpFile, "%d%s%d-%04d-%02d-%02d-%02d-%02d-%02d.dmp", sid, name.c_str(), g_Inner_id, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->www.boyunylpt1.com tm_min, t->tm_sec);
  
  hFile = CreateFileA(strDumpFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  
  if (hFile != INVALID_HANDLE_VALUE)
  
  {
  
  MINIDUMP_EXCEPTION_INFORMATION ExInfo;
  
  ExInfo.ThreadId = GetCurrentThreadId();
  
  ExInfo.ExceptionPointers www.maituyul1.cn  = ExceptionInfo;
  
  ExInfo.ClientPointers = NULL;
  
  BOOL bOK = MiniDumpWriteDump(
  
  GetCurrentProcess(www.furongpt.com),
  
  GetCurrentProcessId(www.dashuju2.cn),
  
  hFile,
  
  MiniDumpNormal,
  
  &ExInfo,
  
  NULL,
  
  NULL);
  
  CloseHandle(hFile);
  
  }
  
  return EXCEPTION_CONTINUE_SEARCH;
  
  }
  
  LPTOP_LEVEL_EXCEPTION_FILTER WINAPI EmptySetUnhandledExceptionFilter(
  
  LPTOP_LEVEL_EXCEPTION_www.yingka178.com FILTER lpTopLevelExceptionFilter)
  
  {
  
  return NULL;
  
  }
  
  void myPurecallHandler(void)
  
  {
  
  throw 1;
  
  }
  
  BOOL HookSetUnhandledExceptionFilter()
  
  {
  
  HMODULE hKernel32 = LoadLibraryA(("kernel32.dll"));
  
  if (hKernel32 == NULL) return FALSE;
  
  void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
  
  if (pOrgEntry == www.yongshi123.cn NULL) return FALSE;
  
  unsigned char newJump[100];
  
  DWORD dwOrgEntryAddr = (DWORD)pOrgEntry;
  
  dwOrgEntryAddr +www.yongshiyule178.com= 5; // add 5 for 5 op-codes for jmp far
  
  void *pNewFunc = &EmptySetUnhandledExceptionFilter;
  
  DWORD dwNewEntryAddr www.michenggw.com= (DWORD)pNewFunc;
  
  DWORD dwRelativeAddr =www.dfgjpt.com dwNewEntryAddr - dwOrgEntryAddr;
  
  newJump[0] = 0xE9;  // JMP absolute
  
  memcpy(&newJump[1], &dwRelativeAddr, sizeof(pNewFunc));
  
  SIZE_T bytesWritten;
  
  BOOL bRet = WriteProcessMemory(GetCurrentProcess(),
  
  pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten);
  
  return bRet;
  
  }
  
  class CrashHandler
  
  {
  
  public:
  
  CrashHandler()
  
  {
  
  //    SetErrorMode(SEM_FAILCRITICALERRORS);
  
  SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CustomCrashHandledExceptionFilter);
  
  _purecall_handler old_pure_handle;
  
  old_pure_handle = _set_purecall_handler(myPurecallHandler);
  
  _invalid_parameter_handler oldHandler;
  
  oldHandler = _set_invalid_parameter_handler(myInvalidParameterHandler);
  
  HookSetUnhandledExceptionFilter();
  
  在高阶导数的时候说过,如果两个函数每一阶导数都相等,那么"理论上"两个函数是相等的。
  
  因为我们有cos′(x)=−sin(x)、cos′′(x)=−cos(x)、cos′′′(x)=sin(x)、cos′′′′(x)=cos(x)
  
  此后就是−sin(x)、−cos(x)、sin(x)、cos(x)循环,求导次数x,其xmod 4=1,2,3,0的时候分别对应这四个。
  
  cos(0)=1⇒f(x)=a0+∑ni=1ai⋅0=a0=1
  
  cos′(0)=0⇒f′(x)=1⋅a1+∑ni=2(i−1)ai⋅0=1!⋅a1=0
  
  cos′′(0)=−1⇒f′′(x)=1⋅2⋅a2+∑ni=3(i−1)⋅(i−2)ai=2!⋅a2=−1
  
  cos′′′(0)=0⇒f′′′(x)=1⋅2⋅3a3+∑ni=4(i−1)⋅(i−2)⋅(i−3)ai=3!⋅a3=0
  
  cos′′′′(0)=1⇒f′′′′(x)=1⋅2⋅3⋅4a4+∑ni=5(i−1)⋅(i−2)⋅(i−3)⋅(i−4)ai=4!⋅a4=1
  
  可以发现规律了,假设取了i次导数,且有i=2n。
  
  n是奇数有:i!⋅ai=−1⇒ai=−1i!
  
  n是偶数有:i!⋅ai=1⇒ai=1i!
  
  也就是cos(x)=1−x22!+x44!−x66!+x48!−⋯
  
  同样的思路可以证明sin(x)=∑∞i=2n+1,n∈N(−1)nxii!=x−x33!+x55!−x77!+⋯
  
  证明ex=⋯比这更容易,根据定义(ex)′=ex,重复上述过程即可。
  
  麦克劳林展开式
  
  ex=∑∞i=0xii!=1+x11!+x22!+x33!+x44!+⋯
  
  sin(x)=∑∞i=2n+1,n∈N(−1)nxii!=x−x33!+x55!−x77!+⋯
  
  cos(x)=∑∞i=2n,n∈N(−1)nxii!=1−x22!+x44!−x66!+⋯
  
  本文正题
  
  eix=1+(ix)11!+(ix)22!+(ix)33!+(ix)44!+(ix)55!=1+ix1!−x22!−ix33!+x44!+ix55!−⋯
  
  把带有i的提出来有:
  
  eix=1−x22!+x44!−x66!+⋯+i(x−x33!+x55!−x77!)=cos(x)+i×sin(x)
  
  当x=π的时候
  
  eiπ=cos(π)+i×sin(π)=−1
  
  所以

你可能感兴趣的:(Crash dump进程信息)