Index: modules/portlib/src/main/native/port/windows/hysignal.c =================================================================== --- modules/portlib/src/main/native/port/windows/hysignal.c (revision 500164) +++ modules/portlib/src/main/native/port/windows/hysignal.c (working copy) @@ -20,6 +20,8 @@ #include "hyport.h" #include "hythread.h" #include "hysignal.h" +#include +#include typedef struct HyWin32AsyncHandlerRecord { @@ -295,7 +297,55 @@ } #undef CDEV_CURRENT_FUNCTION +static void +genMiniDumpFile (EXCEPTION_POINTERS * exceptionInfo, char* dumpInfo) +{ + typedef BOOL (WINAPI * MINIDUMPPROC)(HANDLE /*hProcess*/, DWORD /*ProcessId*/, + HANDLE /*hFile*/, MINIDUMP_TYPE /*DumpType*/, PMINIDUMP_EXCEPTION_INFORMATION /*ExceptionParam*/, + PMINIDUMP_USER_STREAM_INFORMATION /*UserStreamParam*/, PMINIDUMP_CALLBACK_INFORMATION /*CallbackParam*/); + MINIDUMPPROC _MiniDumpWriteDump = NULL; + HANDLE dmpFile = 0; + DWORD uv = 0; + char dumpFileName[64] = {0}; + HMODULE dbghLib = NULL; + BOOL res = FALSE; + MINIDUMP_EXCEPTION_INFORMATION mei; + dbghLib = LoadLibrary( "DBGHELP.DLL"); + if (!dbghLib){ + sprintf(dumpInfo, "Failed to load DbgHelp library."); + return; + } + _MiniDumpWriteDump = (MINIDUMPPROC)GetProcAddress(dbghLib, "MiniDumpWriteDump"); + if (!_MiniDumpWriteDump){ + sprintf(dumpInfo, "Failed to load DbgHelp library."); + return; + } + + uv = GetTickCount(); + sprintf(dumpFileName, "hydump_%d.dmp", uv); + dmpFile = CreateFile(dumpFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (dmpFile == INVALID_HANDLE_VALUE){ + sprintf(dumpInfo, "Failed to create dump file: .%s", dumpFileName); + return; + } + + mei.ThreadId = GetCurrentThreadId(); + mei.ExceptionPointers = exceptionInfo; + mei.ClientPointers = TRUE; + + res = _MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), dmpFile, MiniDumpNormal, &mei, 0, 0 ); + if (!res){ + sprintf(dumpInfo, "Failed generate dump file."); + } + else{ + char dir[_MAX_PATH] = {0}; + GetCurrentDirectory( _MAX_PATH, dir); + sprintf(dumpInfo, "%s\\%s", dir, dumpFileName); + } + CloseHandle(dmpFile); +} + #define CDEV_CURRENT_FUNCTION structuredExceptionHandler int structuredExceptionHandler (struct HyPortLibrary *portLibrary, @@ -409,7 +459,7 @@ hyinfo->handlerAddress2 = (void *) structuredExceptionHandler; hyinfo->ExceptionRecord = exceptionInfo->ExceptionRecord; hyinfo->ContextRecord = exceptionInfo->ContextRecord; - + genMiniDumpFile(exceptionInfo, hyinfo->dumpInfo); /* module info is filled on demand */ } @@ -622,6 +672,10 @@ *name = "Offset_in_DLL"; *value = &info->offsetInDLL; return HYPORT_SIG_VALUE_32; + case 3: + *name = "Dumpfile"; + *value = &info->dumpInfo; + return HYPORT_SIG_VALUE_STRING; default: return HYPORT_SIG_VALUE_UNDEFINED; } Index: modules/portlib/src/main/native/port/windows/hysignal.h =================================================================== --- modules/portlib/src/main/native/port/windows/hysignal.h (revision 500164) +++ modules/portlib/src/main/native/port/windows/hysignal.h (working copy) @@ -30,6 +30,7 @@ void *moduleBaseAddress; U_32 offsetInDLL; char moduleName[_MAX_PATH]; + char dumpInfo[_MAX_PATH]; } HyWin32SignalInfo; #endif /* hysignal_h */