The debug process constitutes an important part in an app's development cycle. Knowing the (right) tools and techniques means you can optimizes time and therefore costs. In this session we will see a number of techniques to optimize debugging of iOS applications exploiting the power of Xcode, LLDB and other support tools.
2. Massimo Oliviero
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
Freelance Software Developer
Co-founder of #pragma mark http://pragmamark.org
Online
web http://www.massimooliviero.net
email massimo.oliviero@gmail.com
twitter @maxoly
slide http://www.slideshare.net/MassimoOliviero
3. Agenda
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Code, some tips for standard functions
• Xcode, the best tools for debugging
• LLDB, your great friend
• Tools, network debugging how to and more
• Remote, over the air debugging
6. NSLog
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• It prints debugs output only to the console
• It’s a simple native Foundation function
• It’s not too bad, but It’s an ancient technique
• It slows things down considerably (if not handled)
7. NSLog optimization
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Use convenient macro
• Use string conversions
• Try alternative frameworks
9. NSLog macro
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Enables DEBUG mode output only
• Outputs function name and line number
• Place macro into .pch file or in a header file
• You can use other macros like __ FILE__ (for example)
15. Xcode
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Configure your Behaviors
• Print more information with Arguments
• Go beyond logging with Breakpoints
19. Xcode Behaviors
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Match Xcode to your Workflow
• Use Behaviors to control Xcode
• Behaviors lets you specify what should happen when a
variety of events occur (like Run)
20. Behaviors
Show Debug Navigator
When
Show debugger views
pauses
21. Change default Behavior
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
For example, when Running pauses:
• show the Breakpoint Navigator instead of Debug Navigator
• show only Variable Views
• open another tab only with Console view
33. Breakpoint action
Condition to evaluate
The num of time to ignore
breakpoint before stoping
Log Message Action
Debugger Command Action
Play sound
Continue program execution
34. Debugger Command Action
po variable
expr (void)NSLog(@”variable: %@”, variable)
breakpoint set -f ADEMasterViewController.m -l 83
35. Sharing Breakpoint
Share breakpoints with the team, so that all can benefit from it
This action will create a new directory to be committed in the repository
AdvanceDebuggingExample.xcodeproj/xcshareddata/
42. Custom summary
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Create a Python script that will instruct LLDB on how to
display a summary of your custom object
• Load your Python script via command line or ~/.lldbinit
file
47. Tools
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Network Link Conditioner
• Charles
• PonyDebugger
• Deploymate
48. Network Link Conditioner
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• It’s a utility that enables you to simulate network
conditions
• To install just select Xcode > Open Developer Tool >
More Developer Tools.You’ll be taken to Apple’s developer
downloads site
• Download “Hardware IO Tools for Xcode”
50. Charles
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
http://www.charlesproxy.com/
• It’s a web debugging proxy
• You can inspect, modify and record requests & responses
• SSL Proxing (http://www.charlesproxy.com/
documentation/faqs/ssl-connections-from-within-iphone-
applications/)
52. PonyDebugger
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
https://github.com/square/PonyDebugger
• Network Traffic Debugger
• Core Data Browser
• It is a client library and gateway server combination that
uses Chrome Developer Tools on your browser to debug
your application's network traffic and managed object
contexts.
54. Deploymate
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• If using an API introduced later than your target OS but
your app is targeting an older OS version, Xcode doesn't
warn you about it
• It helps identify unavailable, deprecated and obsolete API
60. Apple Crash Reports
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
https://itunesconnect.apple.com
• For app published on App Store, you can acquire crash log
from iTunes Connect and import it into Organizer for
symbolication
• To symbolicate a crash log, Xcode needs to have access to
the matching application binary that was uploaded to the
App Store, and the .dSYM file that was generated when
that binary was built. This must be an exact match
65. PLCrashReporter
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
https://code.google.com/p/plcrashreporter/
• In-process CrashReporter framework for the iPhone and
Mac OS X
• Handles both uncaught Objective-C exceptions and fatal
signals
• Backtraces for all active threads are provided
66. Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
- (void) handleCrashReport {
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSData *crashData;
NSError *error;
// Try loading the crash report
crashData = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
if (crashData == nil) {
NSLog(@"Could not load crash report: %@", error);
goto finish;
}
PLCrashReport *report = [[[PLCrashReport alloc] initWithData: crashData error: &error] autorelease];
if (report == nil) {
NSLog(@"Could not parse crash report");
goto finish;
}
....
return;
}
// from UIApplicationDelegate protocol
- (void) applicationDidFinishLaunching: (UIApplication *) application {
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error;
// Check if we previously crashed
if ([crashReporter hasPendingCrashReport])
[self handleCrashReport];
// Enable the Crash Reporter
if (![crashReporter enableCrashReporterAndReturnError: &error])
NSLog(@"Warning: Could not enable crash reporter: %@", error);
}
68. TestFlight
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
https://testflightapp.com/
• Invite your testers, drop in the SDK and start uploading
your builds.
• Upload your builds and TestFlight takes care of the rest.
Painless over-the-air distribution to your testers and
distribution lists.
• Complete tracking of your build, from distribution to
sessions, checkpoints and crashes.
72. Final Thoughts
Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly
• Don’t use NSLog anymore ;)
• Create your Xcode Behaviors
• Breakpoints are your friends
• LLDB is a promising youngster
• Tools can save your life
• The QA phase is essential
73. Advanced iOS Debugging
Thank you!
Massimo Oliviero
massimo.oliviero@gmail.com
http://www.massimooliviero.net
follow me on twitter @maxoly
http://www.slideshare.net/MassimoOliviero
https://speakerdeck.com/massimooliviero