Xcode Debugging Reference
LLDB commands, breakpoints, and view debugging techniques for iOS/macOS development.
LLDB Quick Reference
Basic Commands
# Print variable
po myVariable
p myVariable
# Print with format
p/x myInt # Hexadecimal
p/t myInt # Binary
p/d myInt # Decimal
# Print object description
po self
po myArray
# Expression evaluation
expr myVariable = 5
expr self.isLoading = trueInspecting Objects
# Print all properties
po self.debugDescription
# Print specific property
po self.viewModel.state
# Print array contents
po myArray.map { $0.name }
# Print dictionary
po myDict.keys
po myDict["key"]SwiftUI Debugging
# Print view hierarchy (from any breakpoint in a View)
po Self._printChanges()
# Check @State value
po _myStateVariable.wrappedValue
# Check @Binding
po _myBinding.wrappedValueMemory Inspection
# Check memory address
p unsafeBitCast(myObject, to: Int.self)
# Check reference count
po CFGetRetainCount(myObject as CFTypeRef)
# Print type
po type(of: myObject)Breakpoint Techniques
Conditional Breakpoints
- Set breakpoint (click line number gutter)
- Right-click breakpoint > Edit Breakpoint
- Add condition:
myVariable == 5myArray.count > 10self.state == .loading
Action Breakpoints
Execute code without stopping:
- Edit Breakpoint
- Add Action > Debugger Command
- Enter:
po "Value is: \(myVariable)" - Check "Automatically continue"
Exception Breakpoints
Catch crashes before they happen:
- Debug Navigator > + button
- Add Exception Breakpoint
- Choose: All Exceptions or Objective-C only
Symbolic Breakpoints
Break on any method call:
- Debug Navigator > + button
- Add Symbolic Breakpoint
- Symbol:
-[UIViewController viewDidLoad] - Or:
UIApplication.shared
View Debugging
Debug View Hierarchy
- Run app
- Debug > View Debugging > Capture View Hierarchy
- Or click cube icon in debug toolbar
What to Look For
- Overlapping views - Views stacked unexpectedly
- Constraint issues - Ambiguous layout warnings
- Hidden views - Views with alpha 0 or isHidden true
- Off-screen content - Views positioned outside bounds
Runtime Attribute Inspection
In the view debugger:
- Select view in 3D hierarchy
- Object Inspector shows all properties
- Check frame, bounds, constraints
View Debugging Commands
# Print view hierarchy
po self.view.recursiveDescription()
# Print responder chain
po self.responderChain()
# Highlight view (in simulator)
expr self.view.layer.borderWidth = 2
expr self.view.layer.borderColor = UIColor.red.cgColorNetwork Debugging
Print Network Requests
// Add to URLSession configuration
#if DEBUG
URLSession.shared.configuration.protocolClasses?.insert(NetworkLogger.self, at: 0)
#endifLLDB Network Inspection
# Print URL request
po request.url
po request.httpMethod
po String(data: request.httpBody ?? Data(), encoding: .utf8)
# Print response
po response.statusCode
po String(data: responseData, encoding: .utf8)Thread Debugging
Check Current Thread
# Print current thread
thread info
# Print all threads
thread list
# Print backtrace
bt
bt allMain Thread Checker
Enable in scheme:
- Edit Scheme > Run > Diagnostics
- Check "Main Thread Checker"
Catches UI updates from background threads.
Performance Debugging
Time Profiler in LLDB
# Measure execution time
expr let start = CFAbsoluteTimeGetCurrent()
# ... execute code ...
expr print("Time: \(CFAbsoluteTimeGetCurrent() - start)")Memory Debugging
Enable in scheme:
- Edit Scheme > Run > Diagnostics
- Check "Malloc Stack Logging"
- Check "Zombie Objects" (for EXC_BAD_ACCESS)
Common Debugging Scenarios
Scenario: View Not Appearing
# Check if view is in hierarchy
po self.view.superview
# Check frame
po self.view.frame
# Check if hidden
po self.view.isHidden
po self.view.alpha
# Check constraints
po self.view.constraintsScenario: Button Not Responding
# Check if user interaction enabled
po button.isUserInteractionEnabled
# Check if enabled
po button.isEnabled
# Check gesture recognizers
po button.gestureRecognizers
# Check if obscured
po self.view.hitTest(touchPoint, with: nil)Scenario: Data Not Loading
# Check network reachability
po NetworkMonitor.shared.isConnected
# Check API response
po lastResponse?.statusCode
po String(data: lastResponseData, encoding: .utf8)
# Check decoding
expr try JSONDecoder().decode(MyModel.self, from: data)Useful Xcode Shortcuts
| Action | Shortcut |
|---|---|
| Toggle breakpoint | Cmd + \ |
| Step over | F6 |
| Step into | F7 |
| Step out | F8 |
| Continue | Cmd + Ctrl + Y |
| View debugger | Cmd + Shift + D |
| Memory graph | Cmd + Shift + M |
| Debug navigator | Cmd + 7 |
Debug Console Tips
# Clear console
Cmd + K
# Search console output
Cmd + F
# Copy console selection
Cmd + C
# Increase console font
Cmd + + (plus)Verification Checklist
After debugging session:
- Remove debug print statements
- Disable unnecessary breakpoints
- Turn off diagnostic options in scheme (for production)
- Remove any
exprmodifications made during debugging