What worked for me is asm code as below. This only works on x86 platform, so it is usefull only during debugging on emulator. Returned frame pointers can be used in dissassembly window to jump into source code. I think it should be possible to use map file to get exact source code location.
I use this code to find memory leaks, combined with crtdbg it works very well in very large application with lots of allocations. VS 2013 memory profiler could handle at most 1 minute of data recording.
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);
}
}