PostgreSQL Source Code git master
Loading...
Searching...
No Matches
crashdump.c File Reference
#include "postgres.h"
#include <dbghelp.h>
Include dependency graph for crashdump.c:

Go to the source code of this file.

Typedefs

typedef BOOL(WINAPIMINIDUMPWRITEDUMP) (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)
 

Functions

static LONG WINAPI crashDumpHandler (struct _EXCEPTION_POINTERS *pExceptionInfo)
 
void pgwin32_install_crashdump_handler (void)
 

Typedef Documentation

◆ MINIDUMPWRITEDUMP

Function Documentation

◆ crashDumpHandler()

static LONG WINAPI crashDumpHandler ( struct _EXCEPTION_POINTERS pExceptionInfo)
static

Definition at line 76 of file crashdump.c.

77{
78 /*
79 * We only write crash dumps if the "crashdumps" directory within the
80 * postgres data directory exists.
81 */
82 DWORD attribs = GetFileAttributesA("crashdumps");
83
85 {
86 /* 'crashdumps' exists and is a directory. Try to write a dump' */
90 char dumpPath[_MAX_PATH];
96
97 ExInfo.ThreadId = GetCurrentThreadId();
98 ExInfo.ExceptionPointers = pExceptionInfo;
99 ExInfo.ClientPointers = FALSE;
100
101 /* Load the dbghelp.dll library and functions */
102 hDll = LoadLibrary("dbghelp.dll");
103 if (hDll == NULL)
104 {
105 write_stderr("could not load dbghelp.dll, cannot write crash dump\n");
107 }
108
109 pDump = (MINIDUMPWRITEDUMP) (pg_funcptr_t) GetProcAddress(hDll, "MiniDumpWriteDump");
110
111 if (pDump == NULL)
112 {
113 write_stderr("could not load required functions in dbghelp.dll, cannot write crash dump\n");
115 }
116
117 /*
118 * Dump as much as we can, except shared memory, code segments, and
119 * memory mapped files. Exactly what we can dump depends on the
120 * version of dbghelp.dll, see:
121 * http://msdn.microsoft.com/en-us/library/ms680519(v=VS.85).aspx
122 */
125
126 if (GetProcAddress(hDll, "EnumDirTree") != NULL)
127 {
128 /* If this function exists, we have version 5.2 or newer */
131 }
132
135 "crashdumps\\postgres-pid%0i-%0i.mdmp",
136 (int) selfPid, (int) systemTicks);
137 dumpPath[_MAX_PATH - 1] = '\0';
138
141 NULL);
143 {
144 write_stderr("could not open crash dump file \"%s\" for writing: error code %lu\n",
147 }
148
150 NULL, NULL))
151 write_stderr("wrote crash dump to file \"%s\"\n", dumpPath);
152 else
153 write_stderr("could not write crash dump to file \"%s\": error code %lu\n",
155
157 }
158
160}
#define write_stderr(str)
Definition parallel.c:186
void(* pg_funcptr_t)(void)
Definition c.h:548
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)
Definition crashdump.c:57
static void dumpType(Archive *fout, const TypeInfo *tyinfo)
Definition pg_dump.c:12217
#define snprintf
Definition port.h:260
static int fb(int x)

References dumpType(), fb(), snprintf, and write_stderr.

Referenced by pgwin32_install_crashdump_handler().

◆ pgwin32_install_crashdump_handler()

void pgwin32_install_crashdump_handler ( void  )

Definition at line 164 of file crashdump.c.

165{
167}
static LONG WINAPI crashDumpHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
Definition crashdump.c:76

References crashDumpHandler(), and fb().

Referenced by main().