23

I am trying to debug my iOS app using lldb and I'm getting really weird errors on debug.

A few lines before my breakpoint, I've got:

CGRect frame = view.frame;

Which I can access with no problems with print frame command in lldb. However, when I try to access the frame again in lldb, I type print view.frame and get the following error:

error: property 'frame' not found on object of type 'UIView *'

This doesn't make sense as I can verify the view is a UIView* instance and has a valid property called frame by typing po view and getting correct results:

(UIView *) $4 = 0x1e199bf0 <MyAppCustomView: 0x1e199bf0; frame = (3398 3396; 204 208); layer = <CALayer: 0x1e199ce0>>

This particular lldb error happens to me a lot, and I couldn't find the cause of this error. Someone suggested at Property 'count' not found on object of type 'NSMutableArray *' PO command in lldb that one could use gdb as (gdb) p view.frame but I'm getting error: '(gdb)' is not a valid command. and I highly suspect that a gdb command would "work?" inside another debugger anyway.

Any suggestions or workarounds for this bug which occurs randomly?

Community
  • 1
  • 1
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

3 Answers3

57

Dot notation for message sending is not supported in lldb when using Objective-C. Use bracket notation and cast the result to CGRect:

p (CGRect)[view frame]
Juan Boero
  • 6,281
  • 1
  • 44
  • 62
Nate Chandler
  • 4,533
  • 1
  • 23
  • 32
  • (lldb) p [view frame] error: no known method '-frame'; cast the message send to the method's return type – Can Poyrazoğlu Dec 23 '12 at 01:25
  • after the edit it worked. any reasons why I should explicityly cast it? and any ideas why it would be occuring sometimes, and otherwise, lldb is just working flawless with po/print without any casts? – Can Poyrazoğlu Dec 23 '12 at 01:27
  • 3
    @canpoyrazoğlu Because when LLDB queries the runtime, it is not aware of the types of the non-objects you want to print, casting gives it a promised type. – CodaFi Dec 23 '12 at 01:28
  • @CodaFi OK, now I'm curious. Why does LLDB really care about types? Why doesn't it just run the code and see if it works? –  May 22 '15 at 17:45
  • @ssdscott 's answer should be the accepted answer,it does not work without the outer prarentheses – inix Jul 31 '15 at 02:17
3

Just in case the above doesn't work (which it didn't for me, looking for the frame for a variable cell, class derived from UITableViewCell): forcing the extra parentheses seemed to help lldb's little ditty brain:

p ((CGRect)[cell frame])

presto magico:

(CGRect) $5 = origin=(x=0, y=0) size=(width=320, height=44)
ssdscott
  • 683
  • 6
  • 12
  • This answer should be the accepted answer since that lldb still complain without the outer parentheses. – inix Jul 31 '15 at 02:21
  • The "above" phrase in your answer can change context, point to a specific answer please. – Juan Boero Jul 31 '19 at 17:27
1

I had to disable (uncheck) Thread Sanitizer in Xcode > Product > Scheme > Edit Scheme > Run > Diagnostics. With Thread Sanitizer enabled I wasn't able to access many NSView properties (e.g. bounds, frame) through LLDB.

Andrew
  • 7,630
  • 3
  • 42
  • 51