Error when debugging: Cannot create Swift scratch context

When I run my app from Xcode 12b1 and hit a break point, LLDB says "Cannot create Swift scratch context (couldn't load the Swift stdlib)" and any subsequent commands like "po" seem to do nothing. Who can I fix this?
Post not yet marked as solved Up vote post of mhoeller Down vote post of mhoeller
16k views

Replies

Good to know that there will be a fix. In the meantime, is there any workaround? We're working with the new StoreKit testing stuff that is only available on Xcode 12. Having to rely on NSLog-debugging is the ultimate productivity killer!
Xcode beta 3 works for me now...

thanks a lot, appreciate the fix!

Well I have same problem in new Xcode 12 beta3.
I cannot debug ui tests now and it seems I will have to revert back to beta2?
Same issue happened in Xcode 12 beta3 during debugging. I am running Xcode beta3 on Catalina 10.15.6
For anyone experiencing this issue when running unit tests, my work around was to disable code coverage. Note that this only works if you are on Beta 2. I tried the same workaround on Beta 3 and it no longer works so I'll stick with beta 2 for now.
It seems to be fixed in 12 beta 4.
I'm experiencing the same problem – getting Cannot create Swift scratch context (couldn't create a ClangImporter) in console when I hit the breakpoint and then lldb does nothing when I run po someVar.
Few things important to note:
  • I'm on Catalina 10.15.7 (same issue was on 10.15.6).

  • Initially this issue appeared in Xcode 12.0.1, but not after I updated to it. I can swear it was working just fine until at some point it suddenly stopped working (no updates happened in between).

  • It has nothing to do with the project I'm running. I tried fresh new iOS and macOS projects, same issue everywhere.

  • I downloaded Xcode 12.2 beta 2 and the same problems happens there

This is highly frustrating issue that makes development 10x harder and I'm desperate to find any kind of solution. I'm happy to help any Apple engineer with resolving it, I will send logs and whatever they might need.

I also submitted a ticket via Feedback Assistant: FB8790427
I just started getting this error in 12.0.1; spent 2 hours downloading the 12.2 beta 3 and I'm still seeing the same issue, even after switching my active developer directory.

Get the "Cannot create Swift scratch context (couldn't create a ClangImporter)" error whenever a breakpoint is triggered, and po/v/p don't return anything. When using the built-in inspector, I get "expression produced no result".

Does anyone have any ideas at all? I'm the only one on my team dealing with this.

I'm the only one on my team dealing with this.

Investigating this? Or experiencing this?

If you’re the only one experiencing the problem, it’s time for some differential debugging…

If you and a colleague check out exactly the same code and build it with exactly the same Xcode on exactly same version of macOS, do you see different behaviour? That is, things work for them and don’t work for you?

If so, there’s something about your environment that’s triggering the problem. In that case you should try creating a new user account on your Mac to see if the problem follows that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I too am experiencing this issue (Cannot create Swift scratch context (couldn't create a ClangImporter)).

I did create a new user, and saw success in getting debugging to work properly. However, I'm unsure of what actually is different between the two user accounts. Making a permanent switch to another user account would be too difficult at this point, as well.

I've tried uninstalling Xcode, and clearing out/deleting all Xcode related folders I can find on the broken user account.

Also, Xcode 11 continues to work perfectly. This only occurs on any version of Xcode 12 (all betas have had this problem for me)

I did create a new user, and saw success in getting debugging to work
properly.

That’s great news.

Making a permanent switch to another user account would be too
difficult at this point, as well.

Indeed, and that’s not what I’m proposing. Rather, this is a diagnostic test which shows that there’s some sort of state in your user account that’s triggering this problem. Now you just have to figure out what it is (-:

Unfortunately I don’t have any obvious suggestions for where to look, but here’s another thing you can try:
  1. Create a new user account.

  2. Log in.

  3. Take a snapshot of the files in that user account’s home directly, for example, by running find ~.

  4. Set up Xcode and run your test.

  5. Redo the snapshot as per step 3.

  6. Compare the two snapshots. This should give you a list of files that Xcode touched while building your project. You can take this knowledge back to your main account and go on a deleting spree (-:

WARNING Make a backup first, obviously (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks for the guidance on this. I've gone through the steps you've mentioned, deleting any items I found in my existing (broken) user account that I saw created in the new account (please note that I did not delete some items, as they were related to TextEdit, or other apps). However, this did not solve the issue.

Still experiencing this as of Xcode 12.2 beta 4 (12B5044c). Did anyone find a fix or have anything new to try?
The issue still happens for me with Xcode Version 12.3 beta (12C5020f). I will note that, 12.0 - 12.2 Playgrounds will not work with live view, but 12.3 does. Not sure if the issue was connected, but I did see a small "improvement" with my build machine. Will keep on with the print statements.
Decided to update my toolchains today. Moved from Xcode 12.0 to 12.2 and now I'm experiencing the same issue. Very frustrating. The same "Cannot create Swift scratch context (couldn't create a ClangImporter)" for Version 12.2 (12B45b) and Version 12.3 (12C33).