Walking the stack – one more way
January 21, 2008 – 7:52 pmRecently I’ve been trying to move MemTracer from experiment category to something that’s actually usable in real world scenario. It requires more work than I expected, but it’s slowly moving forward. One of the first problems I encountered was StackWalk64 function. It works nicely, but when called very often it can cause noticeable slowdowns. Walking the stack can be done manually by ESP/EBP traversing, but on Windows XP/Vista platforms it’s actually easier to use undocumented RtlCaptureStackBackTrace function. Example:
USHORT (WINAPI *s_pfnCaptureStackBackTrace)(ULONG, ULONG,
PVOID*, PULONG) = 0;
[...]
if (s_pfnCaptureStackBackTrace == 0)
{
const HMODULE hNtDll = ::GetModuleHandle("ntdll.dll");
reinterpret_cast<void*&>(s_pfnCaptureStackBackTrace) =
::GetProcAddress(hNtDll, "RtlCaptureStackBackTrace");
}
numEntries = s_pfnCaptureStackBackTrace(entriesToSkipAtStart,
maxDepth, reinterpret_cast<PVOID*>(&callStack[0]), 0);
It’s perfect for tools like MemTracer, because it’s very lightweight, doesnt care about symbols, it’ll only grab return addresses and more detailed info can be extracted later.Side note: imagine a company sending ~10 people to GDC. How many of them are actual developers? …
4










2 Responses to “Walking the stack – one more way”
And rest are PR guys, right? ;)
By Kurak on Jan 21, 2008
I dunno whether it is temporary issue and whether it concerns other people as well, but on Opera on 1680×1050 resolution side menu overlaps with the content.
By Riddlemaster on Jan 23, 2008