On 20.10.2010, at 07:16, Sandro Noël wrote:
> How would i go about adding a stack trace to that nsLog like this.
> #define ENTERING() NSLog(@"[%@ %s]-Called By :%@", [self class], _cmd, caller)
> using this code.
I don't know how you can get the actual calling object (I guess you'd have to go "up" one stack frame and look at the "self" parameter there -- if the calling function is a method, and not just a plain function -- but don't know the assembler magic to do that).
To get a backtracke, you could throw an NSException and catch it immediately. An NSException contains a stack backtrace. Alternately, you could set a breakpoint on the method, and then add an action to that breakpoint that is a GDB command. The GDB command "bt" gives you a backtrace in the console. If you set the breakpoint to immediately continue after it's hit, that will give you backtraces all over the console.
There are also some low-level C functions to get a stack backtrace, but they only give you the function addresses, and while I've found ways to turn those into function names, I haven't found one yet that figures out the METHOD name to go with a function (i.e. an IMP). Probably there's nothing out there because you could theoretically associate one IMP with several SELs, and then it wouldn't know which one was really called unless you use code that's aware of ObjC and looks at the hidden _cmd parameter *before* the stack is unwound.
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden