Windows Server dump File

Source: Internet
Author: User

1. Mini Dump:

Need to include Dbghelp.dll library

Mini_dump.h file:

reference:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ee416349 (v=vs.85). aspx


#ifndef mini_dump_h__
#define Mini_dump_h__


Namespace MiniDump
{
void Minidumpbegin (const char* app_name, const char* app_version);
}

#endif//mini_dump_h__

Mini_dump.cpp file:

#include "Mini_dump.h"

#include <windows.h>
#include <shellapi.h>

#include <string>

is Dbghelp.h dbghelp.lib dbghelp.dll windows build-in?
#include <dbghelp.h>
#pragma comment (lib, "Dbghelp.lib")

Visual Studio 2005 Compatible
#define SNPRINTF (Buf,len, Format,...) _snprintf_s (buf, Len,len, format, __va_args__)

Namespace MiniDump
{
Needn ' t Delete
std::string* app_name = 0;

std::string* app_version = 0;

"C:\folder1\xxx.exe" to "c:\folder1\"
std::string getdirectory (const std::string& execution)
{
std::string path ("");
size_t pos = execution.find_last_of ("\ \");
if (pos! = std::string::npos)
Path = EXECUTION.SUBSTR (0, POS + 1);
return path;
}

Generage dump file to avoid file name collisions
std::string Getdumpfilemark ()
{
SYSTEMTIME System_local_time;
Getlocaltime (&system_local_time);

Char File_name[max_path];

snprintf (file_name, MAX_PATH, "%s%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp",
App_name->c_str (), App_version->c_str (),
System_local_time.wyear, System_local_time.wmonth, System_local_time.wday,
System_local_time.whour, System_local_time.wminute, System_local_time.wsecond,
GetCurrentProcessId (), GetCurrentThreadID ());

return file_name;
}

Generate dump file whole name in GetModuleFileName () ' s directory
Like:f:\reference\project\testminidump\vsproject\build\debug\dump\20161015-110026-8552-9344.dmp
std::string Getdumpfilename ()
{
Char File_path[max_path];
GetModuleFileName (NULL, File_path, MAX_PATH);

std::string path = getdirectory (File_path);

Path + = "dump\\";

std::string File_mark = Getdumpfilemark ();

Path + = File_mark;

return path;
}

Minidump_exception_information Getexpparam (exception_pointers* exception_pointers)
{
Minidump_exception_information Exp_param;
Exp_param. ThreadId = GetCurrentThreadID ();
Exp_param. Exceptionpointers = exception_pointers;
Exp_param. Clientpointers = TRUE;
return exp_param;
}

int Generatedump (exception_pointers* exception_pointers)
{
std::string dump_file_name = Getdumpfilename ();

The "\dump" whole directory
std::string dump_file_dir = getdirectory (dump_file_name);

CreateDirectory (Dump_file_dir.c_str (), NULL);

HANDLE Dump_file_handle = CreateFile (Dump_file_name.c_str (),
generic_read| Generic_write, File_share_write | File_share_read,
0, create_always, 0, 0);

Minidump_exception_information Exp_param =
Getexpparam (exception_pointers);

MiniDumpWriteDump (GetCurrentProcess (), GetCurrentProcessId (),
Dump_file_handle, Minidumpnormal, &exp_param, NULL, and NULL);

return 0;
}

LONG _stdcall Golbalexceptionhandler (exception_pointers* exception_pointers)
{
Generatedump (exception_pointers);
return exception_execute_handler;
}

void Intiializememory ()
{
App_name = new std::string ();
App_version = new std::string ();
}

void Minidumpbegin (const char* app_name, const char* app_version)
{
Intiializememory ();

*minidump::app_name = app_name;
*minidump::app_version = app_version;

SetUnhandledExceptionFilter (Golbalexceptionhandler);
}
}

Using the method, start out in the main function, call: Minidumpbegin function,

2. Use the registration form:

Opendump.bat file:----Writing the Registry

@echo off
echo is enabling dump ...
REG ADD "Hkey_local_machine\software\microsoft\windows\windows Error reporting\localdumps"
REG ADD "hkey_local_machine\software\microsoft\windows\windows Error reporting\localdumps"/V dumpfolder/t REG_EXPAND _SZ/D "C:\CrashDump"/F
REG ADD "hkey_local_machine\software\microsoft\windows\windows Error reporting\localdumps"/V dumptype/t reg_dword/d 2 /F
REG ADD "hkey_local_machine\software\microsoft\windows\windows Error reporting\localdumps"/V dumpcount/t reg_dword/d 10/f
echo Dump is enabled
Pause
@echo on

 

Closedump.bat File---Delete registration form

@echo off
Echo is shutting down dump ...
reg delete "Hkey_local_machine\software\microsoft\windows\windows Error reporting\localdumps"/F
Echo Dump is closed
Pause
@echo on

How to use:

1. Run the Opendump.bat file
2. To open the service

program crashes, c \ will appear:

CrashDump file

3. Debug dump File Reference link 72864694

Open Dump File

Double-clicking to open the generated dump file will open with VS2012 and automatically create a solution with the dump summary information as follows:

Be sure to ensure that 进程名称 the corresponding program path exists locally, and that the corresponding symbol file of the original generated program is .pdb also in the current directory;

Sometimes the dump file program path and local inconsistency from the customer, need to copy the program to the dump information inside the path;

Set Symbols Path

The debug file needs the corresponding symbol file, we need to set the path of the symbol file:

In the top right corner of the Dump information summary, click 设置符号路径 :

Recommended Microsoft 符号服务器 , but the first time the online download will be a bit slow, of course, you can download the symbol set file to a path, and then the symbol path points to the path:



Set the source path

Right-click on the solution at the left 属性 调试源文件 , add the path to the source code, and note that it must be the path to the solution (sln):

Debug Dump File

The preparation is ready, now click on the Dump file summary in the top right corner 使用 仅限本机 进行调试 :

If prompted 无法找到调试信息 , 或者调试信息不匹配 , 无法查找或打开 PDB 文件 , indicates that the original generated program's corresponding .pdb symbol file is not placed in the same directory as the debugger, or that the .pdb symbol file does not match the current version of the program;

The program will reproduce the call stack that was before the crash, as shown in:

Can see that the program has been positioned to the crash before the line of code, very convenient to troubleshoot;

4. When you are finished, restore the registry and run the Closedump.bat file.

5. Delete the crashdump file under C drive.

Windows Server dump File

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.