Extremely Useful Debugging
More likely than not, your application will have crashed at some point in its development cycle. And you will have seen a cryptic message like this on the console.
2009-08-19 13:45:19.059 TestApp[3905:20b] Stack: ( 2478641131, 2426342971, 2478670314, 2478663660, 2478663858, 92386, 816691521, 816216343, 816148479, 816144864, 827743722, 827753484, 2478142405, 2478144168, 827745792, 827745989, 816114848, 816160924, 9656, 9510 )
The problem is that you have no idea where in the code the crash is happening. Java’s stack trace is very descriptive, with function names and line numbers. This is also possible in XCode, but you have to take an extra step.
Run your iPhone application and then wait for it to crash, displaying the stack trace as above. The program will have paused at this point. If you go down to the console, you’ll see a prompt that says (gdb), where you can type in gdb commands.
Look at the stack trace above, and try to find a small number somewhere in the middle of the stack. This is likely where your program crashed. In the example above, this number is 92386. Once you have identified this number, you can now identify more helpful information about the crash.
Issuing the command: info symbol 92386
Will give you something like this:
-[MainViewController touchesEnded:withEvent:] + 164 in section LC_SEGMENT.__TEXT.__text of /Users/Min/Library/Application Support/iPhone Simulator/User/Applications/877EB45A-AB6B-4CD5-AA43-C7B0F2C98F7B/TestApp.app/TestApp
Issuing the command: info line *92386
Will you give something like this:
Line 416 of “/Users/Min/Documents/Projects/TestApp/Classes/MainViewController.m” starts at address 0×168b5 <-[MainViewController touchesEnded:withEvent:]+119> and ends at 0×16985 <-[MainViewController touchesEnded:withEvent:]+327>
So there you have it. You now know that the crash took place in the [MainViewController touchedEnd:withEvent:] message on line 416.
If you enjoyed this post, make sure you subscribe to my RSS feed!