Categories
ios lldb swift xcode xcode12

Xcode12 po command in lldb in console cannot find variables in scope

Ever since I updated to Xcode 12, I have not been able to print out variables in the console while debugging with lldb.

Using print() statements directly in Swift code outputs to the console as expected.

A command in the console such as po "hi" outputs “hi” to the console as expected.

Trying to run po <variable_name>, instead, always outputs this line:

error: <EXPR>:3:1: error: cannot find 'variable_name' in scope

instead of the expected variable’s value.

Steps I took

  1. Add these lines to Swift code

    let example = "hi"
    print(example)

  2. Put a breakpoint on the second line, the one with the print() statement

  3. Run the code and wait for the breakpoint to be hit

  4. Try to run po example in the debug console

Expected result

It should print "hi" in the console

Actual result

It prints this error line

error: <EXPR>:3:1: error: cannot find 'example' in scope

It’s the same when running on the simulator or a device. I’ve tried activating the console, and restarting Xcode.

I’ve tried creating a new project in Xcode12 and that works fine, my other older projects created with previous versions of Xcode work fine in Xcode 12.

I’ve tried confronting the Build settings both with the other projects and with a newly created project and it seems nothing’s wrong: optimization is set to None as it should for debug build configurations and the run scheme is set to launch a debug build configuration.

Where else could the problem be?