Slide 1

Slide 1 text

Intrducing debug in WWDC2016 2016/07/01 WWDC.next @dealforest Toshihro Morimoto

Slide 2

Slide 2 text

ࣗݾ঺հ

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

WWDC2016 Debug Session 1. #410 - Visual Debugging with Xcode 2. #412 - Thread Sanitizer and Static Analysis 3. #417 - Debugging Tips and Tricks

Slide 5

Slide 5 text

WWDC2016 Debug Session 1. #410 - Visual Debugging with Xcode (100P) 2. #412 - Thread Sanitizer and Static Analysis (64P) 3. #417 - Debugging Tips and Tricks (494P)

Slide 6

Slide 6 text

WWDC2016 Debug Session 1. #410 - Visual Debugging with Xcode (100P) 2. #412 - Thread Sanitizer and Static Analysis (64P) 3. #417 - Debugging Tips and Tricks (494P)

Slide 7

Slide 7 text

͜Μͳͷ 10 ෼Ͱ ঺հͰ͖ΔΘ͚ͳ͍Ͱ͢ΑͶwww

Slide 8

Slide 8 text

ͱ͍͏Θ͚Ͱૣ଎͍͖·͢

Slide 9

Slide 9 text

LLDB ͜ͱ͸͡Ί

Slide 10

Slide 10 text

LLDB ͜ͱ͸͡Ί

Slide 11

Slide 11 text

ม਺Λग़ྗ͢Δ • p • po • frame variable

Slide 12

Slide 12 text

your app LLDB Swift Compiler inject

Slide 13

Slide 13 text

your app LLDB Swift Compiler inject p, po ͸͜ͷλΠϓ

Slide 14

Slide 14 text

your app LLDB Swift Compiler inject p: ΞϓϦଆͰ LLDB ͷ৘ใΛग़ྗ po: ΞϓϦଆͰఆٛͨ͠৘ใ(description)Λग़ྗ

Slide 15

Slide 15 text

ͨͩ͠ʂʂʂʂ

Slide 16

Slide 16 text

inject ʹࣦഊ͢Δέʔε͕ Swift Ͱ͸ͨ·ʹൃੜ͠·͢

Slide 17

Slide 17 text

LLDB ͷΤϥʔϝοηʔδͷΈ දࣔ͞Ε·͢

Slide 18

Slide 18 text

ͭ·Γ͸࣮ߦ݁Ռ͕ ಘΒΕͳ͍Θ͚Ͱ͢Ͷ

Slide 19

Slide 19 text

ͦΜͳ࣌͸ frame variable Λ ࢖͍·͠ΐ͏

Slide 20

Slide 20 text

LLDB Swift Compiler frame variable ͸ LLDB ͷதͰ׬݁͠·͢

Slide 21

Slide 21 text

͜ΕͰͲΜͳঢ়گͰ΋ ม਺ͷग़ྗ͕ಘΒΕΔΑ͏ʹͳΓ·͢

Slide 22

Slide 22 text

͜Ε͚ͩ஌ͬͱ͍ͯ΋Β͑Ε͹ ࠷௿ݶ࢖͑Δ͔ͳͱࢥ͍·͢

Slide 23

Slide 23 text

Ͱ͸͜Ε͔Βۦ͚଍Ͱ ൃද͞Εͨ಺༰Λ ΩϟνΞοϓ͍͖ͯ͠·͠ΐ͏

Slide 24

Slide 24 text

ม਺Λग़ྗ͢Δ • p • po • frame variable • parray • poarray

Slide 25

Slide 25 text

ม਺Λग़ྗ͢Δ • p • po • frame variable • parray • poarray parray, poarray ͸ C ϙΠϯλ ͷ഑ྻΛදࣔ

Slide 26

Slide 26 text

ม਺Λग़ྗ͢Δ int count = 5; int data[5] = { 1000, 2, 3, 17, 50 }; int *dataset = data; (lldb) p dataset (int *) $1 = 0x00007fff5a5bedb0 (lldb) po dataset 0x00007fff5a5bedb0 (lldb) parray 5 dataset (int *) $3 = 0x00007fff5a5bedb0 { (int) [0] = 1000 (int) [1] = 2 (int) [2] = 3 (int) [3] = 17 (int) [4] = 50 }

