LLDB Tips
Three tips that make debugging easier.
Step faster
Stepping over/into in the debugger can be really slow. Turns out that Debug navigator is the main culprit here. If it gets slow just hide navigator pane (⌘+0) or change to different navigator and enjoy full speed 1.
Print bounds/frame like a normal person
Checking view’s bounds in LLDB by default produces this error:
(lldb) po self.view.bounds
error: property 'bounds' not found on object of type 'UIView *'
error: 1 errors parsing expression
There’s a bunch of workarounds for this. Most sane one was added in Xcode 6.3 with LLDB enchancements: expression parser can now import modules.
(lldb) e @import UIKit
(lldb) po self.view.bounds
(origin = (x = 0, y = 0), size = (width = 320, height = 548))
(origin = (x = 0, y = 0), size = (width = 320, height = 548))
Entering import at the start of each debugging session gets tedious very quickly. To streamline this use Symbolic Breakpoint in a fashion similar to this Reveal tutorial. Go to Debuger pane and add Symbolic Breakpoint pointing to UIApplicationMain
(it’s guaranteed to run only once), add e @import UIKit
action and set it to automatically continue after evaluating. Using breakpoint’s context menu: Move Breakpoint To -> User
, make it an user breakpoint and enjoy it in every project from now on 2.
Breakpoint by regular expression on function name
Use case for this can be for example setting a breakpoint on all isEqual
implementations:
(lldb) breakpoint set --func-regex isEqual
Shorthand:
(lldb) br s -r isEqual
To view all added locations:
(lldb) br list
...
5: regex = 'isEqual', locations = 428, resolved = 428, hit count = 0
5.1: where = Foundation`-[NSKeyValueObservance isEqual:], address = 0x00148904, resolved, hit count = 0
5.2: where = Foundation`-[NSString isEqual:], address = 0x0014f622, resolved, hit count = 0
5.3: where = Foundation`-[NSString isEqualToString:], address = 0x0014f67e, resolved, hit count = 0
5.4: where = Foundation`_isEqualCString, address = 0x0014fdae, resolved, hit count = 0
5.5: where = Foundation`-[NSPathStore2 isEqualToString:], address = 0x0014feef, resolved, hit count = 0
5.6: where = Foundation`-[NSURL(NSURL) isEqual:], address = 0x00170f37, resolved, hit count = 0
Disabling and deleting all locations for such breakpoint:
(lldb) br disable 5
(lldb) br delete 5
-
Can't really remember where I've picked up this tip. ↩
</li>
-
Tip via this Tweet. It's also worth to change Exception Breakpoint to an User one. ↩
</li> </ol></div>