Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging in Xcode

Debugging in Xcode

Debugging in Xcode
Speaker: Hrishikesh Devhare

No developer 👨‍💻 is excited when someone comes to them with a list of bugs. 😒 But everyone has to 🔍debug the code. Let’s discuss hidden gems 💎in Xcode’s breakpoints, watchpoints and visual debugger and LLDB to squash those bugs 🔨and ship 🛳 your app. 😇

Talk Video: https://www.youtube.com/watch?v=fkoC0qyQnGg

Talk presented at Swift Mumbai Chapter 8 Meetup at Eros Now on April 13, 2019
https://www.meetup.com/Swift-Mumbai/events/259194853/

Twitter: https://twitter.com/hrishiD
Presented at Swift Mumbai Chapter 8 Meetup hosted by Eros Now
https://www.meetup.com/Swift-Mumbai/events/259194853/

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

April 13, 2019
Tweet

Transcript

  1. Debugging in Xcode Hrishikesh Devhare

  2. None
  3. Avoid Debugging

  4. None
  5. Avoid Debugging • Static Analyser • Run Time Tools •

    Assertions • Enums
  6. Static Analyser

  7. Finds following types of Bugs • Logic Flaws • Memory

    Management flaws • Dead Store • API Usage flaws Static Analyser
  8. Static Analyser •Product -> Analyse • Issue Navigator

  9. Static Analyser • Build Settings • Won’t cover all scenarios

    • Possibility of false positive • WWDC 2016 Session 412 
 Thread Sanitizer and Static Analysis
  10. Run Time Tools

  11. Run Time Tools

  12. Run Time Tools

  13. • Main Thread Sanitiser • Thread Sanitiser • Address Sanitiser

    • Undefined Behaviour Sanitiser Run Time Tools
  14. Main Thread Sanitizer

  15. Main Thread Sanitizer

  16. • UI Updates on Main Thread • Creation and removal

    of UI Elements • Ready to use • WWDC 2017 Session 404
 Finding Bugs Using Xcode Runtime Tools Main Thread Sanitizer
  17. Thread Sanitiser • Detects Data race • Threading bugs e.g.

    uninitialized mutexes and thread leaks • Use Dispatch API • WWDC 2016 Session 412 
 Thread Sanitizer and Static Analysis
  18. Thread Sanitiser Limitations • Supported only for 64-bit macOS and

    64-bit iOS and tvOS simulators. • watchOS is not supported • Can not use on when running apps on a device. • Performance Impact • increase in memory usage by 5⨉ to 10⨉ • CPU slowdown of 2⨉ to 20⨉
  19. • Detects memory corruption • Use ARC • WWDC 2015

    Session 413 
 Advanced Debugging and the Address Sanitizer Address Sanitiser
  20. • Dividing by zero • Loading memory from a misaligned

    pointer • Dereferencing a null pointer • WWDC 2017 Session 404
 Finding Bugs Using Xcode Runtime Tools Undefined Behaviour Sanitiser
  21. Swift Objective C Require 
 recompilation? Main Thread Sanitizer ✅

    ✅ ❌ Thread Sanitizer ✅ ✅ ✅ Address Sanitizer ✅ ✅ ✅ Undefined Behaviour
 Sanitizer ❌ ✅ ✅ Run Time Tools
  22. • Build Settings available for ASan & UBSan • https://developer.apple.com/documentation/

    code_diagnostics Run Time Tools
  23. Assertions

  24. • Assert / Assert Failure • Pre conditions /Precondition Failures

    • Fatal Error Assertions
  25. None
  26. Enums

  27. • Enums for finite states • Enums for string constants

    Enums
  28. • State management • Network API • View Controller Navigation

    Enums for finite states
  29. Enums for finite states ❌ ✅

  30. Enums for Network API

  31. Enums for Network API

  32. Enums Meet Protocol

  33. Navigation using Enum

  34. • UserDefaults • Image • Notifications • Storyboard / XIB

    files • Dictionary keys • Bundle resources Enums for string constants
  35. Enums for string constants

  36. None
  37. Recap ✅ Use Static Analyser ✅ Runtime tools for debug,

    test configuration. ✅ Asserts to validate app data state. ✅ Use Enums.
  38. Discussion %

  39. None
  40. None
  41. Speed up debugging • Break points • Watchpoints • LLDB

    • Visual Debugging
  42. Thank you