• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
backtrace() alternative?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

backtrace() alternative?


  • Subject: backtrace() alternative?
  • From: Rene Limberger <email@hidden>
  • Date: Mon, 8 Oct 2007 19:27:43 -0700

I am trying to port a linux program to OSX. As part of the OS- specific portion of this porting, i noticed that OSX (BSD) does not support backtrace and has no execinfo.h.

I have tried the following code (found somewhere on the net) as an alternative:

  void **fp = (void **) __builtin_frame_address (0);
  void *saved_pc = __builtin_return_address (0);
  void *saved_fp = __builtin_frame_address (1);
  int depth = 0;

  printf ("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
  fp = saved_fp;
  while (fp != NULL)
    {
      saved_fp = *fp;
      fp = saved_fp;
      if (*fp == NULL)
        break;
      saved_pc = *(fp + 2);
      printf ("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp);
    }

while this gives me *something*, it doesn't seem to resolve the function names past the 1st level, never mind line numbers in the code (i run this on a debug version):

#0 darwinGetBacktrace() in mylib.dylib, fp = 0xb0080118, pc = 0x110c017
#1 ? in ?, fp = 0xb0080438, pc = 0x5096e0
#2 ? in ?, fp = 0xb0080458, pc = 0x5096e0
#3 ? in ?, fp = 0xb0080498, pc = 0xb00804b0
#4 ? in ?, fp = 0xb00804c8, pc = 0x505c80
#5 ? in ?, fp = 0xb00804e8, pc = 0x505c80
#6 ? in ?, fp = 0xb0080558, pc = 0xb0080724
#7 ? in ?, fp = 0xb0080b88, pc = 0xb0080c78
#8 ? in ?, fp = 0xb0080bb8, pc = 0xb0080c78
#9 ? in ?, fp = 0xb0080dd8, pc = 0xb0080f04
#10 ? in ?, fp = 0xb0080e98, pc = 0xb0080f04
#11 ? in ?, fp = 0xb0080f38, pc = 0xbfffeed4

doe anyone on this list have a better backtrace replacement?

thanks,
-r


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: backtrace() alternative?
      • From: Chris Suter <email@hidden>
    • Re: backtrace() alternative?
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Am I Being Debugged?
  • Next by Date: Re: Am I Being Debugged?
  • Previous by thread: Re: Regexp search and replace spanning multiple lines
  • Next by thread: Re: backtrace() alternative?
  • Index(es):
    • Date
    • Thread