← All articles

Optimize debugging in Xcode: ‘v/vo’ vs ‘po/p’ in LLDB

When to use LLDB’s frame-variable commands and when expression evaluation with p or po is the better choice in Xcode.

LLDB Debug optimisation

LLDB offers two different ways to inspect state while debugging in Xcode. The v command is an alias for frame variable; p and po use the expression evaluator.

Use v for variables in the current frame

v reads variables available in the selected stack frame without compiling and running a new expression. It is usually fast and avoids executing application code while you are trying to understand the current state.

(lldb) v user
(lldb) v order.total

vo asks LLDB to use the object description when one is available. It can be useful when the normal variable representation does not show the information you need.

Use p or po when evaluation is required

p evaluates an expression and prints the result. po also evaluates an expression, then requests the object’s description. They are useful for computed properties, method calls and expressions that do not already exist as variables in the current frame.

(lldb) p items.count
(lldb) po view.debugDescription

Expression evaluation can execute code and may change state or trigger side effects. It can also fail when the debugger cannot compile the expression in the current context. That is why I normally start with v for stored state and move to p or po only when I need evaluation or a custom description.

What are you working on?

Tell me about the product, the team or the technical question you need help with. Pick the time that suits you.