7

I used to get exception details from apps running in the simulator like so:

po $eax

Ever since I upgraded to XCode 4.6 it's stopped working; I always get this error:

error: warning: couldn't get object pointer (substituting NULL):
Couldn't find '_cmd' with appropriate type in scope
Couldn't materialize struct: Couldn't read eax (materialize)
Errored out in Execute, couldn't PrepareToExecuteJITExpression

I've seen people recommend using this:

register read eax

But that gives me this error:

eax          = error: unavailable

How do I get exception details in XCode 4.6?

Simon
  • 25,468
  • 44
  • 152
  • 266

3 Answers3

26

If you break on objc_exception_throw the stack frame selected is the last frame in your code, before calling any libraries that might have thrown the exception. At that point lldb doesn't let you access some of the registers (see this answer for a possible explanation.

To get the exception details you have to select the objc_exception_throw stack frame:

Select the objc_exception_throw stack frame

Now po $eax (po $rax if you are running on OS X 64 bit, po $r0 on iPhone/iPad, po $x0 on arm64) should give you the exception details.

Community
  • 1
  • 1
Sebastian
  • 7,670
  • 5
  • 38
  • 50
  • Glad I could help. Just to clarify: Breaking on `objc_exception_throw` **is** an exception breakpoint. – Sebastian Mar 10 '13 at 23:34
  • It's a breakpoint, and it breaks on exceptions, but it's not the XCode feature whose name is 'Exception Breakpoint'. – Simon Mar 12 '13 at 07:31
  • So what is the difference? – Sebastian Mar 12 '13 at 11:20
  • I believe that the XCode one will catch other sorts of exception (e.g. C++). My question was just about objc ones, though. – Simon Mar 12 '13 at 11:22
  • You're right about C++. If you're setting it to Objective-C, on through, it breaks on `objc_exception_throw`. The only difference to setting a symbolic breakpoint on `objc_exception_throw` is that in the latter case `objc_exception_throw` is selected on the call stack trace. (At least I don't know of any other difference) – Sebastian Mar 12 '13 at 11:25
  • 1
    I've set up a breakpoint on `objc_exception_throw` and added a couple of actions- `po [$rax name]` and `po [$rax reason]`. Big timesaver! – joerick Sep 20 '13 at 19:09
  • So we have $rax for 64-bit OSX, but this doesn't seem to work on 64-bit iOS devices. Any update on this for 64-bit iPad/iPhone live devices? Is "po $x0" the correct debugger command? – kurtzmarc Jan 12 '14 at 19:37
  • 1
    when I tried this (Mavericks, Xcode 5.1, Mac project) it was $rd1. – Peter N Lewis Apr 30 '14 at 06:36
  • @PeterNLewis: You probably mean `$rdi`, which for me holds the same value as `$rax` when stopped at an exception breakpoint. – Sebastian Apr 30 '14 at 23:11
  • Yes, sorry, $rdi - but $rax did not work for me, thats when I went through the other registered. Might have just been me, but I figured its worth noting in case someone else tries and this helps. – Peter N Lewis May 01 '14 at 06:00
  • `error: Couldn't materialize struct: couldn't read the value of register r0 Errored out in Execute, couldn't PrepareToExecuteJITExpression` – rohan-patel Jun 26 '14 at 15:39
  • 1
    @simon you also can’t add conditions to exception breakpoints, but you can to symbolic breakpoints, which is useful if you want to ignore certain types of exceptions by string matching the message or class. – Zev Eisenberg Dec 24 '14 at 16:47
3

I don't have anything to add, just use this awesome guide that helps you setup exception breakpoint with action (script) that prints exception description in console.

DanSkeel
  • 3,853
  • 35
  • 54
-3

Go to :

Product -> Scheme -> Edit Scheme -> Run on the left -> diagnostics tab 

and then enable zombies

fizampou
  • 717
  • 2
  • 10
  • 29