Search code examples
lldb

What's a proper way to print variable with a hex pointer given (Xcode 10.3, 11 betas)


Given the infamous < NSLayoutConstraint:0x1c809d970 UIView:0x11fe288b0.height == 16 (active)> & co from the autolayout engine

what's the brave new swiftly world way to print an object of UIView class by a hex pointer value?

(lldb) p *((UIView*)0x11fe288b0)

error: :3:12: error: expected ',' separator *((UIView*)0x11fe288b0) ^ ,

(lldb) po *((UIView*)0x11fe288b0)

error: :3:12: error: expected ',' separator *((UIView*)0x11fe288b0) ^ ,

(lldb) expr *((UIView*)0x11fe288b0)

error: :3:12: error: expected ',' separator *((UIView*)0x11fe288b0) ^ ,

This is in xcode 10.3 and 11 beta 3

UPD:

(lldb) p *((UIView*)0x11fe288b0)

worked at first in xcode 11 beta 5, now it ceased to work: this might have been fixed in beta 5 but possibly that fix got clobbered when I went back to xcode 10.3 that "installed additional components"

UPD2: this seems to be a duplicate of Xcode debugger (lldb) get object description from memory address


Solution

  • If the problem is just layout constraints, the simplest solution is to give your constraint a string identifier. You can do that in code or in the storyboard. Makes debugging constraints really easy; the identifier appears in quotes first thing in the debug output:

    [LayoutConstraints] Unable to simultaneously satisfy constraints.
    (
        "<NSLayoutConstraint:0x600003af86e0 'getStartedBad' ... >",
        "<NSLayoutConstraint:0x600003af8730 'getStartedTop' ... >"
    )
    

    If the question is about a UIView for which you have only the address, you can send messages to it like this:

    (lldb) expr -l objc -O -- [(UIView*)0x11fe288b0 layer]
    

    (Yes, you have to talk Objective-C to it, but I don't think there's any other way.)