Pocket How
Xcode and tooling

LLDB debugging tips for iOS: p, po, v, breakpoints and watchpoints

Xcode 26 and later, iOS and iPadOS apps. Intermediate. By Cihat Salik, .

Short answer

Use v to read a variable without running code, p for most inspection and expressions, and po when you want an object's debugDescription. Replace print statements with breakpoints that log and auto-continue, use symbolic and Swift error breakpoints for crashes, watchpoints for values that change unexpectedly, and the memory graph for leaks.

Why print debugging stops scaling

Adding print calls works until it doesn’t. Each one needs a rebuild, they pile up in the console, and they change timing just enough that a race condition disappears while you watch. LLDB and Xcode’s debugger tools can answer most of the same questions without recompiling: which value a variable held, who called a function, when a property changed, and why an object is still alive. This guide covers the commands and breakpoint types worth knowing well, in the order you reach for them.

p, po and v: pick the right print

The three print commands look interchangeable, but each one does something different under the hood.

v is the short alias for frame variable. It reads values straight from memory using the debug information and runs no code. Apple’s stepping-through-code guide notes that the variable viewer in Xcode uses the same command. Because it runs nothing, it can’t call a method or evaluate a computed property, and asking it to do so produces an error.

(lldb) v self.items.count
(lldb) v order.customer.name

p has been an alias for dwim-print since Swift 5.9 and Xcode 15. The Swift team’s debugging improvements post explains the behaviour. When the argument is a plain variable path, p uses the same fast path as v. When it’s an expression, a function call or a computed property, it falls back to the expression evaluator, which compiles and runs code in your process. Apple’s WWDC24 LLDB session recommends p as the one command for most inspection, including string interpolation:

(lldb) p cart.total
(lldb) p "first item: \(cart.items.first?.title ?? "none")"

po prints the object description, which in Swift means debugDescription from CustomDebugStringConvertible, or description if that’s all you have. Antoine van der Lee shows in his post on custom debug descriptions that po gives you exactly what debugPrint would print. Like expressions in p, it compiles code, so it’s slower and can fail in contexts where the expression evaluator struggles.

Two details from the Swift 5.9 post matter in practice. First, p no longer creates persistent results such as $R0, since they add overhead and keep objects alive. Use expression (or expr) when you want a result you can refer to later. Second, po can print a Swift object from a raw address, which helps when all you have is a pointer from a log line.

When a variable is declared with a protocol type and p or po reports that the member doesn’t exist, Apple’s guide recommends falling back to v, which resolves the dynamic type.

Which one should you default to? The WWDC24 session pushes p for everything, and adopting Swift 6’s @DebugDescription macro makes your custom summaries show up in p and in the variable viewer. Apple’s bug diagnosis guide adds one exception: in breakpoint actions on timing-sensitive code, use v, because po compiles code on every hit. This article’s recommendation: type p by habit, use v in breakpoint actions and when an expression fails, and keep po for types whose debugDescription you wrote for that purpose.

@DebugDescription
struct CartItem {
    let title: String
    let quantity: Int

    var debugDescription: String {
        "\(quantity)x \(title)"
    }
}

The macro needs a debugDescription built from string interpolation over stored properties. It can’t call methods or computed properties, because LLDB evaluates it without running code.

Breakpoints that do work for you

Conditions and ignore counts

A breakpoint inside a loop that runs 500 times is useless if it stops every time. Control-click the breakpoint, choose Edit Breakpoint, and set a condition using variables in scope, such as item.id == targetID. The breakpoints guide also describes the ignore count, which skips the first N hits. The command-line equivalents, from Apple’s LLDB guide, take the breakpoint ID:

(lldb) breakpoint modify --condition 'item.price > 100' 3
(lldb) breakpoint modify --ignore-count 10 3
(lldb) breakpoint modify --one-shot 3

A one-shot breakpoint deletes itself after the first stop. The WWDC24 session combines this with actions: an auto-continuing breakpoint on one function sets a tbreak (a temporary breakpoint) on another, so the debugger stops in the second function only after the first has run.

Actions instead of print statements

In the Edit Breakpoint popover, add an action and check “Automatically continue after evaluating actions”. The breakpoint becomes a log statement that needs no rebuild and leaves no trace in your source. Useful actions:

  • Log Message with expressions in @...@, the breakpoint name or the hit count. Good for “did this run, and how often”.
  • Debugger Command running v or p. Good for printing state at a point.
  • Sound. Apple suggests it for confirming that code runs without disturbing timing.

From the console, breakpoint command add attaches commands to the most recent breakpoint or to an ID you pass. End the list with continue to auto-resume, and type DONE to finish. The WWDC24 session warns that commands added this way replace actions you set in Xcode.

(lldb) b CheckoutView.swift:84
(lldb) breakpoint command add
> v cart.items.count
> continue
> DONE

When a line runs millions of times, even a conditional breakpoint slows the app to a crawl, since LLDB has to stop and evaluate the condition on every hit. The WWDC24 session’s answer is to compile the condition into your code with raise(SIGSTOP) inside an if. The debugger then takes over as if a breakpoint had hit. Remove it before committing.

