LLDB (Swift): Casting Raw Address into Usable Type

前端 未结 11 766
天涯浪人
天涯浪人 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:52

    Objective-C version

    po ((MKPinAnnotationView *)0x7df67c50).alpha
    
    0 讨论(0)
  • 2020-11-27 09:57

    For Custom Classes you need to import your project

    expr -l Swift -- import MyTestProject
    expr -l Swift --  let $vc = unsafeBitCast(0x7fad22c066d0, ViewController.self)
    expr -l Swift -- print($vc.view)
    
    0 讨论(0)
  • 2020-11-27 09:58

    As of Xcode 8/Swift 3, here's what worked for me. (This is based off @sfaxon's answer.)

    (lldb) expr -l Swift -- import UIKit
    (lldb) expr -l Swift -- let $nav = unsafeBitCast(0x1030ff000, to: UINavigationController.self)
    
    0 讨论(0)
  • 2020-11-27 09:59

    The easiest way, swift 4

    expr unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
    
    0 讨论(0)
  • 2020-11-27 10:01

    Under Xcode 8.2.1 and Swift 3, the lldb command po or p won't work with the typed variable. You will need to use the swift command print to examine the properties of the typed object instance. (Thanks to cbowns's answer!) E.g.:

    expr -l Swift -- import UIKit
    expr -l Swift -- let $pin = unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
    expr -l Swift -- print($pin.alpha)
    
    0 讨论(0)
提交回复
热议问题