Debugging in Xcode : Breakpoint (Part 2)
To create a symbolic breakpoint in Xcode, click the
+ button in the lower-left toolbar within the Breakpoint Navigator and choose “Symbolic Breakpoint…”.
In the above screenshot, you can see that I’m adding a symbolic breakpoint for the method ‘getDetails()‘ and added a debugger command ‘bt‘(Backtrace of thread can be useful when debugging multithreaded part of the application).
If you run the app with the breakpoint enabled it will pause every time the ‘getDetails()‘ method is called. The breakpoint will be automatically added if the same method signature is in some other class as well. (see the below screenshot)
To create a conditioning breakpoint, you just set the breakpoint like you normally do. Next, you edit that breakpoint, which will give you the interface to add a condition. Here for the demo, I’ve added a breakpoint inside a loop and added a condition that allows the breakpoint to keep skipping until it meets the condition, the one you want to debug. In the below screenshot you can see that once the condition i.e [selectedFruit == “pineapple”] satisfies it stopped.
You can customize actions on the breakpoints. Multiple actions can be added to a breakpoint(check the below screenshot for reference)
For the demo, I’ve added a breakpoint to the ‘deinit‘ method that plays a sound and debug-info of bt command whenever the ‘Viewcontroller’ gets deallocated.
Setting up Watch Breakpoint
Watchpoint: A watchpoint can be added by right-clicking on a variable in variables view So that it stops execution whenever the value changes. (Also called as data breakpoint).
In the above screenshot, you can see I’ve added a watchpoint to the “arrFruits” variable. The moment I tried to append something to that array it stopped the execution and in the call stack, it shows why it happened.
Watchpoint can be created through lldb commands too.
Note: There are limited hardware resources for watchpoints. If the watchpoint setting fails, consider disabling/delete existing ones to free up resources.
If you enjoyed this article, share it with your friends and colleagues! Peace.