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是打开的。我检查了一下,看看是不是这个问题。结果没有区别。
解决
我在这篇文章中找到了答案:
我未能设置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)