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

New Feature & Tips in LLDB

New Feature & Tips in LLDB

WWDC2015 情報共有会

Toshihiro Morimoto

July 07, 2015
Tweet

More Decks by Toshihiro Morimoto

Other Decks in Technology

Transcript

  1. New Feature & Tips in LLDB
    2015/07/07 WWDC2015 ৘ใڞ༗ձ
    @dealforest
    Toshihiro Morimoto

    View Slide

  2. ࣗݾ঺հ

    View Slide

  3. Crying
    DFTDebugScreenshot
    cocoapods-browser
    Tuna

    View Slide

  4. ͓ئ͍

    View Slide

  5. LLDB ͷ࿩Λ͢Δͱ
    λΠϜϥΠϯ͕͓ͱͳ͘͠ͳΓ
    ޙͰ΁͜Ή͜ͱʹͳΔͷͰ
    ͳΜͰ΋͍͍ͷͰͭͿ΍͍͍ͯͩ͘͞

    View Slide

  6. 402 Whats's new in LLDB
    Έ·͔ͨ͠ʁʁ

    View Slide

  7. ຖ೥ LLVM ͷ࠷దԽͷ࿩͕
    ͸͍͍ͬͯͨɻɻɻ
    (ڈ೥ͩͱ PGO)

    View Slide

  8. ͱ͜Ζ͕ɺࠓ೥͸
    ηογϣϯͱ͓ͯ͠ LLDB ͷ࿩

    View Slide

  9. ૉ੖Β͍͠ʂʂʂ

    View Slide

  10. ·ͣ཈͓͑ͯ͘ϙΠϯτʂ
    p, po ͸ alias Έ͍ͨͳ΋ͷ

    View Slide

  11. breakpoint
    breakpoint set -E swift -N allThrows
    • ݴޠαϙʔτ
    • lldbinit ͰॳظઃఆͰ͖ΔΑ͏ʹͳͬͨ

    View Slide

  12. breakpoint
    ~/.lldbinit
    breakpoint set -n malloc -N memory
    breakpoint set -n free -N memory
    breakpoint disable memory
    (lldb) breakpoint enable memory

    View Slide

  13. formatter
    i = 10
    (lldb) p/x i
    (lldb) expression -format hex -- i
    (lldb) frame variable --format hex i
    (Int) $R2 = 0x000000000000000a

    View Slide

  14. formatting models

    View Slide

  15. formatting models
    • `frame variable` ͸ pure LLDB ͷ৘ใΛग़ྗ
    • `p` ͸ eval ͨ݁͠ՌΛ LLDB format Ͱग़ྗ
    • `po` ͸ eval ͨ݁͠ՌΛݴޠຖʹΑͬͯ
    ࠷దͳ΋ͷΛग़ྗ (objc Ͱ͍͏ description)

    View Slide

  16. runtime
    (lldb) po for i in 1...3 { print(i) }
    1
    2
    3

    View Slide

  17. It’s All Automatic!!

    View Slide

  18. It’s All Automatic!!
    in Swift…

    View Slide

  19. ҆৺͍ͯͩ͘͠͞

    View Slide

  20. View Slide

  21. Xcode 6.x
    :PVS$PEF OBNFT .Z'VOD
    .Z7JFX ✔
    4%,'VODUJPOT /4-PH /4.BLF3FDU ✘
    4%,$MBTTFT /47JFX /4"QQMJDBUJPO ✔
    4%,$POTUBOUT /4"4$**4USJOH&ODPEJOH ✔
    .BDSPT */[email protected]"9 ."9

    View Slide

  22. Xcode 7.x
    :PVS$PEF OBNFT .Z'VOD
    .Z7JFX ✔
    4%,'VODUJPOT /4-PH /4.BLF3FDU ✔
    4%,$MBTTFT /47JFX /4"QQMJDBUJPO ✔
    4%,$POTUBOUT /4"4$**4USJOH&ODPEJOH ✔
    .BDSPT */[email protected]"9 ."9

    View Slide

  23. only Swift

    View Slide

  24. type lookup
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }

    View Slide

  25. type lookup
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }
    (lldb) type lookup Hoge
    struct Hoge : HogeProtocol {
    let a: Swift.String
    let b: Swift.String
    let c: Swift.String
    func aa()
    func ab()
    func ac()
    func hoge() -> Swift.String
    init(a: Swift.String, b:
    Swift.String, c: Swift.String)
    }
    (lldb) type lookup HogeProtocol
    protocol HogeProtocol {
    func hoge() -> Swift.String
    }
    protocol extension ΋͋Ε͹Ͱ·͢

    View Slide

  26. protocol
    4XJGU 4XJGU
    1SJOUBCMF $VTUPN4USJOH$POWFSUJCMF
    %FCVH1SJOUBCMF $VTUPN%FCVH4USJOH$POWFSUJCMF
    $VTUPN3FqFDUBCMF

    View Slide

  27. protocol
    4XJGU 4XJGU
    1SJOUBCMF $VTUPN4USJOH$POWFSUJCMF QSJOU
    %FCVH1SJOUBCMF $VTUPN%FCVH4USJOH$POWFSUJCMF EFCVH1SJOU
    $VTUPN3FqFDUBCMF --%# QP

    View Slide

  28. protocol
    4XJGU 4XJGU
    1SJOUBCMF $VTUPN4USJOH$POWFSUJCMF QSJOU
    %FCVH1SJOUBCMF $VTUPN%FCVH4USJOH$POWFSUJCMF EFCVH1SJOU
    $VTUPN3FqFDUBCMF --%# QP

    View Slide

  29. ͦΕͧΕݟ͍͖ͯ·͠ΐ͏

    View Slide

  30. print
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }

    View Slide

  31. print
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }
    let hoge = Hoge(
    a: “aaaaa",
    b: “bbbbb",
    c: “ccccccccc"
    )
    print(hoge)
    ——————————————————————————————
    > Sample.Hoge(a: "aaaaa", b:
    "bbbbb", c: “ccccccccc")

    View Slide

  32. debugPrint
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }

    View Slide

  33. debugPrint
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }
    let hoge = Hoge(
    a: “aaaaa",
    b: “bbbbb",
    c: “ccccccccc"
    )
    debugPrint(hoge)
    ——————————————————————————————
    > Sample.Hoge(a: "aaaaa", b:
    "bbbbb", c: “ccccccccc")
    ΧελϚΠζ͠ͳ͍ݶΓجຊಉ͡

    View Slide

  34. (lldb) po
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }

    View Slide

  35. (lldb) po
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }
    let hoge = Hoge(
    a: “aaaaa",
    b: “bbbbb",
    c: “ccccccccc"
    )
    ——————————————————————————————
    (lldb) po hoge
    ▿ Sample.Hoge
    - a : "aaaaa"
    - b : "bbbbb"
    - c : "ccccccccc"

    View Slide

  36. (lldb) po
    protocol HogeProtocol {
    func hoge() -> String
    }
    struct Hoge: HogeProtocol {
    let a: String
    internal let b: String
    private let c: String
    func aa() { }
    internal func ab() { }
    private func ac() { }
    func hoge() -> String {
    return "hoge"
    }
    }
    let hoge = Hoge(
    a: “aaaaa",
    b: “bbbbb",
    c: “ccccccccc"
    )
    ——————————————————————————————
    (lldb) po hoge
    ▿ Sample.Hoge
    - a : "aaaaa"
    - b : "bbbbb"
    - c : "ccccccccc"
    human
    readable!!!!

    View Slide

  37. ͱ͸͍͑ LLDB ্Ͱ͔͠࢖͑ͳ͍

    View Slide

  38. ͱ͍͏͜ͱ͸…

    View Slide

  39. break ͠ͳ͍ͱ࢖͑ͳ͍ͱ͔…(ry

    View Slide

  40. https://github.com/dealforest/Tuna

    View Slide

  41. break ͠ͳ͍ breakpoint Λ
    ؆୯ʹઃఆͰ͖·͢

    View Slide

  42. View Slide

  43. Swift 2 Λར༻͢Δࡍ͸ɹɹɹɹɹɹ
    ͔ͳΓ޾ͤʹͳΕΔΑ

    View Slide

  44. Objective-C Ͱ΋޾ͤʹͳΕ·͢

    View Slide

  45. Tips
    • ηογϣϯຖͷ hisotry ͩͬͨͷ͕
    stop / start ͯ͠΋࢒ΔΑ͏ʹͳͬͨ
    • ~/.lldbinit-Xcode ΛΈͳ͘ͳͬͨ
    • all exception breakpoint
    Debugger command `po $arg1`Λ͠ͱ͚͹ fatal
    error message ͕ΈΕΔΑ
    http://natashatherobot.com/xcode-debugging-trick/

    View Slide

  46. ·ͱΊ
    LLDB ΋৭ʑਐԽͯ͠ΔͷͰ
    ৮ͬͯΈΔͱͨͷ͍͠Α

    View Slide

  47. ·ͱΊ
    Tuna Λ࢖ͬͯ human readable ͳ
    ग़ྗͰσόοάΛ͠·ͤΜ͔ʁ

    View Slide

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

    View Slide