简体   繁体   中英

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?

You can change optimization level to "none" value in build settings. Its works for me. 在此处输入图片说明

I had this issue as well, everything was set correctly in build settings, I had the same situation as in the question.

For me the problem was solved after I moved all my SPM dependencies back to CocoaPods, but that's not the silver bullet because I have other projects where some dependencies are on CocoaPods and some on SPM and those work perfectly fine.

What can be useful, though, is that to come to this solution I checked out older commits until I found a working one and then tried to restore things that changed since that commit. This should help find the cause in every specific case.

This issue is so unpredictable that, if you are experiencing it, I think it's worth filing a feedback to Apple, if you can, attaching your projects to the feedbacks.

In my case the problem was caused by 'GoogleAPIClientForREST' installed as Cocoapod dependency in a project containing also a Swift Package.

You can find the issue reported here: https://github.com/google/google-api-objectivec-client-for-rest/issues/478

I don't know if the responsible for the problem is SPM or GoogleAPIClientForREST, but a good workaround for now is to install a previous version of GoogleAPIClientForREST:

pod 'GoogleAPIClientForREST/Drive', '~> 1.3.11'
pod 'GoogleAPIClientForREST/Calendar', '~> 1.3.11'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM