使用 LLDB 时如何修复错误“无法创建 Swift 临时上下文”

bya*_*haf 6 xcode lldb swift

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

\n\n
\n

无法创建 Swift 临时上下文(无法加载 Swift\n stdlib)无法创建 Swift 临时上下文(无法加载 Swift\n stdlib)堆栈转储:\n 0。程序参数:/Applications/Xcode.app/Contents /Developer/usr/bin/lldb [1] 77539\n 分段错误 lldb

\n
\n\n

我尝试导入什么并不重要。

\n\n
~ \xe2\x9d\xaf\xe2\x9d\xaf\xe2\x9d\xaf lldb\n(lldb) expression -l swift -- import AppKit\nCannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:\n0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb\n[1]    6665 segmentation fault  lldb\n~ \xe2\x9d\xaf\xe2\x9d\xaf\xe2\x9d\xaf lldb                                                                                                                                                        \xe2\x9c\x98 139\n(lldb) expression -l swift -- import Foundation\nCannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:\n0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb\n[1]    7122 segmentation fault  lldb\n~ \xe2\x9d\xaf\xe2\x9d\xaf\xe2\x9d\xaf lldb                                                                                                                                                        \xe2\x9c\x98 139\n(lldb) expression -l swift -- import UIKit\nCannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Stack dump:\n0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb\n[1]    7225 segmentation fault  lldb\n~ \xe2\x9d\xaf\xe2\x9d\xaf\xe2\x9d\xaf                                                                                                                                                             \xe2\x9c\x98 139\n
Run Code Online (Sandbox Code Playgroud)\n\n

有趣的是,在 Xcode 中使用 LLDB 时,命令的工作原理完全相同。

\n

mat*_*att 2

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

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
Run Code Online (Sandbox Code Playgroud)

第二个命令成功,证明Foundation导入成功。如果没有,我们就会收到error: use of undeclared type 'NSString'

-l请注意和之间缺少空格Swift。我不知道为什么“完全相同的命令”可以在 Xcode 中使用 LLDB,即使用空格。当然,如果您输入,您会得到应该help expr有效的印象。然而,实验表明,在终端中它必须是(无空格)或(空格),就像大多数命令行命令一样。难道 Xcode LLDB 更宽容或者遵循不同的语法规则(使用不同的解析器)?我不知道。-l Swift -lSwift--language Swift