LLDB (Swift): Casting Raw Address into Usable Type

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

    Thanks to all the answers above, unsafeBitCast also works well with Xcode 8.3.2 / Swift 3 / macOS / Cocoa Application.

    Memorize an address of current instance

    (lldb) p tabView.controlTint
    (NSControlTint) $R10 = defaultControlTint
    
    (lldb) p self
    (LearningStoryboard.NSTabViewController) $R11 = 0x00006080000e2280 {
    .....
    

    Later, examine them

    (lldb) p unsafeBitCast(0x00006080000e2280, to: NSTabViewController.self).tabView.controlTint
    (NSControlTint) $R20 = graphiteControlTint
    
    (lldb) p $R11.tabView.controlTint
    (NSControlTint) $R21 = graphiteControlTint
    

    If something like this happens

    (lldb) p unsafeBitCast(0x00006080000e2280, to: NSTabViewController.self).tabView.controlTint
    error: use of undeclared identifier 'to'
    
    (lldb) p $R11.tabView.controlTint 
    error: use of undeclared identifier '$R11'
    

    make sure that choose one of the stack frames of Swift source code rather than assembler one.

    It is likely to happen when the application was paused by clicking a Pause button or stopped with an exception. By choosing a stack frame accordingly, let lldb infer a proper programing language.

提交回复
热议问题