50 #pragma warning(disable : 4091)
71 typedef BOOL (WINAPI *
MINIDUMPWRITEDUMP) (HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
72 CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
73 CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
74 CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam
96 DWORD attribs = GetFileAttributesA(
"crashdumps");
98 if (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY))
104 char dumpPath[_MAX_PATH];
105 HANDLE selfProcHandle = GetCurrentProcess();
106 DWORD selfPid = GetProcessId(selfProcHandle);
109 struct _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
111 ExInfo.ThreadId = GetCurrentThreadId();
112 ExInfo.ExceptionPointers = pExceptionInfo;
113 ExInfo.ClientPointers = FALSE;
116 hDll = LoadLibrary(
"dbghelp.dll");
119 write_stderr(
"could not load dbghelp.dll, cannot write crash dump\n");
120 return EXCEPTION_CONTINUE_SEARCH;
127 write_stderr(
"could not load required functions in dbghelp.dll, cannot write crash dump\n");
128 return EXCEPTION_CONTINUE_SEARCH;
137 dumpType = MiniDumpNormal | MiniDumpWithHandleData |
138 MiniDumpWithDataSegs;
140 if (GetProcAddress(hDll,
"EnumDirTree") != NULL)
143 dumpType |= MiniDumpWithIndirectlyReferencedMemory |
144 MiniDumpWithPrivateReadWriteMemory;
147 systemTicks = GetTickCount();
149 "crashdumps\\postgres-pid%0i-%0i.mdmp",
150 (
int) selfPid, (
int) systemTicks);
151 dumpPath[_MAX_PATH - 1] =
'\0';
153 dumpFile = CreateFile(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
154 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
156 if (dumpFile == INVALID_HANDLE_VALUE)
158 write_stderr(
"could not open crash dump file \"%s\" for writing: error code %lu\n",
159 dumpPath, GetLastError());
160 return EXCEPTION_CONTINUE_SEARCH;
163 if ((*pDump) (selfProcHandle, selfPid, dumpFile,
dumpType, &ExInfo,
165 write_stderr(
"wrote crash dump to file \"%s\"\n", dumpPath);
167 write_stderr(
"could not write crash dump to file \"%s\": error code %lu\n",
168 dumpPath, GetLastError());
170 CloseHandle(dumpFile);
173 return EXCEPTION_CONTINUE_SEARCH;
#define write_stderr(str)
void(* pg_funcptr_t)(void)
static LONG WINAPI crashDumpHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
BOOL(WINAPI * MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam)
void pgwin32_install_crashdump_handler(void)
static void dumpType(Archive *fout, const TypeInfo *tyinfo)