AppCode 2023.1 Help

Debug code

For debugging C/C++/Objective-C and Swift code, AppCode uses the LLDB debugger bundled in Xcode. Depending on the installed/enabled plugins, you can also debug code written in other languages.

During a debugging session, you launch your program with the debugger attached to it. The purpose of the debugger is to interfere with the program execution and provide you with the information on what’s happening under the hood. This facilitates the process of detecting and fixing bugs in your program.

Configure Debugger settings

  • To configure common debugging properties and behavior, go to Preferences | Build, Execution, Deployment | Debugger. See the detailed description of these settings in Debugger.

Create a custom run/debug configuration

  • If you need some arguments to be passed to the program or some special activity to be performed before launch, you need to set up a custom run/debug configuration. For more information, refer to the Run/debug configurations section.

General debugging procedure

There is no one-size-fits-all procedure for debugging applications. Depending on actual requirements you may have to use different actions in different order. This topic provides general guidelines, which represent typical debugging steps. The details on how and when to use particular features are provided in the respective topics.

  1. Define where the program needs to be stopped. This is done using breakpoints. Breakpoints are special markers, which represent places and/or conditions when the debugger needs to step in and freeze the program state. A program, which has been frozen by the debugger is referred to as suspended.

    The alternative to using breakpoints is manually suspending the program at an arbitrary moment, however this method imposes some limitations on the debugger functionality and doesn't allow for much precision as to when to suspend the program.

  2. Run your program in debug mode.

    Just like with regular running of the program, you can run multiple debugging sessions at the same time.

  3. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.

    The debugger provides you with the information about variable values, the current state of the threads, breakdown of objects that are currently in the heap, and so on. It also allows you to test your program in various conditions by throwing exceptions (for example, to check how they are handled) or running arbitrary code right in the middle of the program execution.

    While these tools let you examine the program state at a particular instant, the stepping feature gives you the control over step-by-step execution of the program. By combining the tools you can deduce where the bug is coming from and test your program for robustness.

Last modified: 05 March 2023