2

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.

sh37211
  • 1,411
  • 1
  • 17
  • 39

2 Answers2

4

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.

MirekE
  • 11,515
  • 5
  • 35
  • 28
  • Ok, thanks, actually I already tried setting "All Exceptions" as a Breakpoint --- using the Breakpoint Navigator (cmd-7), btw --- and this didn't change anything, apart from a "Breakpoint 1.2" bar in green at the same line of code ("UIApplicationMain" definition) where it would otherwise show "EXC_BAD_ACCESS" in red. Adding the "po $arg1" generates the following number as output in the console: "140614316631224". What does one do with that number? – sh37211 Sep 28 '15 at 01:12
  • In my environment with Xcode 7.1 b2 (and in the past with older) it gives the results I described in my answer. If it still gives you a breakpoint in the AppDelegate and a cryptic error message "140614316631224", the chances are that the particular error you are dealing with right now is not in your code. – MirekE Sep 28 '15 at 01:47
  • 1
    Thanks for the cmd-7 hint, fixed. – MirekE Sep 28 '15 at 02:20
  • The crashing issue I'm having itself seems to be involved in trying to restore user data from NSUserDefaults when in iOS 9. If I swap iOS 9 for iOS 8.4, the problem goes away. But since I'd like the app to work in iOS 9 as well, I WOULD like to know what the specific problem is, and thus my hope that the debugger can give more information. – sh37211 Sep 28 '15 at 02:56
0

The previous answer was on the right track, but this answer is more relevant today:

On Xcode 9.2 with Swift 4, do this:

  1. Use Command-8 to bring up the Debug Navigator.
  2. Click the + in the lower left
  3. Select Swift Error Breakpoint

That's it! :)

drewster
  • 5,460
  • 5
  • 40
  • 50