backtrace() alternative?
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