每当我在 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'
。请注意
-l
和 Swift
之间缺少空格。我不知道为什么“完全相同的命令”在 Xcode 中使用 LLDB 工作,即使用空间。当然,如果你输入 help expr
,你会觉得 -l Swift
应该可以工作。尽管如此,实验表明在终端中它必须是 -lSwift
(无空格)或 --language Swift
(空格),就像大多数命令行命令一样。是不是 Xcode LLDB 更宽容或遵循不同的语法规则(使用不同的解析器)?我不知道。
关于swift - 使用 LLDB 时如何修复错误 "Cannot create Swift scratch context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60311557/