【问题标题】:error: use of undeclared type '$__lldb_context' in NSAttributedString extension错误:在 NSAttributedString 扩展中使用未声明的类型“$__lldb_context”
【发布时间】:2017-06-24 04:22:36
【问题描述】:

给定以下 Swift 代码,保存在 bug.swift 中,并使用 Xcode 8.2.1 或 Xcode 8.3 beta 2:

import Foundation

protocol MyProtocol {
    func foo() -> String
}

extension MyProtocol {
    func foo() -> String {
        return "\(self)"
    }
}

extension String: MyProtocol {}
extension NSAttributedString: MyProtocol {}

let normal = "normal".foo()
let attributed = NSAttributedString(string: "attributed", attributes: [:]).foo()

运行以下命令:

swiftc -g bug.swift
lldb bug

LLDB 启动。现在,运行这些命令,并观察输出。在我传递9 的地方,传递你的bug.swift 中包含return "\(self)" 的行:

(lldb) target create "bug"
Current executable set to 'bug' (x86_64).
(lldb) b 9
Breakpoint 1: where = bug`(extension in bug):bug.MyProtocol.foo () -> Swift.String + 19 at bug.swift:9, address = 0x0000000100001e53
(lldb) run
Process 16370 launched: '/Users/zev/Desktop/bug' (x86_64)
Process 16370 stopped
* thread #1: tid = 0x31730e, 0x0000000100001e53 bug`MyProtocol.foo(self="normal") -> String + 19 at bug.swift:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100001e53 bug`MyProtocol.foo(self="normal") -> String + 19 at bug.swift:9
   6    
   7    extension MyProtocol {
   8        func foo() -> String {
-> 9            return "\(self)"
   10       }
   11   }
   12   
(lldb) po self
"normal"


(lldb) c
Process 16370 resuming
Process 16370 stopped
* thread #1: tid = 0x31730e, 0x0000000100001e53 bug`MyProtocol.foo(self=0x00007fff5fbff480) -> String + 19 at bug.swift:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100001e53 bug`MyProtocol.foo(self=0x00007fff5fbff480) -> String + 19 at bug.swift:9
   6    
   7    extension MyProtocol {
   8        func foo() -> String {
-> 9            return "\(self)"
   10       }
   11   }
   12   
(lldb) po self
error: <EXPR>:1:11: error: use of undeclared type '$__lldb_context'
extension $__lldb_context {                            
          ^~~~~~~~~~~~~~~

error: <EXPR>:18:5: error: use of unresolved identifier '$__lldb_injected_self'
    $__lldb_injected_self.$__lldb_wrapped_expr_2(     
    ^~~~~~~~~~~~~~~~~~~~~

第一次下断点,我们在String的一致性MyProtocol,我们可以成功po self

但是,我们第二次遇到断点时,我们处于 NSAttributedStringMyProtocol 的一致性,并且 LLDB 打印的是乱码,而不是来自 po self 的预期输出。

为什么 LLDB 有时无法打印有用的信息?这是一个人为的例子,但我在日常使用 LLDB 时一直遇到这个问题。

【问题讨论】:

  • 显然是一个错误。这很棘手,因为协议中的 self 没有静态类型。所以调试器只有在能够解析对象的运行时类型时才能打印self。正如您的示例所示,从 ObjC->Swift 跨越的对象并不完全是微不足道的......
  • 这个错误已经在一些最新版本的 Swift 中得到解决 ????

标签: swift lldb


【解决方案1】:

重新打开 Xcode 并清除项目后,错误消失了。

【讨论】:

    【解决方案2】:

    根据 Swift 错误报告者的this answer,该错误已在某个时候得到修复。我在 Swift 5.2 中进行了测试,并确认它已修复?

    【讨论】:

    • 按照原始问题的确切步骤,我无法重现该错误。如果你是,也许你发现了一个不同但相关的错误?如果你能找到好的重现步骤,你可以将它发布到 bugs.swift.org :)
    • 调试watchOS应用程序时发生的,调试器在这种情况下非常无用lol
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    相关资源
    最近更新 更多