Re: Setting conditional breakpoint on Cocoa method?
Re: Setting conditional breakpoint on Cocoa method?
- Subject: Re: Setting conditional breakpoint on Cocoa method?
- From: "Chris Suter" <email@hidden>
- Date: Tue, 29 Jul 2008 12:01:49 +1000
Hi Graham,
On Mon, Jul 28, 2008 at 5:02 PM, Graham Cox <email@hidden> wrote:
> Once in a blue moon, I get a console message that a nil string was passed
> to [NSConcreteAttributedString initWithString:] I'd like to find out where
> this is coming from by setting a breakpoint there, but only for a nil
> string. Adding the breakpoint as a symbol to the symbolic breakpoints works,
> but I can't set the condition (e.g. aString == nil), since the parameter's
> name isn't available.
>
> What can I do, since this method is called hundreds of times in the normal
> course of things, so just having an unconditional breakpoint isn't very
> useful. Can I specify a register somehow?
I realise that you used GDB to solve this problem but another way that you
can solve these kinds of problems is to use method_exchangeImplementations.
It's slightly tricky with NSConcreteAttributedString because it's not
publicly declared anywhere but I believe it's still possible (albeit with a
couple of compiler warnings):
#include <Foundation/Foundation.h>
#include <objc/runtime.h>
@class NSConcreteAttributedString;
@implementation NSAttributedString (Override)
- (id)myInitWithString:(NSString *)string
{
if (!string)
NSLog (@"nil string");
return [self myInitWithString:string];
}
@end
int main ()
{
[[NSAutoreleasePool alloc] init];
Method m1 = class_getInstanceMethod ([NSConcreteAttributedString class],
@selector (myInitWithString:));
Method m2 = class_getInstanceMethod ([NSConcreteAttributedString class],
@selector (initWithString:));
method_exchangeImplementations (m1, m2);
[[NSAttributedString alloc] initWithString:nil];
return 0;
}
Another thing that you could have done is have a look at the disassembly for
-[NSConcreteAttributedString initWithString:]. The test for a nil parameter
is obviously going to be early on and the call to a function called
_nilArgumentWarning suggests a likely place for a breakpoint.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden