Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 732
Shannon D Avatar asked Oct 23 '20 20:10

Shannon D


People also ask

What is PO in LLDB?

1. The po command is added to the built-in command set in lldb using: "command alias po expr -O --". If you run help po the last line in the output is: "'po' is an abbreviation for 'expression -O --'. The -- indicates the end of the command options, so all your input on the line is your expression.

What is the use of PO command?

The po command uses the object description, whereas the p and v commands use the data formatters to display the object on the console. A second important difference is that both po and p compile expressions and then execute them and have access to the full language.

How do I see variables in Xcode?

See variable values in code and the variable viewer When your app pauses at a breakpoint, hover over a variable in your source code to view its current value. If the variable is an image or other type that isn't expressible as text, click the Quick Look button at the upper-right to see a preview of the variable.

How do you print a variable in Swift?

In Swift, you can print a variable or a constant to the screen using the print() function. Let's see that in action by creating a playground file, as you learned in the last lesson. After creating your new playground in Xcode, start by declaring three strings representing your favorite word, color, and musician.


1 Answers

You can change optimization level to "none" value in build settings. Its works for me.enter image description here

like image 200
Степан Варткинаян Avatar answered Sep 20 '22 16:09

Степан Варткинаян