Stack Trace: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
New page: The article Stack shows the layout of a stack and mentions the usefulness of a stack trace in debugging. Often a stack trace is written in assembly as it involves finding the current ...
 
No edit summary
Line 4:
 
<pre>
void Debug::TraceStackTrace(unsigned int MaxFrames)
 
{
// Stack contains:
// Second function argument
// First function argument (MaxFrames)
// Return address in calling function
// ebp of calling function (pointed to by current ebp)
unsigned int * ebp = &MaxFrames - 2;
Trace("Stack trace:\n");
for(unsigned int frame = 0; frame < MaxFrames; ++frame)
{
unsigned int ip = ebp[1];
if(ip == 0)
// No caller on stack
break;
// Unwind to previous stack frame
ebp = reinterpret_cast<unsigned int *>(ebp[0]);
unsigned int * arguments = &ebp[2];
Trace(" 0x{0:16} \n", ip);
}
}
</pre>