Debugging exceptions in Cocoa application

I am working on an application with NSTextView. When I insert random bytes into it (say, from a compiled C program), it displays gibberish, as one would expect. However, when I -setShowsControlCharacters: YES, it also crashes and gives the following error several 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 only NSTextView with the same property and it does not have this problem.

My question is, how can I debug my application to find the cause of the error? I do not know where the error came from. I am not familiar with the debugger built into Xcode. If someone could point me in the right direction in terms of how to track such a mistake, I would be very grateful. Thanks.

+4
source share
2 answers

Another set of useful checkpoints to set when your Cocoa debugging application is objc_exception_throw and -[NSException raise] . In 10.5, all exceptions go through objc_exception_throw , but if you are targeting Tiger, you must set a breakpoint on both.

At http://www.cocoadev.com/index.pl?DebuggingTechniques .

+10
source

It is not entirely clear how much you know, therefore I am going to try a very simple approach, please do not be offended.

I assume that NSTextView is in external nib / xib and is not created programmatically.
If so, open your nib / xib in the interface builder and click on the offensive NSTextView element.

Then click Cmd-5 or Tools-> Connection Inspector

Here you can see which Outlets / Actions to look for in the source code.

Most likely, you are the problem - this is the manipulation of the Reference output object or the function Sent action .

Once you have an idea of ​​which method (s) / variable you need to look at, you can open the source code for these parts in Xcode. Then you can set a breakpoint on any line by clicking on this line number on the left side of the editor window.

Click Run β†’ Debugger . A new window will appear, click " Run and Go " on the toolbar of this window. Your application should work as usual until it reaches the breakpoint set by you in the source code. when you hit the break point, you can drag and drop variables into your code in the lower half of the debugger window. The current values ​​of the variables should pop up, making it easy to check.

You can usually get the same information using the Top Right panel of the debugger to check the variable table.

When you are done with this breakpoint, click Continue at the top of the debugger window and your program will execute until the end or the next breakpoint.

This should start with debugging in Xcode. Their different kinds / uses of breakpoints and all sorts of extra fancy things you can do in Xcode. Check out this awesome CocoaHeads video for more information.

Luck,

Brian G.

+4
source

All Articles