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

标签 swift xcode 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 之间缺少空格。我不知道为什么“完全相同的命令”在 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/

相关文章:

iOS 13 : Searchbar crashing when cancel is hit repeatedly

iOS - 由于 'val' 保护级别(来 self 的 pod), 'internal' 无法访问

debugging - 配合使用带有Rust的vscode调试控制台

xcode - 查看 LLDB 中的数组 : equivalent of GDB's '@' operator in Xcode 4. 1

java - 值类型困惑

ios - Metal (iOS) 中的多重采样/锯齿状边缘

ios - SKSpriteNode 在碰撞时失去速度

iphone - 在 UITableViewCell 中访问 UITextField

xcode - 将数据从 TableViewCell 标签传递到 ViewController 时遇到问题

c++ - 在 LLDB 类型摘要中显示 C++ 类成员