c - How to get the value of stack pointer? (MIPS GCC) -
i trying call stack, reason following code returns wrong stack pointer:
unsigned int stack_pointer = 0; __asm("la $26, %[spaddr]\n\t" "or $27, $0, $sp\n\t" "sw $27, 0($26)\n\t" "nop"::[spaddr] "m" (stack_pointer)); return stack_pointer;
what missing here?
to stack pointer use proper output constraint so:
register unsigned sp asm("29"); asm("" : "=r" (sp));
note mips uses register return address, of course non-leaf functions might store on stack.
to implement backtrace, can use builtins __builtin_return_address
, __builtin_extract_return_addr
described in gcc manual.
also, if glibc available, has backtrace
function, see man backtrace.
Comments
Post a Comment