Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode exception breakpoint doesn't print details of the exception being thrown

SUMMARY

When I set an exception breakpoint, I don't get the exception message. How do I get the exception message? I already know how to get the stack trace, but that doesn't include the exception message.

DETAILS

In the past I developed iOS Apps with Xcode and when there was a problem, I'd get an error/exception. The exception would often have a message like "can't dereference null" or whatever.

Now, using Xcode 4.6.x for the past several weeks I've never gotten an exception message. I'll often get a SIGABRT. I put in the break on exception breakpoint and it will break there, but it's off in some assembly within the iOS SDK and I never get a message.

In fact, I can't remember the last time I saw anything show up in the debugger console.

Did exception info dissappear with the migration to LLVM?

It's very frustrating to have my app just crash in the SDK without knowing why. I check the last function to make sure things are set up correctly (objects allocated, etc) and they are which means I'm left with no clues.

Is it possibly a build setting held over from the past is somehow turning off exception messages?

Please reopen question. It now has an answer!

In the comments an excellent answer has been given. This should be promoted to full answer, and so I can mark the question answered and others who have this common issue can find it. In order for that to happen, the question needs to be reopened! (I'll delete this plea after that happens.)

like image 258
nirvana Avatar asked Jun 21 '13 15:06

nirvana


2 Answers

I will update Jeff's answer here:

To have both the line causing the exception highlighted (and not UIApplicationMain() in main.m) AND to see the reason for the exception (e.g., "error: A fetch request must have an entity."), do this:

  • In the Breakpoint navigator:
    1. Add (+), Add Exception Breakpoint
    2. Select the new breakpoint, Control-Click, Edit Breakpoint
    3. Add Action
    4. Enter: po $arg1

The relevant part of the stack trace will be in the nagivator area.

This seems to still work in Xcode 9

Here is my addition for use with Xcode 6 and below.

  1. Enter: po (NSException*) $eax

In Xcode 6 you must explicitly provide the object type because it is no longer inferred.

like image 67
ucangetit Avatar answered Oct 03 '22 15:10

ucangetit


For Xcode 7-9 (based off Jeff's answer):

In the Breakpoint navigator:

  1. Add (+), Add Exception Breakpoint
  2. Select the new breakpoint, Control-Click, Edit Breakpoint
  3. Add Action
  4. Enter: po $arg1
like image 40
jcady Avatar answered Oct 03 '22 14:10

jcady