Why can't LLDB print view.bounds?

后端 未结 8 2095
离开以前
离开以前 2020-12-23 16:02

Things like this drive me crazy when debugging:

(lldb) p self.bounds
error: unsupported expression with unknown type
error: unsupported expression with unkno         


        
8条回答
  •  轮回少年
    2020-12-23 16:46

    You gonna love Xcode 6.3+

    TLDR

    (lldb) e @import UIKit
    (lldb) po self.view.bounds
    

    LLDB's Objective-C expression parser can now import modules. Any subsequent expression can rely on function and method prototypes defined in the module:

    (lldb) p @import Foundation
    (lldb) p NSPointFromString(@"{10.0, 20.0}");
    (NSPoint) $1 = (x = 10, y = 20)
    

    Before Xcode 6.3, methods and functions without debug information required explicit typecasts to specify their return type. Importing modules allows a developer to avoid the more labor-intensive process of determining and specifying this information manually:

    (lldb) p NSPointFromString(@"{10.0, 20.0}");
    error: 'NSPointFromString' has unknown return type; cast the call to its declared return type
    error: 1 errors parsing expression
    (lldb) p (NSPoint)NSPointFromString(@"{10.0, 20.0}”);
    (NSPoint) $0 = (x = 10, y = 20)
    

    Other benefits of importing modules include better error messages, access to variadic functions when running on 64-bit devices, and eliminating potentially incorrect inferred argument types.

    PS: If you also confuse p vs po

    p == print == expression -- == e --
    po == expression -O -- == e -O --
    

    -- is the separator between command+flag vs inputs

    -O flag is for invoking the object description method

提交回复
热议问题