91{
92
93
94
95
96 DWORD attribs = GetFileAttributesA("crashdumps");
97
98 if (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY))
99 {
100
101 HMODULE hDll = NULL;
104 char dumpPath[_MAX_PATH];
105 HANDLE selfProcHandle = GetCurrentProcess();
106 DWORD selfPid = GetProcessId(selfProcHandle);
107 HANDLE dumpFile;
108 DWORD systemTicks;
109 struct _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
110
111 ExInfo.ThreadId = GetCurrentThreadId();
112 ExInfo.ExceptionPointers = pExceptionInfo;
113 ExInfo.ClientPointers = FALSE;
114
115
116 hDll = LoadLibrary("dbghelp.dll");
117 if (hDll == NULL)
118 {
119 write_stderr(
"could not load dbghelp.dll, cannot write crash dump\n");
120 return EXCEPTION_CONTINUE_SEARCH;
121 }
122
124
125 if (pDump == NULL)
126 {
127 write_stderr(
"could not load required functions in dbghelp.dll, cannot write crash dump\n");
128 return EXCEPTION_CONTINUE_SEARCH;
129 }
130
131
132
133
134
135
136
137 dumpType = MiniDumpNormal | MiniDumpWithHandleData |
138 MiniDumpWithDataSegs;
139
140 if (GetProcAddress(hDll, "EnumDirTree") != NULL)
141 {
142
143 dumpType |= MiniDumpWithIndirectlyReferencedMemory |
144 MiniDumpWithPrivateReadWriteMemory;
145 }
146
147 systemTicks = GetTickCount();
149 "crashdumps\\postgres-pid%0i-%0i.mdmp",
150 (int) selfPid, (int) systemTicks);
151 dumpPath[_MAX_PATH - 1] = '\0';
152
153 dumpFile = CreateFile(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
154 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
155 NULL);
156 if (dumpFile == INVALID_HANDLE_VALUE)
157 {
158 write_stderr(
"could not open crash dump file \"%s\" for writing: error code %lu\n",
159 dumpPath, GetLastError());
160 return EXCEPTION_CONTINUE_SEARCH;
161 }
162
163 if ((*pDump) (selfProcHandle, selfPid, dumpFile,
dumpType, &ExInfo,
164 NULL, NULL))
165 write_stderr(
"wrote crash dump to file \"%s\"\n", dumpPath);
166 else
167 write_stderr(
"could not write crash dump to file \"%s\": error code %lu\n",
168 dumpPath, GetLastError());
169
170 CloseHandle(dumpFile);
171 }
172
173 return EXCEPTION_CONTINUE_SEARCH;
174}
#define write_stderr(str)
void(* pg_funcptr_t)(void)
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)
static void dumpType(Archive *fout, const TypeInfo *tyinfo)