Replies
Cannot create Swift scratch context (couldn't create a ClangImporter) (lldb)
po symbol in the (lldb) prompt doesn't work. And so no Swift objects or symbols are available; only an Objective C-type view of them.
This is very annoying! and makes the debugger and debugging basically worthless in Xcode for Swift.
On an M1 Mac mini. I completely uninstalled Xcode and deleted preferences and other developer directories from ~/Library. and re-installed Xcode (from app store). I scoured here and stack overflow for workarounds or diagnoses and nothing has worked.
Code Block console $ system_profiler SPSoftwareDataType Software: System Software Overview: System Version: macOS 11.1 (20C69) Kernel Version: Darwin 20.2.0 Boot Volume: Macintosh HD Boot Mode: Normal Computer Name: * User Name: * Secure Virtual Memory: Enabled System Integrity Protection: Enabled Time since boot: 1:48
this works (swift from command line to run lldb from within) but I have no idea if it's useful info to help diagnose.
Code Block shell ❯ swift Welcome to Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28). Type :help for assistance. 1> : (lldb) expression -l swift -- import Foundation (lldb)
on same M1 Mac mini, create a new test user account and the debugger in Xcode 12.3 starts up normally (without the ClangFormatter message) and Swift variables work properly
on an Intel Mac also running macOS 11.1 Big Sur and Xcode 12.3, the debugger starts up normally at breakpoint (without the ClangFormatter message) and Swift variables work properly
Change your shell from zsh to bash.
Code Block chsh -s /bin/bash
Run your project and debugger should work as expected. Then change your shell back to zsh and the debugger should still work.
I’m not sure what happened or why but I hope this can help someone!
Xcode Version: 12.4 (12D4e)
Mac OS Big Sur 11.1
-
Tried this (command entered in Terminal) but changing shell to bash did not fix the problem using Xcode 12.3 on Catalina. When starting terminal the message "The default interactive shell is now zsh" even the window is captioned -bash and current shell obtained by echo $SHELL is bash
-
Running Xcode from terminal with "open project.xcodeproj" in project.xcodeproj folder after changing shell to bash worked ... looks as though Xcode picks up its shell from somewhere else
-
XCode works OK on different account, even when run from Launchpad. Running from Terminal didn't help on main dev account
-
Can't believe that this worked. It would be nice to know why this is.
I will say though that some custom shells (in my case, fish) return the debugger to its problematic state even after switching back from bash/zsh. So if you're like me and use iTerm, set the custom shell for your profile only and leave bash/zsh as the system default to please Xcode.
-
Seeing this answer solve the problem for others had me disheartened because a new user didn't fix it for me. I then decided to launch my project from the command line and then I saw variables in the debugger and no ClangImporter error. I did happen to switch from bash to zsh a few times before launching from the command line, so that was likely still an important step.
I managed to get this fixed, in my case the root cause was a library that was distributed in binary form and had somehow managed to put extra framework searchpaths in the library configuration. The search paths were relative to the developers computer home folder so they did not work properly. There were also some extra flags that were used for their internal debugging.
I managed to find the root cause by using swift-healthcheck
on the debugger and comparing it to a version that did not have this problem.
There is not too much information about the swift-healthcheck
available currently, but you can just type it in the debugger and see the output. Debug Swift with LLDB (WWDC 2022) session had some information.