LLDB (Swift): Casting Raw Address into Usable Type

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

    @Xi Chen's answer works perfectly when your LLDB session was started in a Swift context. However, in some cases you might have stopped in a breakpoint outside a Swift context; for example, when it's a symbolic breakpoint to Objective-C API, or when in Debug View Hierarchy mode (at least as of Xcode 11.4).

    error: unknown type name 'let'
    error: use of undeclared identifier 'unsafeBitCast'
    

    In that case, you'll need to do it the old way using Objective-C:

    e MKPinAnnotationView *$pin = (MKPinAnnotationView *)0x7df67c50
    

    and now you can use $pin as you would.

提交回复
热议问题