Slide 1

Slide 1 text

Debugging in Swift how hard can it be @_Caro _N, 22/3/2015

Slide 2

Slide 2 text

Why do we struggle with debugging? @_Caro _N, 22/3/2015

Slide 3

Slide 3 text

Output is not helpful (lldb) po objectiveCString 0x00007fbaa1f24910 (ObjectiveC.NSObject = {}) @_Caro _N, 22/3/2015

Slide 4

Slide 4 text

Error messages make no sense @_Caro _N, 22/3/2015

Slide 5

Slide 5 text

What?! That tool exists? @_Caro _N, 22/3/2015

Slide 6

Slide 6 text

How debugging should be like • Get to the content of interest @_Caro _N, 22/3/2015

Slide 7

Slide 7 text

How debugging should be like • Get to the content of interest • Get helpful error messages @_Caro _N, 22/3/2015

Slide 8

Slide 8 text

How debugging should be like • Get to the content of interest • Get helpful error messages • Display additional information where needed @_Caro _N, 22/3/2015

Slide 9

Slide 9 text

How debugging should be like • Get to the content of interest • Get helpful error messages • Display additional information where needed • Know about debugging tools @_Caro _N, 22/3/2015

Slide 10

Slide 10 text

LLDB @_Caro _N, 22/3/2015

Slide 11

Slide 11 text

Expression (lldb) po objectiveCString 0x00007fbaa1f24910 (ObjectiveC.NSObject = {}) @_Caro _N, 22/3/2015

Slide 12

Slide 12 text

Expression (lldb) expression -O -- objectiveCString 0x00007fbaa1f24910 (ObjectiveC.NSObject = {}) @_Caro _N, 22/3/2015

Slide 13

Slide 13 text

Magic command (lldb) expression -l objc -O -- (id) 0x00007fbaa1f24910 @_Caro _N, 22/3/2015

Slide 14

Slide 14 text

Magic command (lldb) expression -l objc -O -- (id) 0x00007fbaa1f24910 I'm a fancy Objective-C String @_Caro _N, 22/3/2015

Slide 15

Slide 15 text

Breakpoints @_Caro _N, 22/3/2015

Slide 16

Slide 16 text

Editing Breakpoints @_Caro _N, 22/3/2015

Slide 17

Slide 17 text

Editing Breakpoints @_Caro _N, 22/3/2015

Slide 18

Slide 18 text

Editing Breakpoints @_Caro _N, 22/3/2015

Slide 19

Slide 19 text

Projectwide Breakpoints • Catch Objective-C or C++ Exceptions on throw or catch @_Caro _N, 22/3/2015

Slide 20

Slide 20 text

Projectwide Breakpoints • Catch Objective-C or C++ Exceptions on throw or catch @_Caro _N, 22/3/2015

Slide 21

Slide 21 text

Projectwide Breakpoints • Catch Objective-C or C++ Exceptions on throw or catch • Catch OpenGL ES errors @_Caro _N, 22/3/2015

Slide 22

Slide 22 text

Projectwide Breakpoints • Catch Objective-C or C++ Exceptions on throw or catch • Catch OpenGL ES errors • Stop when executing a specific function or method @_Caro _N, 22/3/2015

Slide 23

Slide 23 text

Projectwide Breakpoints • Catch Objective-C or C++ Exceptions on throw or catch • Catch OpenGL ES errors • Stop when executing a specific function or method • Stop when test Assertions fail @_Caro _N, 22/3/2015

Slide 24

Slide 24 text

Symbolic Breakpoints @_Caro _N, 22/3/2015

Slide 25

Slide 25 text

Symbolic Breakpoints @_Caro _N, 22/3/2015

Slide 26

Slide 26 text

Compiler errors @_Caro _N, 22/3/2015

Slide 27

Slide 27 text

Approach? @_Caro _N, 22/3/2015

Slide 28

Slide 28 text

1. Remove variables @_Caro _N, 22/3/2015

Slide 29

Slide 29 text

2. Split instructions @_Caro _N, 22/3/2015

Slide 30

Slide 30 text

Add return type @_Caro _N, 22/3/2015

Slide 31

Slide 31 text

Launch arguments @_Caro _N, 22/3/2015

Slide 32

Slide 32 text

Adding arguments in the scheme editor @_Caro _N, 22/3/2015

Slide 33

Slide 33 text

Concurrency -com.apple.CoreData.ConcurrencyDebug 1 @_Caro _N, 22/3/2015

Slide 34

Slide 34 text

SQL Statements -com.apple.CoreData.SQLDebug 3 @_Caro _N, 22/3/2015

Slide 35

Slide 35 text

Many more -com.apple.CoreData.MigrationDebug -com.apple.CoreData.SQLiteDebugSynchronous [0,1,2] -com.apple.CoreData.SQLiteIntegrityCheck 1 -com.apple.CoreData.ThreadingDebug [1,2,3] http://matthewmorey.com/tools-for-core-data/ @_Caro _N, 22/3/2015

Slide 36

Slide 36 text

Localization • -NSDoubleLocalizedStrings 1 @_Caro _N, 22/3/2015

Slide 37

Slide 37 text

Localization • -NSDoubleLocalizedStrings 1 • -NSShowNonLocalizedStrings 1 @_Caro _N, 22/3/2015

Slide 38

Slide 38 text

Localization • -NSDoubleLocalizedStrings 1 • -NSShowNonLocalizedStrings 1 • -AppleLanguages (es de) Technical Note TN2239 iOS Debugging Magic @_Caro _N, 22/3/2015

Slide 39

Slide 39 text

Debugging tools @_Caro _N, 22/3/2015

Slide 40

Slide 40 text

Charles • Debug http/https requests • Throttle traffic • Record download statistics @_Caro _N, 22/3/2015

Slide 41

Slide 41 text

Swift REPL • Test and interact with your app • Add new code • Clean slate xcrun swift in the terminal @_Caro _N, 22/3/2015

Slide 42

Slide 42 text

Activity Tracing Trace crashes in asynchonous code os_activity_t activity = os_activity_start("activity name", OS_ACTIVITY_FLAG_DEFAULT); // [...] os_activity_set_breadcrumb("event description"); // [...] os_trace("Received %d creates, %d updates, %d deletes", created, updated, deleted); // [...] os_activity_end(activity); @_Caro _N, 22/3/2015

Slide 43

Slide 43 text

Activity Tracing @_Caro _N, 22/3/2015

Slide 44

Slide 44 text

Activity Tracing http://www.objc.io/issue-19/activity-tracing.html @_Caro _N, 22/3/2015

Slide 45

Slide 45 text

Summary • expression -l objc -O -- (id) 0x00007fbaa1f24910 • Edit Breakpoints, add symbolic and exception breakpoints • Tackle incomprehensive compiler errors • Launch arguments • Charles, REPL, Activity tracing @_Caro _N, 22/3/2015

Slide 46

Slide 46 text

Thanks @_Caro _N, 22/3/2015