Re: tools for finding a bug?
Re: tools for finding a bug?
- Subject: Re: tools for finding a bug?
- From: publiclook <email@hidden>
- Date: Sat, 22 Feb 2003 12:21:07 -0500
On Saturday, February 22, 2003, at 09:22 AM, Koen van der Drift wrote:
Hi,
The last few days I have been tring to find a bug in my code that
causes a
SIGSEGV (signal 11). Using the console output and setting breakpoints,
I
figured out what line is causing the error:
unsigned i;
unichar buf;
NSString *key;
for ( i = 0; i < [name length]; i++ )
{
buf = [name characterAtIndex:i];
key = [NSString stringWithCharacters:&buf length:1];
if ( [[myDict allKeys] containsObject:key] ) <----- BOOOM
{
// do something
}
}
The first comment is that [[myDict allKeys] containsObject:key] is
incredibly wasteful. You are creating a temporary array just to
determine if it contains an object. The following statement is
equivalent in result and much better in other respecets:
(nil != [myDict objectForKey: key])
The variables name and myDict are initialized in init.
The crash only happens if the user changes the variable 'name' by
typing in
an NSTextView, I change 'name' in the code as follows:
-(void)setName:(NSString *)s
{
[s retain];
[name release];
name = s;
}
If I add an NSLog([massDict description]), I see all the right values,
so
the NSDictionary doesn't seem corrupted.
Sometimes the output in PB is:
MyApp[712] *** -[NSCFString initialize]: selector not recognized
MyApp[712] Exception raised during posting of notification. Ignored.
exception: *** -[NSCFString initialize]: selector not recognized
MyApp has exited due to signal 11 (SIGSEGV)
You main problem is somewhere else in the code. In gdb, set a break
point on -raise.
>break raise
Any time an exception happens anywhere, your break point will be hit
and you can look at the back trace to find out why. By the way,
+initialize is ONLY called by the run-time and it is only called once
per class. You have some trashed memory someplace...
This is helpful info I guess, unfortunately it doesn't tell which
notification caused the error. How do I proceed tracking down this
bug? Are
there any other tools, or debug commands that might be helpful?
thanks,
I don't see the point of your loop at all. You seem to be looking for
dictionary keys composed of single characters taken from a string. You
may want a different data structure such as a set or tree.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.