public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: "PRC" <panruochen@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: How to traceback call stack on MIPS arch?
Date: Tue, 08 Jan 2008 21:25:00 -0000	[thread overview]
Message-ID: <18307.21985.888303.875264@zebedee.pink> (raw)
In-Reply-To: <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

  reply	other threads:[~2008-01-08 10:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-08 19:22 PRC
2008-01-08 21:25 ` Andrew Haley [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18307.21985.888303.875264@zebedee.pink \
    --to=aph@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=panruochen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).