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

Debugging - Things your senior hasn't told you about

Debugging - Things your senior hasn't told you about

We as developers are spending 50% of our time either fixing bugs or making code work. In this talk we’re going over breakpoints, commands, arguments and tools that will help you be more efficient and faster when debugging your Apps.

47c28f369d87931c0ba1f324e40e8c4e?s=128

Carola Nitz

April 16, 2018
Tweet

Transcript

  1. DEBUGGING Things your Senior hasn't told you about (yet) 1

    — @_Caro_N, 4/16/2018
  2. 2 — @_Caro_N, 4/16/2018

  3. WHAT PROBLEMS DO WE FACE? 3 — @_Caro_N, 4/16/2018

  4. WE DON'T HAVE ENOUGH INFORMATION 4 — @_Caro_N, 4/16/2018

  5. TIME CONSUMING TASKS 5 — @_Caro_N, 4/16/2018

  6. WE DON'T KNOW ABOUT GOOD PRACTICES 6 — @_Caro_N, 4/16/2018

  7. COVERED TOPICS ▸ Get more information 7 — @_Caro_N, 4/16/2018

  8. COVERED TOPICS ▸ Get more information ▸ How you can

    speed up debugging 8 — @_Caro_N, 4/16/2018
  9. COVERED TOPICS ▸ Get more information ▸ How you can

    speed up debugging ▸ Best practices for error handling & debugging 9 — @_Caro_N, 4/16/2018
  10. 1. UNRESPONSIVE TO SCROLLS AND CLICK 10 — @_Caro_N, 4/16/2018

  11. 2. HIGH MEMORY PRESSURE 11 — @_Caro_N, 4/16/2018

  12. 3. STUCK IN UIKIT 12 — @_Caro_N, 4/16/2018

  13. 13 — @_Caro_N, 4/16/2018

  14. LLDB TO THE RESCUE! 14 — @_Caro_N, 4/16/2018

  15. GENERAL PURPOSE REGISTERS: 15 — @_Caro_N, 4/16/2018

  16. 16 — @_Caro_N, 4/16/2018

  17. 17 — @_Caro_N, 4/16/2018

  18. LAUNCH ARGUMENTS 18 — @_Caro_N, 4/16/2018

  19. 19 — @_Caro_N, 4/16/2018

  20. 20 — @_Caro_N, 4/16/2018

  21. 21 — @_Caro_N, 4/16/2018

  22. ▸ UIViewLayoutDebugger ▸ ConcurrencyDebug ▸ Migrationdebug & SQLDebug ▸ NSTraceEvents

    22 — @_Caro_N, 4/16/2018
  23. What's New in Auto Layout https://developer.apple.com/videos/play/wwdc2016/236 23 — @_Caro_N, 4/16/2018

  24. LAUNCH ARGUMENTS -com.apple.CoreData.ConcurrencyDebug 1 Core Data Concurrency Debugging by Ole

    Begemann https://oleb.net/blog/2014/06/core-data-concurrency-debugging/ 24 — @_Caro_N, 4/16/2018
  25. LAUNCH ARGUMENTS -com.apple.CoreData.MigrationDebug 1 -com.apple.CoreData.SQLDebug 3 25 — @_Caro_N, 4/16/2018

  26. LAUNCH ARGUMENTS /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSTraceEvents YES 26 — @_Caro_N, 4/16/2018

  27. ✨ iOS Debugging Magic https://developer.apple.com/library/content/technotes/tn2239 ✨ Mac OS X Debugging

    Magic https://developer.apple.com/library/content/technotes/tn2124 27 — @_Caro_N, 4/16/2018
  28. SPEED UP DEBUGGING 28 — @_Caro_N, 4/16/2018

  29. KEYPATHS let colorObservation = textFieldBackground.observe(\.backgroundColor, options:[.old, .new]) { (_, change)

    in) log.debug("color:\( change.oldValue ) -> \( change.newValue )") log.debug("") } 29 — @_Caro_N, 4/16/2018
  30. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' 30 — @_Caro_N, 4/16/2018
  31. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' (lldb) expr -l swift -O -- UIApplication.shared <UIApplication:0x7fa384d00260> 31 — @_Caro_N, 4/16/2018
  32. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' (lldb) expr -l swift -O -- UIApplication.shared <UIApplication:0x7fa384d00260> (lldb) expr @import UIKit (lldb) expr @import Foundation 32 — @_Caro_N, 4/16/2018
  33. 33 — @_Caro_N, 4/16/2018

  34. USEFUL BREAKPOINTS -NSKVODeallocateBreak 34 — @_Caro_N, 4/16/2018

  35. USEFUL BREAKPOINTS -Exception Breakpoint: Objective-C Debugger command: po $arg1 35

    — @_Caro_N, 4/16/2018
  36. USEFUL BREAKPOINTS -UIApplicationMain Debugger command: expr @import UIKit Debugger command:

    expr @import Foundation -NSKVODeallocateBreak -Exception Breakpoint: Objective-C Debugger command: po $arg1 User Breakpoints in Xcode by Michael Ochs https://pspdfkit.com/blog/2017/user-breakpoints-in-xcode/ 36 — @_Caro_N, 4/16/2018
  37. GOOD PRACTICES FOR ERROR HANDLING 37 — @_Caro_N, 4/16/2018

  38. ASSERTIONS ▸ assert() ▸ assertionFailure() 38 — @_Caro_N, 4/16/2018

  39. ASSERT func transformString(string: String?) -> String { assert(string != nil,

    "Invalid parameter") return string! + "_transforme" } 39 — @_Caro_N, 4/16/2018
  40. ASSERTIONFAILURE case RemoteNetworkCell.cloud.rawValue: if let networkCell = tableView.dequeueReusableCell(withIdentifier: VLCRemoteNetworkCell.cellIdentifier) {

    networkCell.textLabel?.text = cloudVC.title networkCell.detailTextLabel?.text = cloudVC.detailText networkCell.imageView?.image = cloudVC.cellImage return networkCell } case RemoteNetworkCell.wifi.rawValue: if let wifiCell = tableView.dequeueReusableCell(withIdentifier: VLCWiFiUploadTableViewCell.cellIdentifier()) { return wifiCell } default: assertionFailure("We're not handling a new CellType, add him to the cases") } assertionFailure("Cell is nil, did you forget to register the identifier?") return UITableViewCell() 40 — @_Caro_N, 4/16/2018
  41. SWIFT_OPTIMIZATION_LEVEL = -Onone // debug SWIFT_OPTIMIZATION_LEVEL = -O // release

    SWIFT_OPTIMIZATION_LEVEL = -Ounchecked // unchecked release 41 — @_Caro_N, 4/16/2018
  42. PRECONDITION & FATALERROR ▸ precondition() ▸ preconditionFailure() ▸ fatalError() 42

    — @_Caro_N, 4/16/2018
  43. PRECONDITION internal init(_repeating repeatedValue: Element, count: Int) { _precondition(count >=

    0, "Repetition count should be non-negative") self.count = count self.repeatedValue = repeatedValue } 43 — @_Caro_N, 4/16/2018
  44. FATALERROR internal enum _Normalization { // ICU's NFC unorm2 instance

    internal static var _nfcNormalizer: OpaquePointer = { var err = __swift_stdlib_U_ZERO_ERROR let normalizer = __swift_stdlib_unorm2_getNFCInstance(&err) guard err.isSuccess else { // This shouldn't be possible unless some deep (unrecoverable) system // invariants are violated fatalError("Unable to talk to ICU") } return normalizer }() 44 — @_Caro_N, 4/16/2018
  45. DEBUG RELEASE RELEASE function -Onone -O -Ounchecked assert() Yes No

    No assertfailure() Yes No No precondition() Yes Yes No preconditionFailu re() Yes Yes Yes fatalerror() Yes Yes Yes 45 — @_Caro_N, 4/16/2018
  46. SUMMARY ▸ Read register, Launch arguments ▸ Keypaths, User Breakpoints

    ▸ assert, precondition, fatalerror 46 — @_Caro_N, 4/16/2018
  47. Resources: Launch Arguments & Environment Variables by Mattt Thompson http://nshipster.com/launch-arguments-and-environment-variables/

    Swift Assertions by Andy Bargh https://andybargh.com/swift-assertions/ Swift asserts - the missing manual by Marcin Krzyzanowski http://blog.krzyzanowskim.com/2015/03/09/swift-asserts-the-missing-manual/ Debugging by Paul Hudson https://www.hackingwithswift.com/read/18/overview 47 — @_Caro_N, 4/16/2018
  48. THANKS 48 — @_Caro_N, 4/16/2018