LLDB(Swift):在Xcode 9 iOS模拟器/设备中将原始内存地址转换为可用类型[重复]

问题描述 投票:0回答:1

在Xcode 9中调试iOS应用程序时,如何在lldb中投射指向已知Swift对象类型的指针?

我试图在Swift中打印一个对象的描述,给出它在Xcode 9 / iOS 11 SDK中的内存地址。我一直在使用这里描述的技术:LLDB (Swift): Casting Raw Address into Usable Type(注意:这种技术在调试macOS应用程序时工作正常。)

(lldb) p unsafeBitCast(0x00006080000e2280, to: UIViewController.self)

但是在调试iOS应用程序时在Xcode 9中的lldb中键入类似的语句会产生以下错误消息:

error: use of undeclared identifier 'to'。或者删除“to:”部分:

error: use of undeclared identifier 'unsafeBitCast'

我搜索了替换Swift unsafeBitCast()方法的文档,但我没有发现它的弃用。这是lldb / Swift iOS运行时中的错误吗?

破碎:Xcode 9 + iOS 11模拟器,Xcode 9 + iOS 9.x模拟器,Xcode 9 + iOS 9.x设备 工作:Xcode 8 + iOS模拟器/设备,Xcode 9 + macOS 10.12应用程序

感谢您的见解。

swift xcode lldb
1个回答
1
投票

您可以从内存地址创建UnsafeMutablePointer并使用指针pointee属性检索对象:

let object = UnsafeMutablePointer<NSTabViewController>(bitPattern: yourMemoryAddress)?.pointee
© www.soinside.com 2019 - 2024. All rights reserved.