Slide 27

Slide 27 text

ม਺Λग़ྗ͢Δ int count = 5; int data[5] = { 1000, 2, 3, 17, 50 }; int *dataset = data;

Slide 28

Slide 28 text

ม਺Λग़ྗ͢Δ int count = 5; int data[5] = { 1000, 2, 3, 17, 50 }; int *dataset = data; (lldb) poarray `count` dataset { 1000 2 3 17 50 }

Slide 29

Slide 29 text

Objective-C ͷΠϯελϯεΛग़ྗ Objective-C Ͱ࡞ΒΕͨΠϯελϯε (lldb) po 0x1003183e0 Enrico, 700 Swift Street, Mountain View, CA

Slide 30

Slide 30 text

Objective-C ͷΠϯελϯεΛग़ྗ Objective-C Ͱ࡞ΒΕͨΠϯελϯε (lldb) po 0x1003183e0 Enrico, 700 Swift Street, Mountain View, CA Swift ͷίʔυ (lldb) po 0x1003183e0 4298212320

Slide 31

Slide 31 text

Objective-C ͷΠϯελϯεΛग़ྗ Objective-C Ͱ࡞ΒΕͨΠϯελϯε (lldb) po 0x1003183e0 Enrico, 700 Swift Street, Mountain View, CA Swift ͷίʔυ (lldb) po 0x1003183e0 4298212320 (lldb) expr -O --language objc -- 0x1003183e0 Enrico, 700 Swift Street, Mountain View, CA po ͱ expr -O ͸ಉٛͰ͢

Slide 32

Slide 32 text

import module (lldb) p [NSApplication sharedApplication].undoManager error: property ‘undoManager’ not found on object of type ‘id’

Slide 33

Slide 33 text

import module (lldb) p [NSApplication sharedApplication].undoManager error: property ‘undoManager’ not found on object of type ‘id’ (lldb) p @import AppKit (lldb) p [NSApplication sharedApplication].undoManager (NSUndoManager * __nullable) $1 = 0x00007fb399629cd0

Slide 34

Slide 34 text

auto import module (lldb) p [NSApplication sharedApplication].undoManager (NSUndoManager * __nullable) $1 = 0x00007fb399629cd0

Slide 35

Slide 35 text

auto import module (lldb) p [NSApplication sharedApplication].undoManager (NSUndoManager * __nullable) $1 = 0x00007fb399629cd0 ͜ͷػೳΛແޮʹ͢Δ͜ͱ΋Ͱ͖·͢ (lldb) settings show target.auto-import-clang-modules false

Slide 36

Slide 36 text

ΧελϚΠζΛӬଓԽ • ~/.lldbinit or ~/.lldbinit-Xcode ʹίϚϯυΛॻ͍ ͓͚ͯ͹ىಈ࣌ʹ࣮ߦ͞ΕΔ • Python ͷϥΠϒϥϦΛ import ͓͚ͯ͠͹ LLDB ͕ attach ͞Εͨ࣌ʹ͙͢࢖͑Δ

Slide 37

Slide 37 text

REPL $ swift Welcome to Apple Swift version 3.0. Type :help for assistance. 1> po "Welcome to WWDC.next!!" error: repl.swift:2:3: error: consecutive statements on a line must be separated by ';' po "Welcome to WWDC.next!!" ^ ; 1> :po "Welcome to WWDC.next!!" "Welcome to WWDC.next!!"

Slide 38

Slide 38 text

REPL $ swift Welcome to Apple Swift version 3.0. Type :help for assistance. 1> :type lookup Comparable protocol Comparable : Equatable { @warn_unused_result func <(lhs: Self, rhs: Self) -> Swift.Bool @warn_unused_result func <=(lhs: Self, rhs: Self) -> Swift.Bool @warn_unused_result func >=(lhs: Self, rhs: Self) -> Swift.Bool @warn_unused_result func >(lhs: Self, rhs: Self) -> Swift.Bool }

