Debugging, Profiling, Code improvement tools
  • Introduction
  • Chapter1: 追蹤問題
    • 1.1.找出錯誤來源
  • Chapter2: 解決問題
    • 2.1.Check list
      • 2.1.1.確認前後條件
  • Chapter3: 錯誤訊息
    • 3.1.python
      • 'charmap' codec can't decode byte 0x8f in position 17: character maps to <undefined>
  • Chapter4:版本管理工具
    • 4.1.Git
      • 4.1.1.Working tree, Index/Cache, Repository and Object
      • 4.1.2.commit
      • 4.1.3.cherry-pick
      • 4.1.4.rebase
    • 4.2.TortoiseGit
      • 4.2.1.bisect
      • 4.4.2.reflog & reset
      • 4.2.3.blame
  • Chapter5: 除錯工具
    • 5.1.Visual studio
      • 5.1.1.輸出debug訊息
      • 5.1.2.中斷點
      • 5.1.3.載入符號, 檢視堆疊
      • 5.1.4.追蹤點
      • 5.1.5.單步執行程式
      • 5.1.6.日誌
      • 5.1.7.靜態程式分析
    • 5.2. WinDbg
      • 5.2.1.安裝WinDbg
      • 5.2.2.設定project及symbol path
      • 5.2.3.分析.dmp file
    • 5.3.API
      • 5.3.1.核心傾印
  • Chapter6: 效能分析工具
    • 6.1.Introduction
    • 6.2.Windows
      • 6.2.1.效能分析指標
      • 6.2.2.Windows Performance Monitor
      • 6.2.3.Process monitor
      • 6.2.4.Windows Performance Toolkit
    • 6.3.C++ project
      • 6.3.1.SMART BEAR AQ Time
    • 6.4.Python project
      • 6.4.1.cProfile, snakeviz
  • Chapter7: 程式碼優化工具
    • 7.1.Python
      • 7.1.1.vulture
Powered by GitBook
On this page
  • 1.目的
  • 2.專案設定
  • 3.步驟
  • 4.範例程式碼

Was this helpful?

  1. Chapter5: 除錯工具
  2. 5.3.API

5.3.1.核心傾印

Previous5.3.APINextChapter6: 效能分析工具

Last updated 5 years ago

Was this helpful?

1.目的

  • 使用MiniDumpWiteDump產生.dmp file

2.專案設定

  • 範例程式碼修改自, 此範例在SomeFunction()中的pBadPtr的地址被指向0, 這會造成crash, 藉此產生.dmp file

  • 貼上程式碼並對專案做下面設定:

    • 專案Property -> Linker -> input -> Additional Dependencies: 加入Dbghelp.lib

    • 專案Property -> Linker -> Debugging -> Generate Debug Info -> Yes (/DEBUG)

    • 專案Property -> Linker -> Debugging -> Generate Map File -> Yes (/MAP)

3.步驟

  • 1.貼上程式碼並完成專案設定後, Build/Rebuild這個專案, 將會產生exe檔, pdb檔及map檔

  • 2.

  • 3.利用WinDbg進一步

4.範例程式碼

#include "stdafx.h"
#include <Windows.h>
#include <dbghelp.h>
#include <shellapi.h>
#include <shlobj.h>
#include <StrSafe.h>
#include <iostream>
using namespace std;

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());


    wprintf(L"%s", szFileName);

    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 = FALSE;

    bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
        hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL);

    return EXCEPTION_EXECUTE_HANDLER;
}
void SomeFunction()
{
        int *pBadPtr = NULL;
        *pBadPtr = 0;

}

int _tmain(int argc, _TCHAR* argv[])
{
    __try
    {
        SomeFunction();
    }
    __except ( GenerateDump(GetExceptionInformation()))
    {

    }
    return 0;
}
MSDN
將這些編譯中所產生的檔案放到對應的路徑, 並設定WinBbg
分析dmp file