Post

Debugging in Xcode Basics (Part 2)

Symbolic Breakpoint

Screenshot-2020-09-16-at-2.43.20-PM

To create a symbolic breakpoint in Xcode, click the + button in the lower-left toolbar within the Breakpoint Navigator and choose “Symbolic Breakpoint…”.

Screenshot-2020-09-16-at-2.44.38-PM-768x338

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)

Screenshot-2020-09-16-at-8.41.33-PM-768x338

Conditioning breakpoints

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.

Screenshot-2020-09-16-at-9.00.03-PM-768x477

Customizing breakpoints

You can customize actions on the breakpoints. Multiple actions can be added to a breakpoint(check the below screenshot for reference)

Screenshot-2020-09-16-at-9.49.15-PM

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.

Screenshot-2020-09-16-at-9.47.39-PM-768x448

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).

Screenshot-2020-09-27-at-1.23.02-PM-768x412

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.

Screenshot-2020-09-27-at-1.27.02-PM-768x459

Watchpoint can be created through lldb commands too.

Screenshot-2020-09-27-at-2.11.20-PM-768x459

There are limited hardware resources for watchpoints. If the watchpoint setting fails, consider disabling/delete existing ones to free up resources.

References:

GDB to LLDB command map

This post is licensed under CC BY 4.0 by the author.