public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to traceback call stack on MIPS arch?
@ 2008-01-08 19:22 PRC
  2008-01-08 21:25 ` Andrew Haley
  0 siblings, 1 reply; 6+ messages in thread
From: PRC @ 2008-01-08 19:22 UTC (permalink / raw)
  To: gcc-help

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?


PRC
2008/1/8

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to traceback call stack on MIPS arch?
  2008-01-08 19:22 How to traceback call stack on MIPS arch? PRC
@ 2008-01-08 21:25 ` Andrew Haley
  2008-01-09 13:52   ` David Daney
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2008-01-08 21:25 UTC (permalink / raw)
  To: PRC; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to traceback call stack on MIPS arch?
  2008-01-08 21:25 ` Andrew Haley
@ 2008-01-09 13:52   ` David Daney
  2008-01-09 14:08     ` Andrew Haley
  2008-01-10  0:11     ` PRC
  0 siblings, 2 replies; 6+ messages in thread
From: David Daney @ 2008-01-09 13:52 UTC (permalink / raw)
  To: Andrew Haley; +Cc: PRC, gcc-help

Andrew Haley wrote:
> 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.
>
>   
For that to work, you must compile all the code with -fexceptions.

You could also try compiling all the code with -fno-omit-framepointer
and writing your own unwinder.  I posted such an unwinder to
java-patches@gcc.gnu.org several years ago.  Later versions of GCC are
starting to do optimizations in the function prolog that make unwinding
without the unwinder meta-data very difficult.

David Daney

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to traceback call stack on MIPS arch?
  2008-01-09 13:52   ` David Daney
@ 2008-01-09 14:08     ` Andrew Haley
  2008-01-10  0:11     ` PRC
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2008-01-09 14:08 UTC (permalink / raw)
  To: David Daney; +Cc: PRC, gcc-help

David Daney writes:
 > Andrew Haley wrote:
 > > 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.
 > >   
 > For that to work, you must compile all the code with -fexceptions.

Or just -funwind-tables.  Yes, I should have mentioned that.  It's
kinda lame that we break the old way of doing backtraces but don't
compile the minimum unwinder data by default.  Sigh.

 > You could also try compiling all the code with -fno-omit-framepointer
 > and writing your own unwinder.  I posted such an unwinder to
 > java-patches@gcc.gnu.org several years ago.  Later versions of GCC are
 > starting to do optimizations in the function prolog that make unwinding
 > without the unwinder meta-data very difficult.

Right, which as far as I can see is the OP's problem.

Andrew.

-- 
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: How to traceback call stack on MIPS arch?
  2008-01-09 13:52   ` David Daney
  2008-01-09 14:08     ` Andrew Haley
@ 2008-01-10  0:11     ` PRC
  2008-01-11  9:29       ` Ian Lance Taylor
  1 sibling, 1 reply; 6+ messages in thread
From: PRC @ 2008-01-10  0:11 UTC (permalink / raw)
  To: David Daney, Andrew Haley; +Cc: gcc-help

-fno-omit-frame-pointer may be what I want, since the programs are running
in a native embeded system without glibc.
I have read the gcc manual and noticed the option -fomit-frame-pointer. But
the manual says nothing about -fno-omit-frame-pointer. Is it a default 
convention that each -fxxx option has a -fno-xxx counterpart?
----------------------------------------------------------
Andrew Haley wrote:
> 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.
>
>   
For that to work, you must compile all the code with -fexceptions.

You could also try compiling all the code with -fno-omit-framepointer
and writing your own unwinder.  I posted such an unwinder to
java-patches@gcc.gnu.org several years ago.  Later versions of GCC are
starting to do optimizations in the function prolog that make unwinding
without the unwinder meta-data very difficult.

David Daney

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to traceback call stack on MIPS arch?
  2008-01-10  0:11     ` PRC
@ 2008-01-11  9:29       ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2008-01-11  9:29 UTC (permalink / raw)
  To: PRC; +Cc: David Daney, Andrew Haley, gcc-help

"PRC" <panruochen@gmail.com> writes:

> -fno-omit-frame-pointer may be what I want, since the programs are running
> in a native embeded system without glibc.
> I have read the gcc manual and noticed the option -fomit-frame-pointer. But
> the manual says nothing about -fno-omit-frame-pointer. Is it a default 
> convention that each -fxxx option has a -fno-xxx counterpart?

Yes, and this convention is documented.

    Many options have long names starting with `-f' or with `-W'--for
    example, -fmove-loop-invariants, -Wformat and so on.  Most of
    these have both positive and negative forms; the negative form of
    -ffoo would be -fno-foo.  This manual documents only one of these
    two forms, whichever one is not the default.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-10  0:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-08 19:22 How to traceback call stack on MIPS arch? PRC
2008-01-08 21:25 ` Andrew Haley
2008-01-09 13:52   ` David Daney
2008-01-09 14:08     ` Andrew Haley
2008-01-10  0:11     ` PRC
2008-01-11  9:29       ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).