Intrducing debug in WWDC2016

Intrducing debug in WWDC2016

WWDC.next

0a86666ca90016b2a28289dda921b0d7?s=128

Toshihiro Morimoto

July 01, 2016
Tweet

Transcript

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

  2. ࣗݾ঺հ

  3. None
  4. WWDC2016 Debug Session 1. #410 - Visual Debugging with Xcode

    2. #412 - Thread Sanitizer and Static Analysis 3. #417 - Debugging Tips and Tricks
  5. 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)
  6. 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)
  7. ͜Μͳͷ 10 ෼Ͱ ঺հͰ͖ΔΘ͚ͳ͍Ͱ͢ΑͶwww

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

  9. LLDB ͜ͱ͸͡Ί

  10. LLDB ͜ͱ͸͡Ί

  11. ม਺Λग़ྗ͢Δ • p <expression> • po <expression> • frame variable

    <local-name>
  12. your app LLDB Swift Compiler inject

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

  14. your app LLDB Swift Compiler inject p: ΞϓϦଆͰ LLDB ͷ৘ใΛग़ྗ

    po: ΞϓϦଆͰఆٛͨ͠৘ใ(description)Λग़ྗ
  15. ͨͩ͠ʂʂʂʂ

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

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

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

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

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

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

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

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

  24. ม਺Λग़ྗ͢Δ • p <expression> • po <expression> • frame variable

    <local-name> • parray <count> <expression> • poarray <count> <expression>
  25. ม਺Λग़ྗ͢Δ • p <expression> • po <expression> • frame variable

    <local-name> • parray <count> <expression> • poarray <count> <expression> parray, poarray ͸ C ϙΠϯλ ͷ഑ྻΛදࣔ
  26. ม਺Λग़ྗ͢Δ 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 }
  27. ม਺Λग़ྗ͢Δ int count = 5; int data[5] = { 1000,

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

    2, 3, 17, 50 }; int *dataset = data; (lldb) poarray `count` dataset { 1000 2 3 17 50 }
  29. Objective-C ͷΠϯελϯεΛग़ྗ Objective-C Ͱ࡞ΒΕͨΠϯελϯε (lldb) po 0x1003183e0 Enrico, 700 Swift

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

    Street, Mountain View, CA Swift ͷίʔυ (lldb) po 0x1003183e0 4298212320
  31. 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 ͸ಉٛͰ͢
  32. import module (lldb) p [NSApplication sharedApplication].undoManager error: property ‘undoManager’ not

    found on object of type ‘id’
  33. 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
  34. auto import module (lldb) p [NSApplication sharedApplication].undoManager (NSUndoManager * __nullable)

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

    $1 = 0x00007fb399629cd0 ͜ͷػೳΛແޮʹ͢Δ͜ͱ΋Ͱ͖·͢ (lldb) settings show target.auto-import-clang-modules false
  36. ΧελϚΠζΛӬଓԽ • ~/.lldbinit or ~/.lldbinit-Xcode ʹίϚϯυΛॻ͍ ͓͚ͯ͹ىಈ࣌ʹ࣮ߦ͞ΕΔ • Python ͷϥΠϒϥϦΛ

    import ͓͚ͯ͠͹ LLDB ͕ attach ͞Εͨ࣌ʹ͙͢࢖͑Δ
  37. 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!!"
  38. 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 }
  39. breakpoint ΋࢖͑·͢

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

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

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

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

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

  45. REPL let value: Int? = 10 value + 10 ⚠Value

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

    of optional type 'Optional<Int>' not unwrapped; did you mean to use '!' or '?'? (lldb) p Optional(10) + 10 (Int) $R0 = 20 Fixit applied, fixed expression was: Optional(10)! + 10
  47. Breakpoint • Symbolic Breakpoints • ಛఆͷ method, property ʹ step-in

    ͢Δ sif <TargetFunctionName> • ͲͷόΠφϦ͕ϩʔυ͞Ε͍ͯΔͷ͔ image list • --queue-name (or -q) Ͱಛఆͷ queue ͕ dequeue ͞ΕΔλ ΠϛϯάͰ attach Ͱ͖Δ
  48. Breakpoint • ύλʔϯϚονϯάͰ attach ͢Δ͜ͱ͕Ͱ͖Δ function໊, ಛఆͷιʔείʔυͳͲ

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

    (lldb) break set --source-regexp "// Break here" -f main.swift
  50. Low-Level Debugging • Optimized code • Third-party code with no

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

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

    debug info ͭΒ͍Ͱ͢ΑͶ…
  53. ͜͜Ͱ͸;Ε·ͤΜ͕ 417 - Debugging Tips and Tricks ʹৄࡉ͕͋Γ·͢

  54. State Machine Quick Look

  55. None
  56. Thread Sanitizer (TSan)

  57. only support • 64-bit macOS • 64-bit iOS and tvOS

    simulators
  58. None
  59. Low-Level Debugging • Optimized code • Third-party code with no

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

    debug info Memory Graph Debugging
  61. iOSDC Ͱ͜ͷลΓͷࣄΛ࿩͔͢΋͠Ε·ͤΜ

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

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

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