lldb 错误:无法查找符号。迅捷iOS

rus*_*net 7 debugging lldb swift

使用 lldb,我想在我的发布 iOS 构建和发布动态框架中实例化一个 Swift 类。

我在模拟器上将 lldb 附加到我的发布版本。

主应用程序 - 有效

(lldb) exp let $c = hello_class()
error: <EXPR>:3:10: error: use of unresolved identifier 'hello_class'
let $c = hello_class()
         ^~~~~~~~~~~
(lldb) expr import My_App
(lldb) exp let $c = hello_class()
(lldb) po $c.hello()
 hello 
Run Code Online (Sandbox Code Playgroud)

动态框架 - 失败

(lldb) dclass -m myframework
Dumping classes
************************************************************
myframework.RustyAppInfo

(lldb) expr import myframework
(lldb) expr let $d = RustyAppInfo()
error: Couldn't lookup symbols:
  __T011myframework12RustyAppInfoCACycfC
Run Code Online (Sandbox Code Playgroud)

应用程序和动态框架都是在没有优化的情况下构建的。

更新

静态框架 - 失败

更改时的结果相同 - Xcode 9 引入的功能 - 静态 Swift 框架。

Xcode - 死代码剥离

默认情况下,使用 Swift 代码Dead Code Stripping是打开的。我检查了一下,看看是不是这个问题。结果没有区别。

rus*_*net 2

解决

我在这篇文章中找到了答案:

http://iosbrain.com/blog/2018/01/13/building-swift-4-frameworks-and-include-them-in-your-apps-xcode-9/

我未能设置public init()框架内的 Swift 类。lldb 可以调用的工作代码:

// set the Framework class to Public
public class rnHello{  

   // set the initializer to public, otherwise you cannot invoke class
    public init() {  

    }

    // set the function to public, as it defaults to internal
    public static func world() {  
        print("hello from a static method")
    }
}
Run Code Online (Sandbox Code Playgroud)

现在您可以通过 Swift 代码或使用 lldb 访问它:

(lldb) po rnHello.world()
hello from a static method
Run Code Online (Sandbox Code Playgroud)

  • 请注意,问题不在于该方法本身是私有的。lldb 的表达式解析器可以调用方法,无论它们是公共的还是私有的。这里的问题是,由于 init 不是公开的,编译器知道它可以推断其所有用途,因此不需要发出未使用的风格,包括从 lldb 生成对象所需的风格。当您公开 init 时,swift 无法再推理其用途,而是必须发出任何可能被调用的内容。 (6认同)