Why can't LLDB print view.bounds?

Things like this confuse me when debugging:

(lldb) p self.bounds error: unsupported expression with unknown type error: unsupported expression with unknown type error: 2 errors parsing expression (lldb) p (CGRect)self.bounds error: unsupported expression with unknown type error: unsupported expression with unknown type error: C-style cast from '<unknown type>' to 'CGRect' is not allowed error: 3 errors parsing expression (lldb) p [self bounds] error: 'bounds' has unknown return type; cast the call to its declared return type error: 1 errors parsing expression (lldb) p (CGRect)[self bounds] (CGRect) $1 = origin=(x=0, y=0) size=(width=320, height=238) (lldb) You suck! error: 'You' is not a valid command. (lldb) … 

Why did the first 3 attempts fail? Is there an easier way to print self.bounds ? Thank.

+47
objective-c lldb
Sep 19 '13 at 2:16
source share
8 answers

Starting with Xcode 6.3, we have a better solution. In short, you need to import UIKit for LLDB to learn about these types: expr @import UIKit . Check out this article to learn some tricks to make your life even easier.

+34
May 18 '15 at 21:01
source share

You can access it

 p (CGRect)[view bounds] 

or

 p view.layer.bounds 



view.bounds is actually view.layer.bounds

It seems that type information [UIView bounds] not available lldb

+49
Sep 20 '13 at 18:02
source share

You will love Xcode 6.3+

TL; DR

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

LLDB Objective-C expression parser can now import modules. Any subsequent expression may be based on prototypes of functions and methods defined in the module:

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

Prior to Xcode 6.3, methods and functions without debugging information required explicit tricks to indicate their return type. Import modules allow the developer to avoid the more laborious process of defining 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 advantages of import modules include improved error messages, access to variational functions when working on 64-bit devices, and eliminating potentially incorrect valid argument types.

PS : If you also confuse p vs po

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

-- is a separator between command+flag vs inputs

-O flag is for calling the description method

+9
Aug 30 '15 at 3:11
source share

LLDB does not support dot notation for sending messages when using p and that

 p self.bounds 

doesn't work but

 p [self bounds] 

does.

(It actually supports it for objects when you use po , though)

In addition, LLDB does not have information about the type of non-objects available at run time, so you need to explicitly specify the type by specifying the return value.

+6
Sep 19 '13 at 3:45
source share

With Xcode 6.3 we can import UIKit and then print a frame or view frame

 expr @import UIKit p self.view.bounds 
+6
May 18 '15 at 20:12
source share

I do not know what the context was when you run this. But it looks like lldb cannot find the type self .

For lldb to evaluate self.bounds , it needs to know that the type self is some class that has the bounds property. It cannot assume that self is an ObjC type, because you can name it in this context:

 void test() { struct { int bounds; } self; } 

so that you get the error message error: unsupported expression with unknown type

However, if you call it using [self bounds] , lldb knows that self will be a lot of ObjC type, because the syntax [] applies only to the ObjC type. But since the self type is not clear, it still cannot evaluate the result of [self bounds] , so you need to pass it to CGRect

0
Sep 19 '13 at 3:47
source share

Try the following expression,

 p self.view.bounds.size.width 

or use

 po self.view 

p - Print is used only for printing ordinary / simple values ​​while, po - The print object works the same as NSLog for printing the value of an object

0
Sep 11 '14 at 11:58 a.m.
source share

I tried @ an0 answer expr @import UIKit , but that didn't work.

Then I added the pch file and add these lines of code to the file:

 #ifndef PrefixHeader_pch #define PrefixHeader_pch #ifdef __OBJC__ #import <UIKit/UIKit.h> #endif #endif /* PrefixHeader_pch */ 

Then link the pch file to my project:

enter image description here

Run the application again, then I can use dot notation in the lldb console:

 (lldb) po self.view.bounds 

How to add pch file, see answer here PCH file in Xcode 6

0
30 Oct '16 at 11:45
source share



All Articles