Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging an exception in a Cocoa app

I am working on an app with an NSTextView. When I paste random bytes into it (say, from a compiled C program) it displays gibberish, as it should. However, when I -setShowsControlCharacters:YES, the same causes a crash and gives the following error multiple times:

2008-11-22 00:27:22.671 MyAppName[6119:10b] *** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range or index out of bounds

I created a new project with just an NSTextView with the same property and it does not have this problem.

My question is, how can I debug my app to find the cause of the error? I have no idea where the bug originates. I am not familiar with the debugger built in to Xcode. If anyone could point me in the right direction in terms of how to track down such a bug I would be very grateful. Thanks.

like image 503
titaniumdecoy Avatar asked Dec 09 '22 22:12

titaniumdecoy


1 Answers

Another set of useful breakpoints to set when your debugging Cocoa apps are objc_exception_throw and -[NSException raise]. In 10.5, all exceptions travel through objc_exception_throw but if you're targetting Tiger you should set a breakpoint on both.

There are more debugging techniques at http://www.cocoadev.com/index.pl?DebuggingTechniques.

like image 74
Ashley Clark Avatar answered Dec 31 '22 04:12

Ashley Clark