SlideShare a Scribd company logo
1 of 73
Download to read offline
Massimo Oliviero
Advanced iOS Debugging


massimo.oliviero@gmail.com


        @maxoly #code12
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
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
Advanced iOS Debugging




      Code
It all began...
               Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




    NSLog(@"Array %@",
           array);
NSLog(@"URL: %@", url);
                  NSLog(@"User: %@", user);

   NSLog(@"Array: %@", array);                                                                NSLog(@"User:

                                                                      NSLog(@"User: %@", user);
         NSLog(@"URL: %@", url);
    NSLog(@"User: %@", user);


          NSLog(@"User: %@", user);                                 NSLog(@"User: %@", user);

  NSLog(@"Error :( %@", error);
    NSLog(@"Error :( %@", error);
   NSLog(@"User %@", NSLog(@"Count: %i", count);


           user);
 NSLog(@"Array: %@", array);
        NSLog(@"Error :( %@",
    NSLog(@"User: %@", user);
                                                               NSLog(@"User: %@", user);
                                                                                                   error
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)
NSLog optimization
              Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   Use convenient macro

•   Use string conversions

•   Try alternative frameworks
NSLog macro
                     Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly



MyGreatApp-prefix.pch
#if defined DEBUG
#define MYNSLog(s, ...) NSLog((@"%s [Line %d] " s), __PRETTY_FUNCTION__,
__LINE__, ##__VA_ARGS__)
#else
    #define MYNSLog(s, ...)
#endif


TestViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];

    MYNSLog(@"message");
}


Console
-[TestViewController viewDidLoad] [Line 33] message
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)
String conversion functions
               Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




AdvanceDebuggingExample.m
CGPoint point = CGPointMake(10.5f, 12.3f);
NSLog(@"point: %@", NSStringFromCGPoint(point));



Console
AdvanceDebuggingExample[3050:c07] point: {10.5, 12.3}
String conversion functions
             Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




Returns a string formatted to contain the data from a
structure:
 •   NSStringFromCGAffineTransform

 •   NSStringFromCGPoint

 •   NSStringFromCGRect

 •   NSStringFromCGSize

 •   NSStringFromUIEdgeInsets

 •   NSStringFromUIOffset
Try alternative frameworks
               Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   CocoaLumberjack
    https://github.com/robbiehanson/CocoaLumberjack


•   NSLogger
    https://github.com/fpillet/NSLogger


•   DMLogger
    https://github.com/malcommac/DMLogger
Advanced iOS Debugging




     Demo
Advanced iOS Debugging




     Xcode
Xcode
              Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   Configure your Behaviors

•   Print more information with Arguments

•   Go beyond logging with Breakpoints
Advanced iOS Debugging




   Behaviors
Xcode default Behaviors




                  Debugger bar
Xcode default Behaviors




Debugger
Navigator
               Variables View    Console
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)
Behaviors




           Show Debug Navigator
When
            Show debugger views
pauses
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
Advanced iOS Debugging




     Demo
Advanced iOS Debugging




  Arguments
Arguments



Product > Scheme > Edit Scheme > Arguments
Core Data Logging



-com.apple.CoreData.SQLDebug 1
Core Data and iCloud



-com.apple.coredata.ubiquity.logLevel 3
Advanced iOS Debugging




 Breakpoints
Creating and editing breakpoint
Breakpoint Navigator
Exception Breakpoint
Symbolic Breakpoint
Breakpoint Action
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
Debugger Command Action

                    po variable

   expr (void)NSLog(@”variable: %@”, variable)

breakpoint set -f ADEMasterViewController.m -l 83
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/
Advanced iOS Debugging




     Demo
Advanced iOS Debugging




     LLDB
Why LLDB
               Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   Consistent Command Syntax

•   Scriptability with Python

•   Performance

•   ...
LLDB Commands
             Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




                           (lldb) <command>




print object           po [object]

print variable         print [variable]

assign value           expr [variable] = [value]
LLDB Commands
                   Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




<noun> <verb> [-options [option-value]] [argument [argument...]]




   set breakpoint            breakpoint set -f [file] -l [line]

     load script             command script import ~/test.py

evaluate expression expr <expression>
Custom object, the problem

Custom object
@interface ADEEvent : NSObject

@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSDate *when;                             Init object
                                                 ADEEvent *event = [[ADEEvent alloc] init];
