使用 LLDB 时如何修复错误 "Cannot create Swift scratch context"

How can I fix the error "Cannot create Swift scratch context" when using LLDB

每当我在 swift 模式下 运行 LLDB 表达式时,我都会收到以下错误。

Cannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump: 0. Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb [1] 77539 segmentation fault lldb

无论我尝试导入什么都没有关系。

~ ❯❯❯ lldb
(lldb) expression -l swift -- import AppKit
Cannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
[1]    6665 segmentation fault  lldb
~ ❯❯❯ lldb                                                                                                                                                        ✘ 139
(lldb) expression -l swift -- import Foundation
Cannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
[1]    7122 segmentation fault  lldb
~ ❯❯❯ lldb                                                                                                                                                        ✘ 139
(lldb) expression -l swift -- import UIKit
Cannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
[1]    7225 segmentation fault  lldb
~ ❯❯❯                                                                                                                                                             ✘ 139

有趣的是,在 Xcode.

中使用 LLDB 时使用的命令非常相同

以下对话在我的终端中有效:

themini:~ mattneubelcap$ swift
Welcome to Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15).
Type :help for assistance.
  1> :
(lldb) expr -lSwift -- import Foundation
(lldb) expr -lSwift -- "howdy" as NSString

第二条命令成功,证明Foundation导入成功。否则,我们会收到 error: use of undeclared type 'NSString'.

请注意 -lSwift 之间缺少 space。我不知道为什么 "the very same commands" 在 Xcode 中使用 LLDB,即 space。当然,如果您键入 help expr,您会觉得 -l Swift 应该 有效。然而,实验表明,在终端中它必须是 -lSwift(没有 space)或 --language Swift(space),就像大多数命令行命令一样。可能是 Xcode LLDB 更宽容或遵循不同的语法规则(使用不同的解析器)?我不知道。