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

App Extension のスタックトレース情報からクラッシュを解析/集計する / Analyzing app extension's stack trace

naru-jpn
September 18, 2021

App Extension のスタックトレース情報からクラッシュを解析/集計する / Analyzing app extension's stack trace

配信アプリで使用している Broadcast Extension 上で発生したクラッシュの詳細について、クラッシュ発生時のスタックトレースを取得して解析し、複数のクラッシュの修正に繋げた話。

naru-jpn

September 18, 2021
Tweet

More Decks by naru-jpn

Other Decks in Technology

Transcript

  1. "QQ&YUFOTJPOͷελοΫτϨʔε৘ใ͔Β
    ΫϥογϡΛղੳूܭ͢Δ
    /BSVLJ$IJHJSB
    !@OBSV@KQO
    J04%$

    View full-size slide

  2. ϛϥςΟϒΞϓϦͷ͝঺հ

    View full-size slide

  3. ࠓճͷ࿩ͷഎܠ

    View full-size slide

  4. &
    ΞϓϦຊମ #SPBEDBTU&YUFOTJPO
    ϛϥςΟϒͷJ04ΞϓϦ͸
    #SPBEDBTU&YUFOTJPOΛར༻ͯ͠഑৴ॲཧΛ͍ͯ͠Δ

    View full-size slide

  5. &
    ΞϓϦຊମ #SPBEDBTU&YUFOTJPO
    ΞϓϦຊମͱ#SPBEDBTU&YUFOTJPO͸ผͷϓϩηεͱͯ͠ಈ࡞͍ͯͯ͠ɺ
    ྫ͑͹ͲͪΒ͔͕Ϋϥογϡͯ͠΋ɺ΋͏Ұํ͸ಈ͖ଓ͚͍ͯͨΓ͢Δ
    💥
    ഑৴ͯ͠ΔΑ
    Ϋϥογϡͨ͠

    View full-size slide

  6. &
    ΞϓϦຊମ #SPBEDBTU&YUFOTJPO
    Ϋϥογϡ͕ൃੜͨ࣌͠ɺ
    ͦΕͧΕͰߦ͍ͬͯΔॲཧ΋ҟͳ͍ͬͯΔ
    💥 💥

    View full-size slide

  7. ΞϓϦຊମ
    ΞϓϦຊମ͸Ϋϥογϡ৘ใΛ'JSFCBTF$SBTIMZUJDTʹૹ৴͍ͯͯ͠ɺ
    'JSFCBTFͷίϯιʔϧ্ͰΫϥογϡΛ֬ೝͯ͠ରԠ͍ͯ͠Δ
    💥
    📝

    View full-size slide

  8. ϩά༻αʔόʔ
    &
    #SPBEDBTU&YUFOTJPO
    #SPBEDBTU&YUFOTJPOʹ͸'JSFCBTF$SBTIMZUJDT͸૊Έࠐ·Ε͓ͯΒͣɺ
    ಠࣗʹΫϥογϡ࣌ͷ৘ใΛऔಘ͍ͯ͠Δ
    💥
    📝
    5ISFBEDBMM4UBDL4ZNCPMT

    View full-size slide

  9. ϩά༻αʔόʔ
    &
    #SPBEDBTU&YUFOTJPO
    ݩʑɺϩά͸Ϋϥογϡͷൃੜස౓Λ೺Ѳ͢ΔͨΊʹ࢖༻͞Ε͍ͯͯɺ
    औಘ͞Ε͍ͯΔ৘ใΛݟ͚ͨͩͰ͸Ϋϥογϡͷৄࡉ͸෼͔Βͳ͍
    💥
    📝
    5ISFBEDBMM4UBDL4ZNCPMT

    View full-size slide

  10. ˠ#SPBEDBTU&YUFOTJPOͷΫϥογϡͷमਖ਼͸
    ΞϓϦຊମͱൺֱͯ͠ɺܦݧʹґΔͱ͜Ζ͕େ͖͔ͬͨ
    ݩʑɺϩά͸Ϋϥογϡͷൃੜස౓Λ೺Ѳ͢ΔͨΊʹ࢖༻͞Ε͍ͯͯɺ
    औಘ͞Ε͍ͯΔ৘ใΛݟ͚ͨͩͰ͸Ϋϥογϡͷৄࡉ͸෼͔Βͳ͍

    View full-size slide

  11. &
    ΞϓϦຊମ #SPBEDBTU&YUFOTJPO
    ೥ͷ͸͡ΊɺʮΠϠϗϯ഑৴ʯͱݺ͹Ε͍ͯΔػೳͷվमʹ൐ͬͯ
    #SPBEDBTU&YUFOTJPOͰ৽ͨͳΫϥογϡ͕ൃੜ͢Δ͜ͱ͕ͳΜͱͳ͘෼͔͍ͬͯͨ
    💥

    View full-size slide

  12. ˠͲ͏͍͏಺༰ͷΫϥογϡ͕ɺ
    Ͳͷ͘Β͍ͷׂ߹Ͱൃੜ͍ͯ͠Δ͔ௐ΂Δखஈ͕ཉ͔ͬͨ͠
    ೥ͷ͸͡ΊɺʮΠϠϗϯ഑৴ʯͱݺ͹Ε͍ͯΔػೳͷվमʹ൐ͬͯ
    #SPBEDBTU&YUFOTJPOͰ৽ͨͳΫϥογϡ͕ൃੜ͢Δ͜ͱ͕ͳΜͱͳ͘෼͔͍ͬͯͨ

    View full-size slide

  13. #SPBEDBTU&YUFOTJPOʹ΋'JSFCBTF$SBTIMZUJDTΛ૊ΈࠐΉ
    ˠͦ΋ͦ΋Ͱ͖Δͷ͔஌Βͳ͍
    ΫϥογϡΛௐ΂ͯΔͷʹ৽͍͠໰୊͕ग़ͨΒා͍
    Broadcast Extension ͸σϦέʔτͳͷͰۃྗ৮Γͨ͘ͳ͍

    View full-size slide

  14. 9DPEFͷ0SHBOJ[FSΛཔΔ
    ˠ಺༰Λཧղ͢Δͷʹܦݧ͕ඞཁͩͬͨ
    ͨͱ͑͹4IBSFEʹEP0VUQVU1SPDFTTͱ͍͏ϝιου͸ଘࡏ͠ͳ͍

    View full-size slide

  15. #SPBEDBTU&YUFOTJPOͰϩάͱͯ͠औಘ͍ͯ͠Δ
    ελοΫτϨʔε DBMM4UBDL4ZNCPMT
    ͷ৘ใΛ׆༻͢Δ
    ˠͪΐ͏Ͳ6OJUZ'SBNFXPSLͷΫϥογϡ΋ௐ͍ࠪͯͯ͠
    E4:.·ΘΓΛௐ΂͍ͯͨ͜ͱ΋͋ΓɺͰ͖ͦ͏ͳؾ͕ͨ͠
    Mirrativ tech blog - ʲiOSʳUnity Framework ͱΫϥογϡղੳͷऔΓ૊Έ

    View full-size slide

  16. "QQ&YUFOTJPOͷελοΫτϨʔε৘ใ͔Β
    ΫϥογϡΛղੳूܭ͢Δ
    Ϋϥογϡ࣌ͷελοΫτϨʔεΛऔಘ͢Δ
    E4:.ϑΝΠϧΛͱͬͯ͘Δ
    BUPTίϚϯυͰελοΫτϨʔεΛղੳ͢Δ
    ղੳΛࣗಈԽͯ͠ूܭ͢Δ
    ΫϥογϡΛमਖ਼͢Δ
    ඞཁͳࡐྉΛଗ͑Δ
    खಈͰղੳ͢Δ
    ࣗಈͰղੳ͢Δ
    मਖ਼͢Δ

    View full-size slide

  17. Ϋϥογϡ࣌ͷελοΫτϨʔεΛऔಘ͢Δ

    View full-size slide

  18. Ϋϥογϡݕ஌ͱϋϯυϦϯά
    class func setup() {


    // ྫ֎ͷݕ஌ͱ࣮ߦ͢Δؔ਺ͷࢦఆ


    NSSetUncaughtExceptionHandler(exceptionHandler)


    // γάφϧͷݕ஌ͱ࣮ߦ͢Δؔ਺ͷࢦఆ


    for sigcontext in [SIGABRT, SIGILL, SIGSEGV, SIGFPE, SIGBUS, SIGPIPE, SIGTRAP] {


    signal(sigcontext, signalHandler)


    }


    }


    private static let exceptionHandler: @convention(c) (NSException) -> () = { exeption in


    handleSignalException(exeption: exeption)


    }


    private static let signalHandler: @convention(c) (Int32) -> () = { signal in


    handleSignalException()


    }
    https://stackover
    fl
    ow.com/questions/36325140/how-to-catch-a-swift-crash-and-do-some-logging

    View full-size slide

  19. ίʔϧελοΫͷऔಘ
    let callstack = exception.callStackSymbols.joined(separator: “\n”)


    // ΋͘͠͸


    let callstack = Thread.callStackSymbols.joined(separator: “\n”)

    View full-size slide

  20. ίʔϧελοΫͷऔಘ
    let callstack = exception.callStackSymbols.joined(separator: “\n”)


    // ΋͘͠͸


    let callstack = Thread.callStackSymbols.joined(separator: “\n”)
    0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992


    1 libsystem_platform.dylib 0x00000001e3b9c29c 987D48D5-3CAA-34D7-9141-C0BD6E2351E8 + 21148


    2 broadcast-upload 0x0000000105106224 broadcast-upload + 1106468


    3 broadcast-upload 0x0000000105103604 broadcast-upload + 1095172


    4 Foundation 0x00000001991eb438 __NSFireTimer + 104


    5 CoreFoundation 0x0000000197d911d4 338F58B1-9B75-38A0-B908-E2574AB1D39A + 672212


    6 CoreFoundation 0x0000000197d90dd0 338F58B1-9B75-38A0-B908-E2574AB1D39A + 671184


    7 CoreFoundation 0x0000000197d90220 338F58B1-9B75-38A0-B908-E2574AB1D39A + 668192


    8 CoreFoundation 0x0000000197d89f8c 338F58B1-9B75-38A0-B908-E2574AB1D39A + 642956



    ͜ͷίʔϧελοΫͷ৘ใΛղੳͯ͠ɺϓϩάϥϜͷ࣮ߦߦ਺ͳͲΛಛఆ͍ͨ͠

    View full-size slide

  21. E4:.ϑΝΠϧΛͱͬͯ͘Δ

    View full-size slide

  22. "QQ4UPSF$POOFDU͔ΒE4:.ϑΝΠϧΛͱͬͯ͘Δ
    ͜ͷE4:.ϑΝΠϧ͸ͦΕͧΕ͕֤λʔήοτϥΠϒϥϦʹରԠ͍ͯ͠Δ
    App Store Connect

    View full-size slide

  23. E4:.ϑΝΠϧ͕ͲͷλʔήοτϥΠϒϥϦʹରԠ͍ͯ͠Δ͔ௐ΂Δ
    Mirrativ tech blog - ʲiOSʳUnity Framework ͱΫϥογϡղੳͷऔΓ૊Έ
    files=`ls "$1"`


    for uuid in ${files[@]}; do


    module=`ls "$1/${uuid}/Contents/Resources/DWARF/"`


    echo "${uuid:0:8}: ${module}"


    done
    fi
    OE@ETZNTI

    View full-size slide

  24. Mirrativ tech blog - ʲiOSʳUnity Framework ͱΫϥογϡղੳͷऔΓ૊Έ
    $ ./find_dsym.sh /Users/naruki.chigira/Desktop/appDsyms


    2d4dd1c9: widget


    310ef0bf: broadcast-upload


    6d82e920: WebRTC


    7cc5d65f: UnityFramework


    b11f4f4f: Shared


    de357eed: mirrativ



    ֤λʔήοτϥΠϒϥϦʹରԠ͢ΔE4:.͕؆୯ʹ୳ͤΔΑ͏ʹͳͬͨ
    E4:.ϑΝΠϧ͕ͲͷλʔήοτϥΠϒϥϦʹରԠ͍ͯ͠Δ͔ௐ΂Δ

    View full-size slide

  25. BUPTίϚϯυͰελοΫτϨʔεΛղੳ͢Δ

    View full-size slide

  26. BUPTͷجຊతͳ࢖͍ํΛ஌Δ
    $ man atos


    atos(1) BSD General Commands Manual atos(1)


    NAME


    atos -- convert numeric addresses to symbols of binary images or processes


    SYNOPSIS


    atos [-o ] [-p | ] [-arch
    architecture] [-l ] [-s ] [-printHeader] [-fullPath] [-f input-file>] [ …]



    NBOίϚϯυͰ֬ೝͯ͠ΈΔ
    atos [-o ] [-arch architecture] [-l ] [ …]
    ࠓճͷΫϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ

    View full-size slide

  27. BUPTʹ౉͢ύϥϝʔλE4:.ϑΝΠϧ
    atos [-o ] [-arch architecture] [-l ] [ …]
    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
    E4:.ϑΝΠϧͷύε த਎

    0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992
    ./appDsyms/310ef0bf-51fa-3535-8078-3fa06c470774.dSYM/Contents/Resources/DWARF/broadcast-upload

    View full-size slide

  28. BUPTʹ౉͢ύϥϝʔλΞʔΩςΫνϟ
    atos [-o ] [-arch architecture] [-l ] [ …]
    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
    Ϋϥογϡ͕ൃੜͨ͠୺຤ͷ$16ΞʔΩςΫνϟ
    BSN BSNF

    View full-size slide

  29. ɾΞʔΩςΫνϟΛऔಘ͢ΔͨΊͷ4XJGUͷίʔυ
    IUUQTHJTUHJUIVCDPNOBSVKQOBEEEDBBCFCEFC
    fi
    MFEFWJDFTXJGU
    ɾJ1IPOF ͷΑ͏ͳϞσϧ໊͔ΒΞʔΩςΫνϟΛऔಘ͢ΔͨΊͷTRM
    IUUQTHJTUHJUIVCDPNOBSVKQOGGFCEEDBDEBD
    fi
    MFEFWJDFTRM
    BUPTʹ౉͢ύϥϝʔλΞʔΩςΫνϟ

    View full-size slide

  30. BUPTʹ౉͢ύϥϝʔλελοΫτϨʔεͷΞυϨε
    atos [-o ] [-arch architecture] [-l ] [ …]
    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
    -l 0x104ff8000 0x10502eaf8

    View full-size slide

  31. atos [-o ] [-arch architecture] [-l ] [ …]
    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
    -l 0x104ff8000 0x10502eaf8
    0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992
    " #
    https://stackover
    fl
    ow.com/questions/11747802/symbolicating-stack-trace-without-crash
    "
    "#
    BUPTʹ౉͢ύϥϝʔλελοΫτϨʔεͷΞυϨε

    View full-size slide

  32. atos [-o ] [-arch architecture] [-l ] [ …]
    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
    -l 0x104ff8000 0x10502eaf8
    0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992
    " #
    https://stackover
    fl
    ow.com/questions/11747802/symbolicating-stack-trace-without-crash
    "#
    BUPTʹ౉͢ύϥϝʔλελοΫτϨʔεͷΞυϨε
    "0x" + String(UInt64("10502eaf8", radix: 16)! - UInt64("223992", radix: 10)!, radix: 16)

    View full-size slide

  33. $ atos -o {path_to_dsym} -arch arm64e -l 0x104ff8000 0x10502eaf8
    0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992
    https://stackover
    fl
    ow.com/questions/11747802/symbolicating-stack-trace-without-crash
    ελοΫτϨʔεΛղੳ͢Δ
    closure #1 in variable initialization expression of static AnalyticsManager.recieveSignal
    (in broadcast-upload) (AnalyticsManager+Extension.swift:22)
    🎉

    View full-size slide

  34. $ atos -o {path_to_dsym} -arch arm64e -l 0x104ff8000 0x105106224 0x105103604
    2 broadcast-upload 0x0000000105106224 broadcast-upload + 1106468


    3 broadcast-upload 0x0000000105103604 broadcast-upload + 1095172
    https://stackover
    fl
    ow.com/questions/11747802/symbolicating-stack-trace-without-crash
    ελοΫτϨʔεΛղੳ͢Δ
    specialized Stream.on(timer:) (in broadcast-upload) (Stream.swift:164)


    @objc Stream.on(timer:) (in broadcast-upload) (:0)
    🎉

    View full-size slide

  35. $ atos -o {path_to_dsym} -arch arm64e -l 0x104ff8000 0x10502eaf8
    ࣮༻্ͷ՝୊
    ɾE4:.ϑΝΠϧͷࢦఆ΍ΞυϨεͷܭࢉ͕खؒ
    ɾ࣮ߦʹ͕͔͔࣌ؒΔ
    ɹɾUJNFίϚϯυͰܭଌ͢Δͱ()[.BD#PPL1SPͰ
    ˠख࡞ۀͰ͸ղੳͰ͖ͳ͍͠ɺେྔͷϩάΛղੳ͢Δʹ͸Ωϟογϡ
    తͳ࢓૊Έ͕ඞཁ

    View full-size slide

  36. ղੳΛࣗಈԽͯ͠ूܭ͢Δ

    View full-size slide

  37. ղੳ༻ΞϓϦʹΑΔࣗಈԽʢ݅෼ͷΫϥογϡղੳʣ

    View full-size slide

  38. ूܭ݁Ռͷྫ
    ൃੜճ਺ ղੳࡁΈͷελοΫτϨʔε
    ͜͜·Ͱ͘Ε͹֤Ϋϥογϡͷ಺༰ͱӨڹͷେ͖͕͞Ұ໨Ͱ෼͔Δ

    View full-size slide

  39. ΫϥογϡΛमਖ਼͢Δ

    View full-size slide

  40. Ϋϥογϡͷमਖ਼
    ৄࡉ͸লུʜ
    ɾ഑৴தʹ4JSJΛىಈ͢ΔͱɺԻ੠σʔλͷྲྀΕ͕ෆنଇʹͳΔ
    ɾ഑৴தʹଞͷ௨࿩ΞϓϦͰ௨࿩Λ͢Δͱɺ૝ఆ֎ͷνϟωϧ਺Λ࣋ͬ
    ͨԻ੠σʔλ͕ྲྀΕͯ͘Δ
    ͳͲ

    View full-size slide

  41. Ϋϥογϡमਖ਼ޙͷΫϥογϡ཰ͷվળ
    मਖ਼൛ͷϦϦʔε೔
    Ϋϥογϡͷൃੜ਺Λ
    ໿ݮΒ͢͜ͱ͕Ͱ͖ͨʂ

    View full-size slide

  42. ·ͱΊ
    ෭࣍తʹಘΒΕͨ΋ͷ
    ɾΫϥογϡͷৄࡉͱ಺༁͕؆୯ʹ෼͔ΔΑ͏ʹͳͬͨ͜ͱͰɺ
    ɹमਖ਼Λ͢ΔࡍͷϝϦοτ΍Өڹྗͷࣄલͷઆ໌͕͠΍͘͢ͳͬͨ
    ɾܦݧ͕ͳ͍ͱཧղͰ͖ͳ͔ͬͨྖҬͷղ૾౓্͕͕Γɺ
    ɹଐਓੑΛݮΒ͢͜ͱʹܨ͕ͬͨ
    ɾελοΫτϨʔεͱE4:.͔ΒΫϥογϡͷৄࡉ͕ղੳͰ͖ͯɺ
    ɹΫϥογϡͷղফʹܨ͕ͬͨ

    View full-size slide

  43. ͓·͚
    DBMM4UBDL4ZNCPMT͔ΒऔಘͰ͖ΔจࣈྻΛύʔε͢ΔͨΊͷϥΠϒϥϦ
    IUUQTHJUIVCDPNOBSVKQO$BMM4UBDL4ZNCPMT

    View full-size slide

  44. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

    View full-size slide