Debugging with LLDB

Testing Mid-level Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

At a breakpoint you want to see a local struct's properties quickly, without running any code in the app. Which command?

Options
Hint 1 of 1

Which command doesn't evaluate an expression?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A v myValue

Correct. frame variable reads memory directly without evaluating code.

Why not the others?
  • B po myValue. po runs code to get the description, which is slower and can have side effects.
  • C e myValue = .init(). That changes the value instead of showing it.
  • D bt. bt prints the backtrace, not variables.

30-second answer

At a breakpoint, v (frame variable) reads variables straight from memory without running code, so it is fast and safe. p evaluates an expression and po evaluates it and prints its description. Use breakpoint conditions, actions that log and continue, symbolic breakpoints like UIViewAlertForUnsatisfiableConstraints, and watchpoints to catch when a value changes.

Practise saying it · 30 s. No recording, just a timer

Explain your LLDB workflow.

Say your answer out loud, then check which of these points you covered:

  • v vs p vs po
  • Conditional and logging breakpoints
  • Watchpoints

Deep dive

expression (or e) can change state at runtime, for example e self.view.backgroundColor = .red.

bt prints the backtrace; thread list shows all threads.

Swift Error breakpoints stop where errors are thrown.

Logging breakpoints avoid adding print statements and rebuilding.

Common mistakes

  • Using po for everything, which can be slow or fail.
  • Adding prints and rebuilding instead of using breakpoint actions.

Senior take & follow-ups

Seniors know the cost of each command and use breakpoints as tools, not just pauses.

Follow-up questions

Think of your answer first, then open the hint.

  1. What is a watchpoint?

    Show hint

    It stops when a memory location changes.

  2. How do you find who changes a property?

    Show hint

    A watchpoint, or a breakpoint in didSet.

Suggest a fix if something here is wrong or out of date.