我需要从C++应用程序获取堆栈跟踪,并将其序列化为字符串,以便稍后解析。在Windows上,我听说唯一可用的API是StackWalk64,但它似乎不被支持。
在Windows Store应用程序中,如何从C++获取堆栈跟踪?
我需要从C++应用程序获取堆栈跟踪,并将其序列化为字符串,以便稍后解析。在Windows上,我听说唯一可用的API是StackWalk64,但它似乎不被支持。
在Windows Store应用程序中,如何从C++获取堆栈跟踪?
FINLINE static DWORD GetCallerFrameNum(int index) {
#if defined(_DEBUG) && defined(_MSC_VER) && defined(_M_IX86)
DWORD caller = 0;
__asm
{
mov ebx, ebp
mov ecx, index
inc ecx
xor eax, eax
StackTrace_getCaller_next :
mov eax, [ebx + 4]
mov ebx, [ebx]
dec ecx
jnz StackTrace_getCaller_next
mov caller, eax
}
return caller;
#else
return 0;
#endif
}
template<class T>
void RecordStackTrace(T& vecOut) {
vecOut.clear();
vecOut.reserve(32);
for (INT iInitLevel = 1; iInitLevel < 32; ++iInitLevel) {
DWORD dwFrameNum = GetCallerFrameNum(iInitLevel);
if (!dwFrameNum)
return;
vecOut.push_back(dwFrameNum);
}
}