How can I change the preferences in Xcode so that it highlights the exact location of an error like other programming environments instead of simply returning SIGABRT? Or is this not possible?
Xcode should already stop and show where execution is when a signal like SIGABRT occurs. (It does for me, without any special configuration).
a NSInvalidArgumentException occurs Xcode only highlights main.m
It's not signals you need to catch for that, it's exceptions. Go to the breakpoint navigator and add an exception breakpoint.
Related
I don't know what has changed on my setup, but it used to be that when my (Swift) code crashed, the debugger would show the offending line of source code.
Now no matter what the problem is, the debugger only highlights the line in AppDelegate.swift where UIApplicationMain is defined.
I can tell by putting in print statements more or less where in the code the problem arose, however... what's the point of having a debugger if it never conveys any information and I just have to do everything "old school" with print statements -- especially if there are asynchronous processes going on in which the print statement isn't necessary a reliable indicator of where the crash occured?
I've seen threads from years ago that talk about going into "Preferences -> Behaviors" and modifying what gets shown when the code exits unexpectedly. But (a) I never needed this in the past, and more importantly (b) this seems to have no effect, i.e. the debugger is still just quitting on main.
Is there a good way to get the old, specific, debugging behavior back?
I'm currently running Xcode 7.0, but this behavior occurs with 7-GM Seed, and even now when I go back to try 7 beta 5 and beta 6, which used to work.
Go to the Debug Navigator (cmd-7), click the plus button in the bottom and select Add Exception Breakpoint. This will break at the actual line where the problem happened.
In the exception breakpoints detail editor create debugger command action and in the text box enter po $arg1. This will show the error message in the debug console.
The previous answer was on the right track, but this answer is more relevant today:
On Xcode 9.2 with Swift 4, do this:
Use Command-8 to bring up the Debug Navigator.
Click the + in the lower left
Select Swift Error Breakpoint
That's it! :)
It's been bothering me since Xcode 6, that whenever I set 'All Exceptions' without any other breakpoints, Xcode would stop at start when I init a UILabel view wrapper in RootVC.
If I try to remove the causing line, another "random" line would trigger it again. Thoughts on what caused the exception?
This breakpoint comes from an exception that was thrown by TFileDescriptorContext. All Exceptions halts also on C++ exceptions.
It gives you a good indication where the problem comes from. Take a look if all fonts that are listed in Info.plist are part of your application bundle.
"Normally" you are not interested in C++ exceptions when you are in Objective-C, so feel free to ignore them.
Edit: This problem has been discussed several times here on SO. Updating when I can find the posts again which might give you even a deeper insight.
Where XCode generate error for application crash ?
I'm crazyng ! My application when open second file xib with webview then it crash. But I don't know why ? how can i Know where is error ?
You need to learn how to use the debugger in Xcode.
Run your app under the debugger then instead if simply getting a stack trace Xcode will stop at the line the fault occurs and show you your code and variables. You can then examine the contents of your variables, the call tree, etc. and hunt down the problem.
Once you know the general area of the problem you can place breakpoints to pause your application before the problem occurs and check whether your variables have the values expected etc. Then you can run till the next breakpoint, or step through your code a line at a time.
You can add code, such as NSAssert's and NSLog's to your app to check progress and display information without stopping the run, etc.
It's a process, and some problems will be harder to track down, but you'll get quicker at it with practice.
The Xcode documentation will tell you all about the debugger.
HTH
I had a xib file with an old outlet connected. That would crash and set a breakpoint on the line pushing the view controller with :
Catchpoint 2 (throw)Pending breakpoint 1 - "objc_exception_throw" resolved
Not very helpful, I remember in XCode 3 I had something like "an outlet is not connected"
How do I get that back ?
edit : if I check "automatically continue after evaluating actions", I get this message :
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<OrderController 0x7942760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key table.'
*** First throw call stack:
(0x16e1052 0x2182d0a 0x16e0f11 0x4cb032 0x43cf7b 0x43ceeb 0x457d60 0x99991a 0x16e2e1a 0x164c821 0x99846e 0x83fe2c 0x8403a9 0x8405cb 0x840941 0x85247d 0x85266f 0x85293b 0x8533df 0x853986 0xcf67dbd 0x8535a4 0x3a3da 0x841fbf 0x8422d4 0x8425d7 0x842785 0x85c0a5 0x842730 0x78b5ea 0x16b59ce 0x164c670 0x16184f6 0x1617db4 0x1617ccb 0x18f7879 0x18f793e 0x77aa9b 0x276d 0x1fd5)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
(gdb)
which is better than nother, but the breakpoint stops on main.m ! Here is the current setup of my breakpoint
Mystery solved. At least for me, hitting 'continue' a couple of times allowed the error to be printed to the console.
The issue (in this case) was having a couple of other custom breakpoints set (objc_exception_throw, -[NSException raise]).
Enabling "automatically continue after evaluating" for BOTH allowed the process to be killed without manual intervention, somewhere around which time the detailed error message was printed to the console.
Hope this helps.
If you have multiple projects, make sure that the breakpoint is active for the correct project. I recommend using a Xcode 4 workspace in this case and assign the global exceptions breakpoint to the workspace. You can do that by right-clicking the breakpoint in the Breakpoints Navigator pane and select "Move Breakpoint to…"
I've set up an Exception Breakpoint in XCode 4. Will it break for exceptions that originate within the Cocoa Touch framework AND are handled by the framework? I.E. Will the debugger stop for all exceptions, even if they are a natural part of the framework and handled by it internally?
My debugger keeps halting for a seemingly harmless exception from deep down in the framework and I need to know if I can safely ignore it.
If you're like me, there are times you want to ignore particular exceptions (like Apple's intermittently buggy CMMThrowExceptionOnError, which Apple neglects to provide any feedback to my bug reports for months)
So, my not-very-efficient solution is to add the following breakpoint instead of 'Add C++ Exception Breakpoint...'
from gdb command line, enter
break __cxa_throw
Then, in the XCode breakpoints editor, add the following 'Debugger Command' to this breakpoint. By substituting the offending address of $eip, you can exclude individual
exceptions from your breakpoint.
silent
# go up one stack frame silently
up-silently
# in my particular app, address of CMMThrowExceptionOnError is 0x9704d22e
if ( $eip == 0x9704d22e )
# echo gdb ignore exception\n
#print $eip
cont
end
If you can devise a better solution which doesn't incur the overhead of a debugger script, please let me know.
The exception breakpoint is just that: a breakpoint for exceptions. This includes those within the framework. It doesn't matter whose exception it is - if it's raised, it should break.
Just a short note on LLDB used by defat in Xcode 4.3
Commands have a different syntax.
set $eip = xxxx
is now
reg write tip 0x006373ec
a full map of commands is available at http://lldb.llvm.org/lldb-gdb.html