Stack Trace: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
m Bot: Replace deprecated source tag with syntaxhighlight
Line 33:
Note that the above code and GDB backtracing require a NULL %ebp, to know when to stop. Otherwise the traces will run off into garbage. To account for this, set up a NULL stack frame before you jump to your C entry point:
 
<sourcesyntaxhighlight lang="asm">
mov $stack_end, %esp ; Initialize %esp
...
xor %ebp, %ebp ; Set %ebp to NULL
call kmain ; According to calling convention, kmain will save %ebp (=NULL) to the stack
</syntaxhighlight>
</source>
 
With this, stack tracers will see the NULL %ebp as the end of the trace.
Line 46:
This assembly implementation for x86 uses the same algorithm as above and similarly relies on a NULL base pointer to be placed near the top of the stack. Rather than print the contents of the stack, however, it builds an array of addresses which can then be resolved into symbol names.
 
<sourcesyntaxhighlight lang="asm">
; Walks backwards through the call stack and builds a list of return addresses.
; Args:
Line 82:
leave
ret
</syntaxhighlight>
</source>
 
=== Resolving Function Names ===