Re: How to get the name of a method at runtime?

2008-03-10 Thread John Stiles
My experience with dladdr has been that it returns junk at least half of the time. IIRC, Tiger was worse than Leopard, but neither is as accurate as NSTask'ing out to atos (which basically works perfectly, albeit slow as dirt). I've got an open radar on it. stephen joseph butler wrote: On

How to get the name of a method at runtime?

2008-03-09 Thread Stuart Malin
I'd like to have a method determine the name of the method that invoked it -- as an NSString. For example - (void) method1 { [someObject method2]; } - (void) method2 { // here, I'd like to be able to find the name of the caller // in this example, that would be

Re: How to get the name of a method at runtime?

2008-03-09 Thread Jonathan Dann
I think maybe you missed the existence of _cmd. Both self (this object) and _cmd (this selector) are passed as implicit arguments to every Objective-C method. You can also call __func__ from within a method call, I use this often, NSLog(@%p %s,self,__func__); // Thanks James Bucanek Jon

Re: How to get the name of a method at runtime?

2008-03-09 Thread stephen joseph butler
On Sun, Mar 9, 2008 at 4:45 PM, Tony Becker [EMAIL PROTECTED] wrote: If you're on Leopard, there is a new backtrace(3) call. If you're on Tiger, it's a little more complex... You can use the compiler function (long)__builtin_return_address(0) to find the

Re: How to get the name of a method at runtime?

2008-03-09 Thread Bill Bumgarner
On Mar 9, 2008, at 2:59 PM, stephen joseph butler wrote: On Sun, Mar 9, 2008 at 4:45 PM, Tony Becker [EMAIL PROTECTED] wrote: If you're on Leopard, there is a new backtrace(3) call. If you're on Tiger, it's a little more complex... You can use the compiler function

Re: How to get the name of a method at runtime?

2008-03-09 Thread Tony Becker
Agreed, I forgot to add that warning. I was using it to put fingerprints against alloc calls, retain/release cycles, and some other methods so I could track down memory leaks and some less then compliant code in debug builds. It should not end up in release builds. On Mar 9, 2008, at 6:06

Re: How to get the name of a method at runtime?

2008-03-09 Thread Jean-Daniel Dupas
ObjectAlloc and other Apple developement tools already record memory calls (retain, release, alloc, ...) full trace. You really doesn't need to reinvent the wheel to find leaks. Le 9 mars 08 à 23:17, Tony Becker a écrit : Agreed, I forgot to add that warning. I was using it to put

Re: How to get the name of a method at runtime?

2008-03-09 Thread Stuart Malin
Interesting approach, Tony. However, __builtin_return_address isn't an object, so stringWithFormat throws an exception when given the %@ token. It should be %u (or %U ?? - I'm not sure of the difference). So, just so I could step through the code in the debugger, I wrote: int