Slide 39

Slide 39 text

breakpoint ΋࢖͑·͢

Slide 40

Slide 40 text

צͷ͍͍ਓ͸ؾ෇͍͔ͨ΋͠Ε·ͤΜ

Slide 41

Slide 41 text

Playgroud Ͱ΋ LLDB ͕ಈ͘ͷ͔ʂʂʂ

Slide 42

Slide 42 text

ͱࢥͬͨਓ΋͍ΔͰ͠ΐ͏

Slide 43

Slide 43 text

࢒೦ͳ͕ΒμϝͰͨ͠

Slide 44

Slide 44 text

ͨͩ͠࢖͑Δະདྷ͕ ΍ͬͯ͘Δ͔΋͠Ε·ͤΜͶ

Slide 45

Slide 45 text

REPL let value: Int? = 10 value + 10 ⚠Value of optional type 'Optional' not unwrapped; did you mean to use '!' or '?'?

Slide 46

Slide 46 text

REPL let value: Int? = 10 value + 10 ⚠Value of optional type 'Optional' not unwrapped; did you mean to use '!' or '?'? (lldb) p Optional(10) + 10 (Int) $R0 = 20 Fixit applied, fixed expression was: Optional(10)! + 10

Slide 47

Slide 47 text

Breakpoint • Symbolic Breakpoints • ಛఆͷ method, property ʹ step-in ͢Δ sif • ͲͷόΠφϦ͕ϩʔυ͞Ε͍ͯΔͷ͔ image list • --queue-name (or -q) Ͱಛఆͷ queue ͕ dequeue ͞ΕΔλ ΠϛϯάͰ attach Ͱ͖Δ

Slide 48

Slide 48 text

Breakpoint • ύλʔϯϚονϯάͰ attach ͢Δ͜ͱ͕Ͱ͖Δ function໊, ಛఆͷιʔείʔυͳͲ

Slide 49

Slide 49 text

Breakpoint • ύλʔϯϚονϯάͰ attach ͢Δ͜ͱ͕Ͱ͖Δ function໊, ಛఆͷιʔείʔυͳͲ // Break here (lldb) break set --source-regexp "// Break here" -f main.swift

Slide 50

Slide 50 text

Low-Level Debugging • Optimized code • Third-party code with no debug info

Slide 51

Slide 51 text

Low-Level Debugging • Optimized code • Third-party code with no debug info ୭͠΋Ұ౓͸ܦݧ͋Δ͔ͱ͸ࢥ͍·͢

Slide 52

Slide 52 text

Low-Level Debugging • Optimized code • Third-party code with no debug info ͭΒ͍Ͱ͢ΑͶ…

Slide 53

Slide 53 text

͜͜Ͱ͸;Ε·ͤΜ͕ 417 - Debugging Tips and Tricks ʹৄࡉ͕͋Γ·͢

Slide 54

Slide 54 text

State Machine Quick Look

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Thread Sanitizer (TSan)

Slide 57

Slide 57 text

only support • 64-bit macOS • 64-bit iOS and tvOS simulators

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Low-Level Debugging • Optimized code • Third-party code with no debug info FPS Performance Gauge

Slide 60

Slide 60 text

Low-Level Debugging • Optimized code • Third-party code with no debug info Memory Graph Debugging

Slide 61

Slide 61 text

iOSDC Ͱ͜ͷลΓͷࣄΛ࿩͔͢΋͠Ε·ͤΜ

Slide 62

Slide 62 text

·ͱΊ ػೳ௥Ճ΋͞Δ͜ͱͳ͕Β ࢿྉʹ͸طଘͷ؀ڥͰ΋ ͙͢ʹ࢖͑Δϊ΢ϋ΢͕ ͨ͘͞Μॻ͔Ε͍ͯ·͢

Slide 63

Slide 63 text

·ͱΊ ࠓ͙͢ʹͰ΋࢖͑ΔͷͰ ಡΉͱσόοάϥΠϑ͕ ޾ͤʹͳΔ͔΋͠Ε·ͤΜͶ

Slide 64

Slide 64 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