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.
3. Agenda
‣ 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
‣ Resources, links and videos
7. NSLog
‣ 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)
8. NSLog optimization
‣ Use convenient macro
‣ Use string conversion functions
‣ Try alternative frameworks
10. NSLog macro
‣ 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)
20. Xcode Behaviors
‣ 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)
22. Change default Behavior
For example, when Running pauses:
‣ show the Breakpoint Navigator instead of Debug
Navigator
‣ show only Variable Views
‣ open another tab only with Console view
39. Breakpoint Action
Condition to evaluateThe num of time to ignore
breakpoint before stoping
Log Message Action
Debugger Command Action
Play sound
Continue program execution
40. Debugger Command Action
po variable
expr (void)NSLog(@”variable: %@”, variable)
breakpoint set -f ADEMasterViewController.m -l 83
41. 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/
48. Custom Summary, the solution
‣ 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
55. Network Link Conditioner
‣ 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”
58. Charles Proxy
‣ 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/
‣ http://www.charlesproxy.com
‣ Price start from US$50
61. 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.
‣ https://github.com/square/PonyDebugger
64. Deploymate
‣ 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
‣ http://www.deploymateapp.com/
‣ Price US$19.99
73. Apple Crash Reports
‣ 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
‣ https://itunesconnect.apple.com
78. 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
‣ https://code.google.com/p/plcrashreporter/
79. PLCrashReporter
- (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);
}
81. TestFlight
‣ 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.
‣ https://testflightapp.com
94. Final Thoughts
‣ 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