LLDB (Swift): Casting Raw Address into Usable Type

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

    It took me longer to figure out that I'd like to admit. It's similar to @afinlayson answer, but with better explanation (I hope!) and fixed syntax

    If you want to check properties of an objects using Xcode’s view hierarchy debugger then this will work: You’re in objc context by default so you’ll have to switch it to Swift context

    1. First import your project (if you want to use some of the classes defined there)

    expr -l Swift -- import

    1. Cast object using it’s memory address to whatever class you want

    expr -l Swift -- let $vc = unsafeBitCast(0x7fb7c51cb270, to: ..self)

    1. Access any value you want from the object

    expr -l Swift -- print($vc.)

    Example:

    expr -l Swift -- import Football

    expr -l Swift -- let $vc = unsafeBitCast(0x7fb7c51cb270, to: Football.Ball.self)

    expr -l Swift -- print($vc.velocity)

提交回复
热议问题