@end                                             event.title = @"Codemotion Conference";
                                                 event.when = [NSDate date];




         No summary for custom object
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
Custom summary
                         Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly



import lldb

def   ade_summary(valobj, internal_dict):
!     titleAsString = valobj.GetChildMemberWithName('_title').GetSummary()
!     whenAsString = valobj.GetChildMemberWithName('_when').GetSummary()
!     return 'Title: ' + titleAsString + ' - when: ' + whenAsString

def __lldb_init_module(debugger, dict):
    debugger.HandleCommand('type summary add ADEEvent -F CustomSummaries1.ade_summary')




      •   Create “ADEEvent_summary.py” in Xcode project

      •   Then load script:
          (lldb) command script import /path/to/ADEEvent_summary.py
Console tips
                            Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




(lldb) po [self.view recursiveDescription]
$7 = 0x082a2c60 <UITableView: 0x8971000; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H;
gestureRecognizers = <NSArray: 0x8184be0>; layer = <CALayer: 0x8184570>; contentOffset: {0, 0}>
   | <UITableViewCell: 0x8282900; frame = (0 176; 320 44); text = '2013-03-12 21:22:34 +0000'; autoresize = W;
layer = <CALayer: 0x8282a30>>
   |    | <UITableViewCellContentView: 0x8282a60; frame = (0 0; 300 43); gestureRecognizers = <NSArray:
0x8282c30>; layer = <CALayer: 0x8282ac0>>
   |    |    | <UILabel: 0x8282e50; frame = (10 0; 280 43); text = '2013-03-12 21:22:34 +0000'; clipsToBounds
= YES; userInteractionEnabled = NO; layer = <CALayer: 0x8282ee0>>
   |    | <UIButton: 0x8282c80; frame = (290 0; 30 43); opaque = NO; userInteractionEnabled = NO; layer = ...



(lldb) po [[UIWindow keyWindow] recursiveDescription]
$5 = 0x08273bc0 <UIWindow: 0x8181010; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x81810e0>>
    | <UILayoutContainerView: 0xd06eed0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer:
0xd071460>>
    |    | <UINavigationTransitionView: 0xd09e850; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W
+H; layer = <CALayer: 0xd09e920>>
    |    |    | <UIViewControllerWrapperView: 0x846e160; frame = (0 64; 320 504); autoresize = W+H; layer =
<CALayer: 0x846e210>>
...
Advanced iOS Debugging




     Demo
Advanced iOS Debugging




      Tools
Tools
              Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   Network Link Conditioner

•   Charles

•   PonyDebugger

•   Deploymate
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”
Network Link Conditioner
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/)
Charles
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.
PonyDebugger
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
Deploymate
Advanced iOS Debugging




     Demo
Advanced iOS Debugging




    Remote
Remote debugging
                 Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly




•   Apple Crash Reports

•   PLCrashReporter

•   TestFlight
Advanced iOS Debugging




Apple Crash Reports
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
Apple Crash Reports
Apple Crash Reports
Xcode Symbolication
Advanced iOS Debugging




PLCrashReporter
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
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);

}
Advanced iOS Debugging




   TestFlight
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.
TestFlight Apps Managment
TestFlight Crashes
Advanced iOS Debugging




Final Thoughts
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
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

