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

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

2bfb16e53b154afc9f141f831b4aaaf2?s=47 naru-jpn
September 18, 2021

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

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

2bfb16e53b154afc9f141f831b4aaaf2?s=128

naru-jpn

September 18, 2021
Tweet

Transcript

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

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

  3. ࠓճͷ࿩ͷഎܠ

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

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

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

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

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

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

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

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

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

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

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

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

    ʲiOSʳUnity Framework ͱΫϥογϡղੳͷऔΓ૊Έ
  16. "QQ&YUFOTJPOͷελοΫτϨʔε৘ใ͔Β ΫϥογϡΛղੳूܭ͢Δ  Ϋϥογϡ࣌ͷελοΫτϨʔεΛऔಘ͢Δ  E4:.ϑΝΠϧΛͱͬͯ͘Δ  BUPTίϚϯυͰελοΫτϨʔεΛղੳ͢Δ  ղੳΛࣗಈԽͯ͠ूܭ͢Δ

     ΫϥογϡΛमਖ਼͢Δ ඞཁͳࡐྉΛଗ͑Δ खಈͰղੳ͢Δ ࣗಈͰղੳ͢Δ मਖ਼͢Δ
  17. Ϋϥογϡ࣌ͷελοΫτϨʔεΛऔಘ͢Δ

  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
  19. ίʔϧελοΫͷऔಘ let callstack = exception.callStackSymbols.joined(separator: “\n”) // ΋͘͠͸ let callstack

    = Thread.callStackSymbols.joined(separator: “\n”)
  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 … ͜ͷίʔϧελοΫͷ৘ใΛղੳͯ͠ɺϓϩάϥϜͷ࣮ߦߦ਺ͳͲΛಛఆ͍ͨ͠
  21. E4:.ϑΝΠϧΛͱͬͯ͘Δ

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

  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
  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:.ϑΝΠϧ͕ͲͷλʔήοτϥΠϒϥϦʹରԠ͍ͯ͠Δ͔ௐ΂Δ
  25. BUPTίϚϯυͰελοΫτϨʔεΛղੳ͢Δ

  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 <binary-image-file>] [-p <pid> | <partial-executable-name>] [-arch architecture] [-l <load-address>] [-s <slide>] [-printHeader] [-fullPath] [-f <address- input-file>] [<address> …] … NBOίϚϯυͰ֬ೝͯ͠ΈΔ atos [-o <binary-image-file>] [-arch architecture] [-l <load-address>] [<address> …] ࠓճͷΫϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ
  27. BUPTʹ౉͢ύϥϝʔλE4:.ϑΝΠϧ atos [-o <binary-image-file>] [-arch architecture] [-l <load-address>] [<address> …]

    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ E4:.ϑΝΠϧͷύε த਎ 0 broadcast-upload 0x000000010502eaf8 broadcast-upload + 223992 ./appDsyms/310ef0bf-51fa-3535-8078-3fa06c470774.dSYM/Contents/Resources/DWARF/broadcast-upload
  28. BUPTʹ౉͢ύϥϝʔλΞʔΩςΫνϟ atos [-o <binary-image-file>] [-arch architecture] [-l <load-address>] [<address> …]

    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ Ϋϥογϡ͕ൃੜͨ͠୺຤ͷ$16ΞʔΩςΫνϟ BSN BSNF
  29. ɾΞʔΩςΫνϟΛऔಘ͢ΔͨΊͷ4XJGUͷίʔυ IUUQTHJTUHJUIVCDPNOBSVKQOBEEEDBBCFCEFC fi MFEFWJDFTXJGU ɾJ1IPOF ͷΑ͏ͳϞσϧ໊͔ΒΞʔΩςΫνϟΛऔಘ͢ΔͨΊͷTRM IUUQTHJTUHJUIVCDPNOBSVKQOGGFCEEDBDEBD fi MFEFWJDFTRM BUPTʹ౉͢ύϥϝʔλΞʔΩςΫνϟ

  30. BUPTʹ౉͢ύϥϝʔλελοΫτϨʔεͷΞυϨε atos [-o <binary-image-file>] [-arch architecture] [-l <load-address>] [<address> …]

    Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ -l 0x104ff8000 0x10502eaf8
  31. atos [-o <binary-image-file>] [-arch architecture] [-l <load-address>] [<address> …] Ϋϥογϡղੳͷࡍʹඞཁͳύϥϝʔλ

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

    -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)
  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) 🎉
  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) (<compiler-generated>:0) 🎉
  35. $ atos -o {path_to_dsym} -arch arm64e -l 0x104ff8000 0x10502eaf8 ࣮༻্ͷ՝୊

    ɾE4:.ϑΝΠϧͷࢦఆ΍ΞυϨεͷܭࢉ͕खؒ ɾ࣮ߦʹ͕͔͔࣌ؒΔ ɹɾUJNFίϚϯυͰܭଌ͢Δͱ()[.BD#PPL1SPͰ<T> ˠख࡞ۀͰ͸ղੳͰ͖ͳ͍͠ɺେྔͷϩάΛղੳ͢Δʹ͸Ωϟογϡ తͳ࢓૊Έ͕ඞཁ
  36. ղੳΛࣗಈԽͯ͠ूܭ͢Δ

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

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

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

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

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

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

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

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