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

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
Add these lines to Swift code
let example = "hi"
print(example)
Put a breakpoint on the second line, the one with the print() statement
Run the code and wait for the breakpoint to be hit
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?

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.

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

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'

Related

Google Protobufs in iOS app crashing at GPBDescriptor

This one is a real head-scratcher...
PART ONE
We have a swift iOS application with different targets for Dev and Prod (normal stuff).
We've incorporated Google Protobufs into it for one of our latest features. This was done using Google's J2ObjC library and the pod 'Protobuf', '= 3.11.4' pod. (Our .proto files were made with v3.11.4).
Running our Dev target works fine (mostly, see Part Two). Running our Prod target crashes in the constructor of any GPBMessage object.
It crashes within the + (GPBDescriptor *)descriptor function of the pbobc.m file of our message object...eventually getting to this error within GPBDescriptor.m
Line:
enumHandling_.enumDescriptor_ = coreDesc->dataTypeSpecific.enumDescFunc();
Error:
(lldb) po coreDesc->dataTpeSpecific
error: <user expression 2>:1:11: no member named 'dataTpeSpecific' in 'GPBMessageFieldDescription'
coreDesc->dataTpeSpecific
~~~~~~~~ ^
What's weird is this crashes in Prod and not Dev. Combing through both targets' Build Settings...they're identical. Build Phases are the same, Build Rules are the same, Plists are basically the same...
I don't know what else to check.
PART TWO
There is one GPB message that crashes on init in both our Dev and Prod targets. (We can run without it, so I've commented it out during development.)
The difference between this message and the others is that this one is a list of enums.
It crashes on the same line. ¯\(ツ)/¯
Thank you SO MUCH in advance! :D
of course immediately after I post the question I find the answer...
Google protocol buffers on iOS
Needed to add -fno-objc-arc to every ...pbobjc.m file in the Compile Sources of Build Phases.
I had already done this for a few files in Dev, hence the (very subtle!) difference.

Resource-Target of pod erroneously needing Swift Version set

After successfully linting and updating a pod, I updated it in the main project. However, upon cleaning I encountered this issue:
Normally this is simple to resolve (go to Build Settings and set the Swift Language Version -- however, this error is occurring on the Resource-Target, which doesn't have that setting...making it very strange that I am running into this error.
I've figured out how to resolve this.
The Resource-Target includes a xcdatamodel. I needed to change the Code Generation to Objective-C rather than Swift. This was hard to find especially since the pod lint step did not catch this or give any warning.
I found this answer via: https://github.com/CocoaPods/CocoaPods/issues/7950 -- even though this issue doesn't seem to be exactly the same as this one, but it is related.

Logging and breakpoints not working in XCTests

I have a large iOS project, and my problem is that, when running XCTests:
Breakpoints within the app, or within the tests themselves, are not hit
NSLogs/prints from within the app are not visible within the test log, but logs from within the tests are visible
I have another iOS project within the same workspace, and breakpoints and logging work fine.
The iOS project in question was originally created on an old version of Xcode (circa 2012, unsure which version exactly); and I have seen this comment elsewhere from somebody having seen this issue with an old .xcodeproj.
The project itself is hybrid Obj-C/Swift, uses several Cocoapods, a watchkit extension, and tests divided into three targets.
Given my project's complicated configuration, I would prefer to avoid beginning again with a fresh .xcodeproj and try to mirror exactly the configuration of my faulty one.
What could the reason for this fault be and what might I change within my existing .xcodeproj's configuration to fix it?
Select your scheme, go to Edit scheme... and tick the Debug executable option under the Test > Info pane.
The debugger will attach to both your tests and your target application, and breakpoints will be hit on both parts of your project.
Note that when a breakpoint is hit in your target application, your test is still running and may time out, killing both applications.
The culprit was DEPLOYMENT_POSTPROCESSING = YES in the project file.
This has to do with how your test scheme is set up. I was having the same issue and I fixed mine by turning Debbuging "ON" for the test executable.
I made a new scheme for my UI tests, so I assumed the debugger wasn't attaching to the new UI tests scheme when no breakpoints were hit. However, this post
had the correct answer for me.
In my case breakpoint was not hit in just one callback, so I changed "Swift Compiler" "Optimization Level" to "No optimization" in project target build settings for debug, and it started working in Xcode 9.3 as well as AppCode.
For breakpoint not working case check which Optimization Level you have, if you have the new -Os breakpoints start acting weird, change to -None or No Optimization in debug mode whatever option you have
Problem with logs not appearing in a debug area, in my case, was due to the OS_ACTIVITY_MODE argument which was set to "disable" in Scheme -> Test -> Arguments
I tried everything in the replies as of this date, but in the end the only thing that worked in my case was to remove the target and recreate it again.

Couldn't get Xamarin projects working with Rider-EAP on OSX

I was really excited, when JetBrains launched the Project Rider-EAP. First thing I've tried was to get a Xamarin-iOS project to run in Rider-EAP, but it doesn't work out of the box.
Update 1: This issue is now listed as critical bug with fix in EAP 2: https://youtrack.jetbrains.com/issue/RIDER-618
1. Problem (fixed) Projects didn't load with the exception that Xamarin.iOS.targets could not be found.
I fixed this with a simple Symlink:
ln -s /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/ “/Applications/Rider EAP.app/Contents/lib/ReSharperHost/macos-x64/mono/lib/mono/xbuild/”
2. Problem
References are not loaded correctly. Therefore the whole syntax highlighting and everything beyond is broken.
See screenshot: References are not loaded correctly
I get the following error as well:
Error:null: Error initializing task MakeDir: Could not load file or assembly '/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Tasks.dll' or one of its dependencies
Switching the xbuild to mono 4.2.2 removes the error but not solves the problem.
PS: It seams that the references are loaded correctly for Xamarin Android projects.
Basic Xamarin Support like open and build is added with EAP 8 of Project Rider.
More advanced features will come with the next Builds and are tracked here: https://youtrack.jetbrains.com/issue/RIDER-1533

How to get Xcode debugger to show 'self' and variable values again?

For some reason, Xcode has stopped showing the value of 'self' when debugging (it just says 'self' and nothing else. Local variables are showing, though. Also if I add valid values with Add Expression, they always say Invalid Expression.
It used to work well until a while ago, although I can't determine when it last worked. The debugger seems to work well for other projects, so I'm guessing it's something in the project settings.
I've inspected build settings, and made sure that optimization values are set to None [-Oo] for debug (and None [-Onone] in Swift).
I've also made sure that the current scheme is Debug, and that Debug Scheme has 'Debug executable' selected.
This is a Swift project, with some Objective-C files, and it's in Xcode 6.4 (6E35b).
How can I get Xcode to show the value of 'self' again, and to display values of expressions that I add in the debugger?
Finally solved this.
#AustinT and anyone who runs into this:
The problem for me was caused by a double installation of crashlytics, through cocoapods and through traditional installation.
I tried to leave only the cocoapods version for hours, following the official guide, but I couldn't get it to work. I got a 'not found' message on the build phase script.
So eventually I gave up and just left the traditional installation version, and erased every mention of the pod version in the project.
The debugger went back to normal, and life is good again.

Resources