More Related Content

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Advanced iOS debbuging

  • 1. Massimo Oliviero Advanced iOS Debugging massimo.oliviero@gmail.com @maxoly #code12
  • 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
  • 5. It all began... Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly NSLog(@"Array %@", array); NSLog(@"URL: %@", url); NSLog(@"User: %@", user); NSLog(@"Array: %@", array); NSLog(@"User: NSLog(@"User: %@", user); NSLog(@"URL: %@", url); NSLog(@"User: %@", user); NSLog(@"User: %@", user); NSLog(@"User: %@", user); NSLog(@"Error :( %@", error); NSLog(@"Error :( %@", error); NSLog(@"User %@", NSLog(@"Count: %i", count); user); NSLog(@"Array: %@", array); NSLog(@"Error :( %@", NSLog(@"User: %@", user); NSLog(@"User: %@", user); error
  • 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
  • 8. NSLog macro Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly MyGreatApp-prefix.pch #if defined DEBUG #define MYNSLog(s, ...) NSLog((@"%s [Line %d] " s), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else #define MYNSLog(s, ...) #endif TestViewController.m - (void)viewDidLoad { [super viewDidLoad]; MYNSLog(@"message"); } Console -[TestViewController viewDidLoad] [Line 33] message
  • 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)
  • 10. String conversion functions Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly AdvanceDebuggingExample.m CGPoint point = CGPointMake(10.5f, 12.3f); NSLog(@"point: %@", NSStringFromCGPoint(point)); Console AdvanceDebuggingExample[3050:c07] point: {10.5, 12.3}
  • 11. String conversion functions Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly Returns a string formatted to contain the data from a structure: • NSStringFromCGAffineTransform • NSStringFromCGPoint • NSStringFromCGRect • NSStringFromCGSize • NSStringFromUIEdgeInsets • NSStringFromUIOffset
  • 12. Try alternative frameworks Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly • CocoaLumberjack https://github.com/robbiehanson/CocoaLumberjack • NSLogger https://github.com/fpillet/NSLogger • DMLogger https://github.com/malcommac/DMLogger
  • 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
  • 17. Xcode default Behaviors Debugger bar
  • 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
  • 24. Arguments Product > Scheme > Edit Scheme > Arguments
  • 26. Core Data and iCloud -com.apple.coredata.ubiquity.logLevel 3
  • 27. Advanced iOS Debugging Breakpoints
  • 28. Creating and editing breakpoint
  • 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/
  • 38. Why LLDB Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly • Consistent Command Syntax • Scriptability with Python • Performance • ...
  • 39. LLDB Commands Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly (lldb) <command> print object po [object] print variable print [variable] assign value expr [variable] = [value]
  • 40. LLDB Commands Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly <noun> <verb> [-options [option-value]] [argument [argument...]] set breakpoint breakpoint set -f [file] -l [line] load script command script import ~/test.py evaluate expression expr <expression>
  • 41. Custom object, the problem Custom object @interface ADEEvent : NSObject @property (nonatomic, strong) NSString *title; @property (nonatomic, strong) NSDate *when; Init object ADEEvent *event = [[ADEEvent alloc] init]; @end event.title = @"Codemotion Conference"; event.when = [NSDate date]; No summary for custom object
  • 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
  • 43. Custom summary Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly import lldb def ade_summary(valobj, internal_dict): ! titleAsString = valobj.GetChildMemberWithName('_title').GetSummary() ! whenAsString = valobj.GetChildMemberWithName('_when').GetSummary() ! return 'Title: ' + titleAsString + ' - when: ' + whenAsString def __lldb_init_module(debugger, dict): debugger.HandleCommand('type summary add ADEEvent -F CustomSummaries1.ade_summary') • Create “ADEEvent_summary.py” in Xcode project • Then load script: (lldb) command script import /path/to/ADEEvent_summary.py
  • 44. Console tips Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly (lldb) po [self.view recursiveDescription] $7 = 0x082a2c60 <UITableView: 0x8971000; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8184be0>; layer = <CALayer: 0x8184570>; contentOffset: {0, 0}> | <UITableViewCell: 0x8282900; frame = (0 176; 320 44); text = '2013-03-12 21:22:34 +0000'; autoresize = W; layer = <CALayer: 0x8282a30>> | | <UITableViewCellContentView: 0x8282a60; frame = (0 0; 300 43); gestureRecognizers = <NSArray: 0x8282c30>; layer = <CALayer: 0x8282ac0>> | | | <UILabel: 0x8282e50; frame = (10 0; 280 43); text = '2013-03-12 21:22:34 +0000'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x8282ee0>> | | <UIButton: 0x8282c80; frame = (290 0; 30 43); opaque = NO; userInteractionEnabled = NO; layer = ... (lldb) po [[UIWindow keyWindow] recursiveDescription] $5 = 0x08273bc0 <UIWindow: 0x8181010; frame = (0 0; 320 568); layer = <UIWindowLayer: 0x81810e0>> | <UILayoutContainerView: 0xd06eed0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0xd071460>> | | <UINavigationTransitionView: 0xd09e850; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W +H; layer = <CALayer: 0xd09e920>> | | | <UIViewControllerWrapperView: 0x846e160; frame = (0 64; 320 504); autoresize = W+H; layer = <CALayer: 0x846e210>> ...
  • 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
  • 58. Remote debugging Massimo Oliviero - massimo.oliviero@gmail.com - www.massimooliviero.net - @maxoly • Apple Crash Reports • PLCrashReporter • TestFlight
  • 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