Windows Dump
lastmod 2020-10-26created 2016-11-275 edits
Writing a Minidump with Code
The actual implementation is straightforward. The following is a simple example of how to use MiniDumpWriteDump.
#include <dbghelp.h>
#include <shellapi.h>
#include <shlobj.h>
int GenerateDump(EXCEPTION_POINTERS* pExceptionPointers)
{
BOOL bMiniDumpSuccessful;
WCHAR szPath[MAX_PATH];
WCHAR szFileName[MAX_PATH];
WCHAR* szAppName = L"AppName";
WCHAR* szVersion = L"v1.0";
DWORD dwBufferSize = MAX_PATH;
HANDLE hDumpFile;
SYSTEMTIME stLocalTime;
MINIDUMP_EXCEPTION_INFORMATION ExpParam;
GetLocalTime( &stLocalTime );
GetTempPath( dwBufferSize, szPath );
StringCchPrintf( szFileName, MAX_PATH, L"%s%s", szPath, szAppName );
CreateDirectory( szFileName, NULL );
StringCchPrintf( szFileName, MAX_PATH, L"%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp",
szPath, szAppName, szVersion,
stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay,
stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond,
GetCurrentProcessId(), GetCurrentThreadId());
hDumpFile = CreateFile(szFileName, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
ExpParam.ThreadId = GetCurrentThreadId();
ExpParam.ExceptionPointers = pExceptionPointers;
ExpParam.ClientPointers = TRUE;
bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL);
return EXCEPTION_EXECUTE_HANDLER;
}
void SomeFunction()
{
__try
{
int *pBadPtr = NULL;
*pBadPtr = 0;
}
__except(GenerateDump(GetExceptionInformation()))
{
}
}
Category
See also
Favorite site
- MSDN: Using Dump Files
- How to generate a memory dump with keyboard input
- Windows feature lets you generate a memory dump file by using the keyboard
- Windows memory dump overview and how to configure it
- Changes to the memory dump generation process in Windows 7
- jkmoon.tistory.com - Memory dump settings
- Using your own symbols: source indexing with a source server
- Analyzing a memory dump 2
- Analyzing Windows dump files
- MSDN: How to read the small memory dump file that Windows creates for debugging
- Changes to the memory dump generation process in Windows 7
- Debugging Tips (7) - Analyzing an Application Memory Dump (part 2)
- How to debug with Visual Studio (using dump and pdb files)
- Slideshare - Practical techniques for post-mortem debugging with dump files NDC2012