Windows에서 프로그래밍 방식으로 덤프 파일에서 스택 추적을 얻는 방법
-
22-07-2019 - |
문제
프로그래밍 방식으로 사용자 덤프 파일에서 스택 추적을 검색하고 싶습니다. 알려진 위치 에이 사용자 덤프가 있으며 스택 추적 만 추출하여 일반 텍스트 파일에 넣고 싶습니다. 그렇게 할 수있는 방법이 있습니까?
참고 : 수동으로 할 수 있습니다 - WindBG를 열고 "K"명령을 입력 할 수 있습니다. 그러나 앞에서 언급했듯이 프로그래밍 방식 으로이 작업을 수행하고 싶습니다.
감사
해결책
당신은 확인해야합니다 Windbg dbgeng.dll을 프로그래밍 방식으로 사용하는 방법에 대한 예제가있는 SDK 하위 폴더.
코드 샘플 :
PSTR g_DumpFile;
PSTR g_ImagePath;
PSTR g_SymbolPath;
ULONG64 g_TraceFrom[3];
IDebugClient* g_Client;
IDebugControl* g_Control;
IDebugSymbols* g_Symbols;
void CreateInterfaces(void)
{
HRESULT Status;
// Start things off by getting an initial interface from
// the engine. This can be any engine interface but is
// generally IDebugClient as the client interface is
// where sessions are started.
if ((Status = DebugCreate(__uuidof(IDebugClient),
(void**)&g_Client)) != S_OK)
{
Exit(1, "DebugCreate failed, 0x%X\n", Status);
}
// Query for some other interfaces that we'll need.
if ((Status = g_Client->QueryInterface(__uuidof(IDebugControl),
(void**)&g_Control)) != S_OK ||
(Status = g_Client->QueryInterface(__uuidof(IDebugSymbols),
(void**)&g_Symbols)) != S_OK)
{
Exit(1, "QueryInterface failed, 0x%X\n", Status);
}
}
void
DumpStack(void)
{
HRESULT Status;
PDEBUG_STACK_FRAME Frames = NULL;
int Count = 50;
printf("\nFirst %d frames of the call stack:\n", Count);
if (g_TraceFrom[0] || g_TraceFrom[1] || g_TraceFrom[2])
{
ULONG Filled;
Frames = new DEBUG_STACK_FRAME[Count];
if (Frames == NULL)
{
Exit(1, "Unable to allocate stack frames\n");
}
if ((Status = g_Control->
GetStackTrace(g_TraceFrom[0], g_TraceFrom[1], g_TraceFrom[2],
Frames, Count, &Filled)) != S_OK)
{
Exit(1, "GetStackTrace failed, 0x%X\n", Status);
}
Count = Filled;
}
// Print the call stack.
if ((Status = g_Control->
OutputStackTrace(DEBUG_OUTCTL_ALL_CLIENTS, Frames,
Count, DEBUG_STACK_SOURCE_LINE |
DEBUG_STACK_FRAME_ADDRESSES |
DEBUG_STACK_COLUMN_NAMES |
DEBUG_STACK_FRAME_NUMBERS)) != S_OK)
{
Exit(1, "OutputStackTrace failed, 0x%X\n", Status);
}
delete[] Frames;
}
void __cdecl main(int Argc, __in_ecount(Argc) char** Argv)
{
CreateInterfaces();
ParseCommandLine(Argc, Argv);
ApplyCommandLineArguments();
DumpStack();
Exit(0, NULL);
}
다른 팁
나는 몇 년 전 DDJ에서 Windows와 Unix/Linux와 함께 C/C ++에 스택을 덤프하는 것에 관한 기사를 썼습니다. Cordump를 사용하지는 않지만 스택 프레임을 로그 파일, 내부 오류 또는 OS가 응용 프로그램 결함을 결정할 때 스택 프레임을 기록합니다.
어쩌면 그것은 당신을 도울 것입니다 :
제휴하지 않습니다 StackOverflow