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

Intrducing debug in WWDC2016

Intrducing debug in WWDC2016

WWDC.next

Toshihiro Morimoto

July 01, 2016
Tweet

More Decks by Toshihiro Morimoto

Other Decks in Technology

Transcript

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

    View full-size slide

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

    View full-size slide

  3. 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)

    View full-size slide

  4. 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)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. LLDB ͜ͱ͸͡Ί

    View full-size slide

  8. LLDB ͜ͱ͸͡Ί

    View full-size slide

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

    View full-size slide

  10. your app
    LLDB
    Swift Compiler
    inject

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. ͨͩ͠ʂʂʂʂ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  24. ม਺Λग़ྗ͢Δ
    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
    }

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  29. 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 ͸ಉٛͰ͢

    View full-size slide

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

    View full-size slide

  31. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  35. 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!!"

    View full-size slide

  36. 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
    }

    View full-size slide

  37. breakpoint ΋࢖͑·͢

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  41. ࢒೦ͳ͕ΒμϝͰͨ͠

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  44. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  52. State Machine Quick Look

    View full-size slide

  53. Thread Sanitizer (TSan)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide