Re: backtrace() alternative?
Re: backtrace() alternative?
- Subject: Re: backtrace() alternative?
- From: Rene Limberger <email@hidden>
- Date: Mon, 8 Oct 2007 21:30:23 -0700
Thanks,
that get's me a bit further. now i am getting:
#0 ? in ?, fp = 0xb0080118, pc = 0xffffffff
#1 C() in mylib.dylib, fp = 0xb0080438, pc = 0x10899f2
#2 B() in mylib.dylib, fp = 0xb0080458, pc = 0x1046798
#3 A() in mylib.dylib, fp = 0xb0080498, pc = 0x1079841
...
#10 some_func() in mylib.dylib, fp = 0xb0080e98, pc = 0x1010c4c
#11 thread_create_running() in /usr/lib/libSystem.B.dylib, fp =
0xb0080f38, pc = 0x90024227
****
that is a good start. however, i am still unable to get the line
numbers, considering that this is a debug build. glibc's backtrace()
gives line numbers for each entry. anyone have any suggestions on how
to lookup the debug info of the symbols?
thanks for the help!
-r
On Oct 8, 2007, at 8:42 PM, Chris Suter wrote:
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
_______________________________________________
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