Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import UIKit for debugging Objective-C by default

Whenever I try to read the frame of an UIView for example while debugging, I get this error:

error: property 'frame not found on object of type 'UIView *'
error: 1 errors parsing expression

After searching for a solution, I found out that I can use this command to solve this without adding (annoying and in some cases complicated) casts:

expr @import UIKit;

But I still find it annoying to have to do this every time (why doesn't Xcode do this by default?!), so I thought I should be able to do this using the .lldbinit file, but I couldn't get it to work.

I don't know much about that file, I have this in it atm:

command script import /usr/local/opt/chisel/libexec/fblldb.py

so I tried adding the UIKit import command at the end of the file but it didn't look that it worked. I also tried prefixing it with command to no avail. Is this possible or not? (please say yes; it will save my life)

like image 412
Iulian Onofrei Avatar asked Jul 20 '15 08:07

Iulian Onofrei


1 Answers

lldb will auto-import modules that the debug info tells us the program imports fairly soon now. All the pieces weren't in place to do that for the first Xcode 7 releases.

Statements in the .lldbinit get run before the main file is read in, it is supposed to help set up the environment to read in your program. But at that point there's nothing into which to import these symbols. You need to do it after the main binary is read in (and you really need to do it after you have run, since I think we need to run some code to do this.)

At present, the simplest way to do this is to make an auto-continue breakpoint at main, and attach the expr @import UIKit statement as a debugger command in that breakpoint. You'll have to do this once per new project you make, but if you're working on the same project for a while, it's not such an inconvenient workaround.

like image 167
Jim Ingham Avatar answered Sep 28 '22 03:09

Jim Ingham