Xcode 11, iOS 13, Unable to find the cause of crash

Could you please help me with solving this crash? The app is in production and I have seen this crash in Xcode Organizer. It is happening on some of the devices that run 13.1.2 iOS or 13.1.3 iOS operating system. I cannot see any of these crashes in Crashlytics, so I suppose it is happening while lunching the app.



Incident Identifier: C27DBB84-D6DE-4942-9381-2A17511C3A77
CrashReporter Key:   f4e6a31dc4e99dd541c0d17431ab10080e5d8d8d
Hardware Model:      iPhone11,8
Process:             myApp [387]
Path:                /private/var/containers/Bundle/Application/C25253A0-B801-43D4-A2E0-C48FA53376E6/myApp.app/myApp
Identifier:          com.MyApp
Version:             6 (1.0.7)
AppStoreTools:       11A1002b
AppVariant:          1:iPhone11,8:13
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.MyApp [526]




Date/Time:           2019-10-21 20:57:46.3826 +0200
Launch Time:         2019-10-21 20:57:46.3461 +0200
OS Version:          iPhone OS 13.1.3 (17A878)
Release Type:        User
Baseband Version:    2.01.08
Report Version:      104


Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0


Last Exception Backtrace:
0   CoreFoundation                0x19cb45c30 __exceptionPreprocess + 224 (NSException.m:199)
1   libobjc.A.dylib                0x19c8600c8 objc_exception_throw + 60 (objc-exception.mm:565)
2   CoreFoundation                0x19ca43fc0 -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:144)
3   CoreFoundation                0x19cb4a3d4 ___forwarding___ + 1328 (NSForwarding.m:3325)
4   CoreFoundation                0x19cb4c570 _CF_forwarding_prep_0 + 96
5   CoreFoundation                0x19ca90f8c _CFLocaleCopyCurrentGuts + 740 (CFLocale.c:652)
6   CoreFoundation                0x19ca3b7fc +[NSLocale currentLocale] + 16 (NSLocale.m:285)
7   Foundation                    0x19cdfe898 -[NSUserDefaults(NSUserDefaults) init] + 1464 (NSUserDefaults.m:600)
8   Foundation                    0x19cdfe2a4 +[NSUserDefaults(NSUserDefaults) standardUserDefaults] + 72 (NSUserDefaults.m:686)
9   myApp                        0x100847bc4 __45+[GMSx_GTMSessionFetcher fetcherUserDefaults]_block_invoke + 64
10  libdispatch.dylib              0x19c7ed00c _dispatch_client_callout + 20 (object.m:495)
11  libdispatch.dylib              0x19c7ee6f4 _dispatch_once_callout + 32 (once.c:52)
12  myApp                        0x100847b7c +[GMSx_GTMSessionFetcher fetcherUserDefaults] + 56
13  myApp                        0x1008480fc +[GMSx_GTMSessionFetcher fetchersForBackgroundSessions] + 76
14  myApp                        0x100843af4 +[GMSx_GTMSessionFetcher load] + 20
15  libobjc.A.dylib                0x19c868400 load_images + 760 (objc-loadmethod.mm:204)
16  libdyld.dylib                  0x19c94a280 invocation function for block in dyld3::AllImages::runInitialzersBottomUp(dyld3::closure::Image c... + 224 (AllImages.cpp:1607)
17  libdyld.dylib                  0x19c93c900 dyld3::closure::Image::forEachImageToInitBefore(void (unsigned int, bool&) block_pointer) const + 104 (Closure.cpp:886)
18  libdyld.dylib                  0x19c949d0c dyld3::AllImages::runStartupInitialzers() + 280 (AllImages.cpp:1596)
19  libdyld.dylib                  0x19c964fbc dyld3::entry_runInitialzersBottomUp(mach_header const*) + 32 (libdyldEntryVector.cpp:126)
20  dyld                          0x1011f4528 dyld::launchWithClosure(dyld3::closure::LaunchClosure const*, DyldSharedCache const*, dyld3::Mach... + 1080 (dyld2.cpp:5933)
21  dyld                          0x1011f298c dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, un... + 2960 (dyld2.cpp:6570)
22  dyld                          0x1011ed22c dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, uns... + 432 (dyldInitialization.cpp:145)
23  dyld                          0x1011ed038 _dyld_start + 56


Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib        0x000000019c930ef4 __pthread_kill + 8
1   libsystem_pthread.dylib        0x000000019c851d1c pthread_kill + 196 (pthread.c:1456)
2   libsystem_c.dylib              0x000000019c7e1a54 abort + 104 (abort.c:110)
3   libc++abi.dylib                0x000000019c8f83c8 abort_message + 132 (abort_message.cpp:76)
4   libc++abi.dylib                0x000000019c8f85c0 demangling_terminate_handler() + 308 (cxa_default_handlers.cpp:66)
5   libobjc.A.dylib                0x000000019c8603a8 _objc_terminate() + 124 (objc-exception.mm:701)
6   libc++abi.dylib                0x000000019c905634 std::__terminate(void (*)()) + 20 (cxa_handlers.cpp:59)
7   libc++abi.dylib                0x000000019c9055c0 std::terminate() + 44 (cxa_handlers.cpp:87)
8   libdispatch.dylib              0x000000019c7ed020 _dispatch_client_callout + 40 (object.m:498)
9   libdispatch.dylib              0x000000019c7ee6f4 _dispatch_once_callout + 32 (once.c:52)
10  myApp                        0x0000000100847b7c +[GMSx_GTMSessionFetcher fetcherUserDefaults] + 56
11  myApp                        0x00000001008480fc +[GMSx_GTMSessionFetcher fetchersForBackgroundSessions] + 76
12  myApp                        0x0000000100843af4 +[GMSx_GTMSessionFetcher load] + 20
13  libobjc.A.dylib                0x000000019c868400 load_images + 760 (objc-loadmethod.mm:204)
14  libdyld.dylib                  0x000000019c94a280 invocation function for block in dyld3::AllImages::runInitialzersBottomUp(dyld3::closure::Image c... + 224 (AllImages.cpp:1607)
15  libdyld.dylib                  0x000000019c93c900 dyld3::closure::Image::forEachImageToInitBefore(void (unsigned int, bool&) block_pointer) const + 104 (Closure.cpp:886)
16  libdyld.dylib                  0x000000019c949d0c dyld3::AllImages::runStartupInitialzers() + 280 (AllImages.cpp:1596)
17  libdyld.dylib                  0x000000019c964fbc dyld3::entry_runInitialzersBottomUp(mach_header const*) + 32 (libdyldEntryVector.cpp:126)
18  dyld                          0x00000001011f4528 dyld::launchWithClosure(dyld3::closure::LaunchClosure const*, DyldSharedCache const*, dyld3::Mach... + 1080 (dyld2.cpp:5933)
19  dyld                          0x00000001011f298c dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, un... + 2960 (dyld2.cpp:6570)
20  dyld                          0x00000001011ed22c dyldbootstrap::start(dyld3::MachOLoaded const*, int, char const**, dyld3::MachOLoaded const*, uns... + 432 (dyldInitialization.cpp:145)
21  dyld                          0x00000001011ed038 _dyld_start + 56


Thread 1:
0   libsystem_pthread.dylib        0x000000019c858c70 pthread_dependency_wait_np + 180 (pthread_dependency.c:112)


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x000000016f8a47a0   x5: 0x000000016f8a4d50   x6: 0x000000000000006e   x7: 0x0000000000000600
    x8: 0x000000010125d840   x9: 0x00000000e4bf3867  x10: 0x0000000000000002  x11: 0x0000000000000003
   x12: 0x0000000000000000  x13: 0x000000000000000d  x14: 0x0000000000000010  x15: 0x0000000000000000
   x16: 0x0000000000000148  x17: 0x00000001d9efaf10  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x0000000000000407  x21: 0x000000010125d920  x22: 0x0000000100843ae0  x23: 0x00000001e2710000
   x24: 0x00000002817a8500  x25: 0x00000001d496949b  x26: 0x0000000100da8ec8  x27: 0x00000001e4bf0000
   x28: 0x000000019c94a1a0   fp: 0x000000016f8a4cb0   lr: 0x000000019c851d1c
    sp: 0x000000016f8a4c90   pc: 0x000000019c930ef4 cpsr: 0x40000000
   esr: 0x56000080  Address size fault

Can you email me the full crash report as an attachment? There’s something I’d like to check but to do that I need the full report, not just the excerpt that you’ve included here.

My email address is in my signature.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[valentina.konatar sent me their crash report via email.]

Crashes like this, where you’ve crashed because of a call to

abort
within the exception handling machinery, are typically caused by someone throwing an unhandled language exception. The
Last Exception Backtrace
section has a backtrace of the throw site:
Last Exception Backtrace:  
0   CoreFoundation  … __exceptionPreprocess + 224 (NSException.m:199)  
1   libobjc.A.dylib … objc_exception_throw + 60 (objc-exception.mm:565)  
2   CoreFoundation  … -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:144)  
3   CoreFoundation  … ___forwarding___ + 1328 (NSForwarding.m:3325)  
4   CoreFoundation  … _CF_forwarding_prep_0 + 96  
5   CoreFoundation  … _CFLocaleCopyCurrentGuts + 740 (CFLocale.c:652)  
6   CoreFoundation  … +[NSLocale currentLocale] + 16 (NSLocale.m:285)  
7   Foundation      … -[NSUserDefaults(NSUserDefaults) init] + 1464 (NSUserDefaults.m:600)  
8   Foundation      … +[NSUserDefaults(NSUserDefaults) standardUserDefaults] + 72 (NSUserDefaults.m:686)  
9   myApp           … __45+[GMSx_GTMSessionFetcher fetcherUserDefaults]_block_invoke + 64  
10  libdispatch.dyli… _dispatch_client_callout + 20 (object.m:495)  
11  libdispatch.dyli… _dispatch_once_callout + 32 (once.c:52)  
12  myApp           … +[GMSx_GTMSessionFetcher fetcherUserDefaults] + 56  
13  myApp           … +[GMSx_GTMSessionFetcher fetchersForBackgroundSessions] + 76  
14  myApp           … +[GMSx_GTMSessionFetcher load] + 20  
15  libobjc.A.dylib … load_images + 760 (objc-loadmethod.mm:204)  
16  libdyld.dylib   … invocation function for block in dyld3::AllImages::runInitialzersBottomUp…
17  libdyld.dylib   … dyld3::closure::Image::forEachImageToInitBefore…
18  libdyld.dylib   … dyld3::AllImages::runStartupInitialzers…
19  libdyld.dylib   … dyld3::entry_runInitialzersBottomUp…
20  dyld            … dyld::launchWithClosure…
21  dyld            … dyld::_main…
22  dyld            … dyldbootstrap::start…
23  dyld            … _dyld_start + 56

This breaks up into 6 sections:

  • Frames 23 through 16 are dyld’s startup code running Mach-O image initialisers.

  • Frame 15 is the Objective-C runtime running class

    +load
    methods.
  • Frames 14 through 9 is

    +[GMSx_GTMSessionFetcher load]
    running (except for frames 11 and 10, which are just a
    dispatch_once
    ).
  • Frame 8 shows that the last part of your code, the

    dispatch_once
    block in
    +[GMSx_GTMSessionFetcher fetcherUserDefaults]
    , has called
    +[NSUserDefaults standardUserDefaults]
    .
  • Frames 8 through 5 are Foundation / Core Foundation initialising stuff.

  • Frames 4 through 0 are the Objective-C / Core Foundation runtimes throwing an ‘unrecognised selector’ exception.

So what is

_CFLocaleCopyCurrentGuts
(frame 5) doing that triggers this exception? If you disassemble you see something like this:
(lldb) disas -n _CFLocaleCopyCurrentGuts
…
… <+696>:  bl     0x1b7fe2510       ; CFBundleGetMainBundle
… <+700>:  cbz    x0, 0x1b7ee38b4   ; <+916>
… <+704>:  bl     0x1b7f0977c       ; CFBundleCopyBundleLocalizations
… <+708>:  cbz    x0, 0x1b7ee38e8   ; <+968>
… <+712>:  mov    x24, x0 
… <+716>:  bl     0x1b7eacf70       ; CFArrayGetCount
… <+720>:  cmp    x0, #0x1          ; =0x1 
… <+724>:  b.lt   0x1b7ee38d4       ; <+948>
… <+728>:  mov    x0, x22 
… <+732>:  bl     0x1b7eacf70       ; CFArrayGetCount
… <+736>:  cmp    x0, #0x1          ; =0x1

Note that +736 is the offset in the exception backtrace, so the call that threw the exception is the

CFArrayGetCount
on line +732.

It’s a bit weird that

CFArrayGetCount
, a CF routine, can throw an Objective-C language exception. The reason this occurs is toll-free bridging. The array being passed in to
CFArrayGetCount
might not be a
CFArray
, it might be an
NSArray
, or any subclass of
NSArray
. So the code in
CFArrayGetCount
looks at the array to see if it looks like a
CFArray
and, if it doesn’t, calls the Objective-C
-count
method on it. It’s not clear what sort of object this is, but whatever it is it doesn’t respond to
-count
and hence this language exception.

If you look further up the disassembly you’ll see that this array comes from calling

CFBundleCopyBundleLocalizations
on
CFBundleGetMainBundle
. So there’s two possibilities here:
  • CFBundleCopyBundleLocalizations
    is returning something that’s not an array.
  • There’s some weird memory error that’s corrupted the resulting array.

I’d first check that

CFBundleCopyBundleLocalizations
is returning reasonable results for your app. Add a line to the app’s startup sequence that calls that function and logs the result. Does the value make sense?

If so, my next step would be to run the Standard Memory Debugging Tools over your app to see if that helps flush out the issue.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Xcode 11, iOS 13, Unable to find the cause of crash
 
 
Q