LLDB (Swift): Casting Raw Address into Usable Type

前端 未结 11 827
天涯浪人
天涯浪人 2020-11-27 09:30

Is there an LLDB command that can cast a raw address into a usable Swift class?

For example:

(lldb) po 0x7df67c50 as MKPinAnnotationView
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 09:37

    You can use Swift's unsafeBitCast function to cast an address to an object instance:

    (lldb) e let $pin = unsafeBitCast(0x7df67c50, MKPinAnnotationView.self)
    (lldb) po $pin
    

    Then you can work with $pin as usual – access properties, call methods, etc.

    Check out this article for more information: Swift Memory Dumping.

提交回复
热议问题