OK, so imagine that my breakpoint in objc_exception_throw
has just triggered. I'm sitting at the debugger prompt, and I want to get some more information about the exception object. Where do I find it?
views:
122answers:
3Check this place out it will tell you how to deal with those errors:
http://www.markj.net/debugging-tip-objc_exception_throw-breakpoint/
It shows you how to add break points and figure out where its happening in you code. That will show you where that thing is.
The exception object is passed in as the first argument to objc_exception_throw
. The syntax to refer to it depends on the calling conventions of the architecture you're running on. If you're debugging on an actual iOS device, the pointer to the object is in register r0
. To print it or send messages to it, use the following simple syntax:
(gdb) po $r0
(gdb) po [$r0 name]
(gdb) po [$r0 reason]
On the iPhone Simulator, all function arguments are passed on the stack, so the syntax is considerably more horrible. The shortest expression I could construct that gets to it is *(id *)($ebp + 8)
. To make things less painful, I suggest using a convenience variable:
(gdb) set $exception = *(id *)($ebp + 8)
(gdb) po $exception
(gdb) po [$exception name]
(gdb) po [$exception reason]
You can also set $exception
automatically whenever the breakpoint is triggered by adding a command list to the objc_exception_throw
breakpoint.
(Note that in all cases I tested, the exception object was also present in the eax
and edx
registers at the time the breakpoint hit. I'm not sure that'll always be the case, though.)