• 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
Re: backtrace() alternative?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: backtrace() alternative?


  • Subject: Re: backtrace() alternative?
  • From: Chris Suter <email@hidden>
  • Date: Tue, 9 Oct 2007 13:42:41 +1000


On 09/10/2007, at 12:27 PM, Rene Limberger wrote:

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?

That code should work on a PowerPC machine, not Intel. For Intel machines the return address is next to the frame pointer so it should be + 1 rather than + 2 on the saved_pc line.


- Chris

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: Rene Limberger <email@hidden>
References: 
 >backtrace() alternative? (From: Rene Limberger <email@hidden>)

  • Prev by Date: Re: backtrace() alternative?
  • Next by Date: Re: backtrace() alternative?
  • Previous by thread: Re: backtrace() alternative?
  • Next by thread: Re: backtrace() alternative?
  • Index(es):
    • Date
    • Thread