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

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.

Related

Unable to Build mac project in XCode14.0/14.1 with macOS ventura

I have recently updated to macOS 13.0 and for that minimum XCode Version required is 14.x series. But my existing project never getting successfully building. Its getting stuck at some point.
Its not getting failed. Build process screenshot is attached below. Its not pointing to any specific class. Seems like there are lots of classes which are getting compiled successfully at last but still build process is stuck at some point:
Seen similar threads like below on apple pages but nothing seems working. Does anyone got resolution?
Xcode 14 project compile error
XCode 14 compile errors immediately disappear or do not appear at all
Something similar has happened to me in the past on a number of occasions. If the Swift compiler is hanging mid-build, usually the issue is that there is some expression that is too complex for Swift to do the type inference on.
What you need to do is first find the exact statement that is causing the hang. This is how I do it:
First find out which source file is causing the problem. Look at the build log to figure this out (the build log can be located by looking at the reports navigator ⌘9 ). Find the build log and click on it. The build log will appear in an editor window.
One of the compiles will still be in progress and its file is the one you want.
The next thing to do is comment out all the code and recompile. This time the compilation will finish (if you have the right file, or there is only one) but probably with a lot of errors. Then you add the code back in, function by function, until one of them causes the compilation to hang again. If it's not obvious which line of the function is causing the problem, comment it out again and then add the lines back one by one until the compilation breaks again.
Once you have located the line, you need to simplify the type inference on that line. If it's a closure, try adding an explicit declaration for its parameters and return type. If it involves some complex array, try adding a type annotation to its declaration. Also try breaking down complex expressions into multiple simpler expressions.
There's no one size fits all answer to this but usually, once you have located the exact line that is causing the problem, it should be reasonably obvious how to fix it.

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
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'

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.

Xcode 7 crash every time I try to print something in the debugger console

I've searched around and can't find anything on this.
Using Swift 2 and Xcode Version 7.0.1 (7A1001). Every time I execute something in the debugger console, Xcode crashes.
The project is not very big, and has less than 10 third party frameworks.
I can't think of much more information that's relevant, but I'm sure there's more, so please do ask me if there's anything I should add to my question that would help.
I've of course cleaned build and derived data.
It's driving me insane. Thanks!
UPDATE 16/11/12
Submitted rdar://23559366.
How are you maintaining your third party frameworks? Via Carthage?
If so then this is probably your issue: https://github.com/Carthage/Carthage/issues/924
This is an issue if the location of the /Carthage/Build/iOS folder is in a different location to where it was produced (i.e if it was compiled on a different machine and the absolute file path has changed).
A temporary fix would be to run carthage build --no-use-binaries on your machine to rebuild the symbols using the current absolute file path working around the bug.
But if you wasn't using carthage then its probably not your issue so sorry
I had similar problem with Xcode whenever I hit breakpoint.
In case you see this screen right before your Xcode crashes - you are lucky and my fix might save you. All you need to do is open this window and in the Project Navigator, select any file that you want, so that instead of that white blank view you would get your code. After this you are most likely will be able to successfully stop your app at your breakpoint and perform the debug.
I am not sure why this happens, but I suspect that the reason is Debug View Hierarchy mode, which you might have triggered prior to setting you breakpoint and trying to stop at it. At least this is when it happens to me.
I have similar problem earlier.
If you try to print non-optional variable and unfortunately it holds nil value then it breaks/crash. so that make sure declare all possible variables as "Optional type".

Resources