Stack Trace: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
→‎Walking the stack: Add instructions for NULL stack frame
Line 34:
}
</source>
 
Note that the above code requires a NULL return address, and GDB backtracing requires 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:
 
<source lang="asm">
mov $stack_end, %esp ; Initialize %esp
...
xor %ebp, %ebp ; Set %ebp to NULL
push %ebp ; Push a NULL return address to the stack
jmp kmain ; According to calling convention, kmain will save %ebp (=NULL) to the stack
</source>
 
With this, stack tracers will see the NULL %ebp and/or return address as the end of the trace. You can use call in place of push/jmp, but your tracer will need to check for a NULL %ebp, rather than a NULL return address.
 
=== Resolving Function Names ===