Symbolic, Swift error and exception breakpoints

Some bugs happen in code you didn’t write. A symbolic breakpoint stops on a function name in any module. Add one from the plus button at the bottom of the Breakpoint navigator. Apple’s standard example is UIViewAlertForUnsatisfiableConstraints, which stops when Auto Layout breaks a constraint so you can see the backtrace. Other useful symbols include -[UIApplication sendAction:to:from:forEvent:] to find which control fired an action. From the console:

(lldb) breakpoint set -n UIViewAlertForUnsatisfiableConstraints
(lldb) breakpoint set -E Swift
(lldb) breakpoint set -E objc

The last two are the command-line forms of the Swift Error and Exception breakpoints, which Apple’s guide recommends for crashes that land on a try! or in main. A Swift Error breakpoint stops where the error is thrown, which is usually several frames away from where it surfaces. If you throw errors on purpose in normal control flow, add the type name with -O so you don’t stop on every expected error.

Runtime Issue breakpoints stop when a sanitizer or the Main Thread Checker reports a problem, instead of letting it scroll past in the issue navigator.

Symbolic breakpoints on hot system functions fire constantly. Apple’s tip: disable them until you reach the point you care about, then enable them, or add a condition.

Watchpoints: who changed this value

A watchpoint stops when memory changes, which answers the question breakpoints can’t: which code wrote this value. In Xcode, pause, Control-click a variable in the variable viewer and choose Watch. From the console, per Apple’s LLDB guide:

(lldb) watchpoint set variable self.selectedIndex
(lldb) watchpoint set variable -w read_write total
(lldb) watchpoint modify --condition 'total < 0' 1
(lldb) watchpoint list
(lldb) watchpoint delete 1

The default watch type is write. Watchpoints use hardware debug registers, and the guide notes they’re limited by the number of registers the device has, so delete them when you’re done. They work best on stored properties of classes and on globals, whose address stays fixed. A local value type moves or disappears when its scope ends, so watch the property that holds it instead.

Seeing the view hierarchy

The Debug View Hierarchy button in the debug bar captures every view and lays them out in 3D layers. It answers layout questions quickly: a view that’s present but zero-sized, a transparent view intercepting taps, or a view clipped by its parent. Select a view to see its frame, constraints and class in the inspectors. Apple’s bug diagnosis guide pairs it with environment overrides, which switch appearance, Dynamic Type size and accessibility settings on the running app without changing device settings.

For SwiftUI, the hierarchy shows the hosting views and platform views SwiftUI creates, not your View structs one to one. It’s still the right tool for frame and hit-testing problems. For “why did this body run” questions, use the SwiftUI instrument instead.

Memory graph: why is this still alive

The Debug Memory Graph button pauses the app and replaces the backtrace with a list of every type and its instances. Apple’s guide describes the workflow for a retain cycle:

  1. Watch the memory gauge while you open and close a screen.
  2. If memory goes up and doesn’t come down, pause and open the memory graph.
  3. Look for more instances of the screen’s view controller or model than you expect.
  4. Select one, Control-click a node holding a strong reference and choose Focus on Node.
  5. If you find a path of strong references that loops back to the object, you have a cycle. Make one side weak or remove the reference.

Closures stored on an object that capture self strongly are the classic cause. Timers, notification observers and Combine sinks stored on the object they capture are close behind. Turn on Malloc Stack Logging in the scheme’s Diagnostics tab before you run, and the memory graph also shows the backtrace where each object was allocated.

Debugging Swift concurrency

Async code makes backtraces harder to read, since a suspended task isn’t on any thread’s stack. Xcode 26 improved how the debugger follows execution across async functions and threads. The Xcode 27 release notes add a language swift task tree command that prints every Swift task LLDB knows about as a tree, which helps when you need to know which task spawned which child. Xcode 27 also lets LLDB import explicitly built Swift modules from DerivedData in projects with bridging headers, which the notes say can make the first po of a session much faster.

Traps

  • Optimised builds lie. In Release, variables are often <unavailable> and lines execute out of order. Debug in the Debug configuration unless the bug only reproduces in Release.
  • po changes state. Evaluating a computed property or calling a method runs real code. A lazy property initialised by your po can hide the bug you were chasing.
  • Breakpoint actions aren’t validated when you add them. A typo shows up as an error only on the first hit.
  • Too many watchpoints. You hit the hardware limit quickly. One or two at a time.
  • Stale breakpoints. Shared breakpoints in a scheme or a forgotten symbolic breakpoint slow down every run for the whole team. Clean them up.

Quick reference

Question Tool
What is this variable’s value? v (no code runs)
What does this expression return? p
What’s this object’s description? po
Keep a result for later expr
Log without stopping or rebuilding Breakpoint action, auto-continue
Stop only on the bad case Breakpoint condition or ignore count
Crash lands in main or on try! Exception or Swift Error breakpoint
Bug inside a framework Symbolic breakpoint
Who changed this value? Watchpoint
Why is this view in the wrong place? Debug View Hierarchy
Why wasn’t this deallocated? Debug Memory Graph
Which tasks are running? language swift task tree (Xcode 27)

Sources and further reading

Read next