This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to traceback call stack on MIPS arch?
- From: Andrew Haley <aph at redhat dot com>
- To: "PRC" <panruochen at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 8 Jan 2008 10:52:17 +0000
- Subject: Re: How to traceback call stack on MIPS arch?
- References: <200801081007106802280@gmail.com>
PRC writes:
> Gcc saves the frame pointer to fp(s8) register at the beginning of
> each function if compiling source with -O0. But it won't do so if
> compiling source with -O2. Without frame pointers, can I trace back
> call stacks in current function context? Or is there any option
> which forces gcc to save frame pointers for MIPS arch?
You need to use the unwinder.
#include <unwind.h>
#include <stdio.h>
static _Unwind_Reason_Code
backtrace_helper (struct _Unwind_Context *ctx, void *a)
{
void *ip = (void*)_Unwind_GetIP (ctx);
fprintf (stdout, " %p\n", ip);
return _URC_NO_REASON;
}
void
print_backtrace (void)
{
_Unwind_Backtrace (backtrace_helper, NULL);
}
int
main (int argc, char **argv)
{
print_backtrace ();
return 0;
}
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903