• c++ print stacktrace


    c++ stack print stack trace debug utility
    //z 2014-06-30 12:40:28 L.184'40772 BG57IV3@XCL T1809462551.K.F1586050276[T34,L813,R24,V564] is2120
    #include <DbgHelp.h>
    #pragma comment(lib, "dbghelp.lib")
    
    void printStack(void)
    {
    	char cBuff[1024] = {0};
    	unsigned int   i;
    	void         * stack[128];
    	unsigned short frames;
    	SYMBOL_INFO  * symbol;
    	HANDLE         process;
    
    	process = GetCurrentProcess();
    
    	SymInitialize(process, NULL, TRUE);
    
    	frames = CaptureStackBackTrace(0, 128, stack, NULL);
    	symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
    	symbol->MaxNameLen = 255;
    	symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
    
    	OutputDebugString(_T("##########################################################################
    "));
    	for (i = 0; i < frames; i++)
    	{
    		SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
    		sprintf_s(cBuff,1024,("%i: %s - 0x%0X
    "),frames - i - 1, symbol->Name, symbol->Address);
    		OutputDebugStringA(cBuff);
    	}
    	OutputDebugString(_T("--------------------------------------------------------------------
    "));
    
    	free(symbol);
    }
    //z is2120 2014-06-30 12:40:28 L.184'40772 BG57IV3@XCL T1809462551.K.F1586050276[T34,L813,R24,V564]



    @IS2120#CNBLOGS.T2169364049[T1,L65,R1,V259]:备忘
    $ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $
  • 相关阅读:
    模板方法模式
    结构型模式
    组合模式
    享元模式
    [STL离散化]Skyscrapers的lower_bound系列
    [水]浙大校赛补题
    [数]来自亮亮OJ的五道数学题
    [数]被数学淹没不知所措
    [tour]2019HUST onsite签到
    [树组BIT]训练两题重新理解ver.
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745649.html
Copyright © 2020-2023  润新知