Xcode debugging cheatsheet
Breakpoints, LLDB commands and view-hierarchy tricks, kept to what ships with Xcode and nothing third-party.
This is a cheatsheet - starting point to look for things that you can do. Avoided complex / 3rd party things as they require some additional setup that may not be allowed in certain projects.
Breakpoints
- Breakpoint is user enabled point in code where the application pauses
- Line and column breakpoints
- Pauses the program before the statement on line/column is executed
- Conditions
- Execute walk method just for LadyBug:
self.bugType == 1
- Execute walk method just for LadyBug:
- Actions: Sound, Log message, Debug command
- Symbolic breakpoints: Add breakpoint on a method without source file
[UIImage systemImageNamed:]po $arg1-> Receiver objectpo $arg2->po (SEL)$arg2-> Method namepo $arg3-> First argument, and goes
- Watch points: Pauses when the value changes
LLDB commands
help: Information about commandsv: Does not compile the expression instead it just dumps value from the stackp: Evaluates and prints the outputpo: Evaluates the print debug outputdescriptionmethod- Use
[]syntax if.is failing due to typecasting
expression: Evaluates and prints, also stores the output in a variable- Expressions in other languages:
expression -l swift/objc -O -- <code>
- Expressions in other languages:
alias: Creates a shortcut for complex commandscommand alias greet p @"Hello World"
Techniques
- Inject code without building it:
expression <sample fix/feature>expr [bugs addObjectsFromArray:[[self makeAntViews:20] mutableCopy]]
- Short circuit / skip code execution:
- Move the debugger handle
thread jump --by 1
- Early return through a method:
thread return <return value>- NOTE: This does not always work and can be dangerous
- Print the view hierarchy:
po [self.view recursiveDescription] - Highlight a view:
(UIColor *)[bug setBackgroundColor:UIColor](void)[CATransition flush]: Refreshes UI
- Add delay in code:
expr [NSThread sleepForTimeInterval:2] - Auto layout debugging:
po [self.view _autolayoutTrace]
References: