![]() ![]() So, continuing after the breakpoint will still result in iOS throwing the exception. The array index and the increment are on the same line of code. Rerun the application, and when you force the error, it will stop before iOS throws the exception. ![]() Next, double-click next to the offending line in the source code to bring up a breakpoint dialog popup.Īdd a condition for the breakpoint counter > 3. The application should have crashed sooner than it did.īut what if the problem was more difficult to isolate? Let’s add one more breakpoint and step through the application again. ![]() If you look down in the debug window in Xcode, you can see that counter somehow made it to a value of five when the array is only four elements long. We’re incrementing the array index without checking bounds. The problem is clear from viewing the highlighted line. Just as you might expect from the Raygun error report, the code references an array. The debugger stopped when the application generated the exception and highlighted the line of code that is responsible. Now, rerun the application and force the error. Step 5: Run the application with breakpoint Next, click anywhere to dismiss the popup and accept the defaults. This will take us to where the problem occurs. The default is to break on both C++ and Objective C exceptions and to stop the debugger where they are thrown. Xcode brings up the breakpoint navigator on the left, and a popup will appear. So, go to the Debug menu, select Breakpoints and Create Exception Breakpoint. Now, let’s use Xcode to catch the exception and discover where it’s coming from. Raygun already told us that the application has an uncaught exception, so we haven’t learned anything new about the bug yet. We’re going to control it from the GUI (Graphical User Interface).įinally, click the stop button, next to run, to stop the debug session. Down at the bottom of Xcode lldb’s command line interface is available. Xcode shows us that a SIGABRT was thrown inside main. In the editor pane, Xcode highlights that function in main.m. Xcode highlights main in thread #1 since uncaught exceptions “bubble up” to that location in the application. On the left-hand side, the debug navigator displays the application threads. Next, click the iOS app’s button until the application throws the exception and the debugger comes up in Xcode. After the build completes, the application will start in the simulator. Make sure that you have Run selected on the left-hand side, and debug build enabled on the right. We want to be sure we run a debug build, so start by holding the option key and clicking the run icon on the upper left-hand side of Xcode. Let’s start with replicating the error in the simulator. ![]() So, you can debug your application on your development desktop. You can install and run applications with a single click, and the environment has integrated support for the lldb debugger. The simulator supports all current iOS platforms. Xcode provides iOS developers with an integrated environment for developing, testing, and debugging iOS applications. So, we’ll need to run the application in a debugger to find the exact location. Since we’re dealing with an uncaught exception, the backtrace only provides us with a rough idea of where the error is occurring somewhere in UIKit. Raygun also provides a backtrace for the error. NSRangeException indicates that the code exceeded the bounds of a data structure, and the report suggests a subscript out of range is causing the crash. The class name and error message tell us a lot about the error. But in the event of any errors happening in deployed applications, the date and time can be advantageous. Since we forced the error now, we don’t need the date and time. ( BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions įortunately, you integrated your application with Raygun Error Monitoring and Crash Reporting, so you can use the information to get an idea of where to look for the bug. After you check out the project, add your Raygun API (Application Programming Interface) key to didFinishLaunchingWithOptions in AppDelegate.m If you want to follow along, you’ll need to sign up for a Raygun account. The single view has a button with text that changes for each press. We’ll use a single view iOS application for this tutorial. So, let’s get started! Step 1: Sample project The source code for this project is available on Github. We’ll be using the current version of Xcode at the time of this writing, which is version 10. This tutorial requires a macOS computer with Xcode installed. Explore Xcode’s debugging tools for iOS.We’ll follow six steps to examine a simple application and isolate and fix a bug. Learn more and try Raygun free for 14 days. Be alerted to issues affecting end users and replicate problems 1,000x faster than using logs and incomplete information from users. It takes minutes to add Raygun into your software. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |