iOS Apps Crashing?

i.vikash
6 min readDec 2, 2021

--

How to identify the cause of common crashes?

Crash why ??

In mobile application development crash is a bitter truth for the developers. No one want’s any crash in the application but it still happens.

As a developer even we make sure that our code will not generate any crashes, still there are multiple reasons for it. So in this post, we will try to identify the common cause of the crash by checking the crash report. It will help us to quickly resolve the issue.

In this post, we will only discuss a common cause, not how to resolve it. The resolution will be discussed in another post.

So Let’s Start:

Below are some common causes based on the pattern in the crash report-

Crash Summary

Below are the snapshot for the same-

Common Cause For Crashes

Now let’s try to understand it one by one. Since we are trying to identify it based on crash report pattern, I am assuming that we already have a basic idea of these-

Crash report structure:-

To know more about crash report structure please refer to the below link-

https://developer.apple.com/documentation/xcode/examining-the-fields-in-a-crash-report

Symbolicated crash report:-

To know more about how to fully symbolicate or partially symbolicate crash report you can refer the below link-

https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report#Determine-If-a-Crash-Report-is-Symbolicated

Every crash report contains multiple sections, in this post we will only focus on two sections-

  1. Exception Information section : The exception code identifies the specific way the app crashed.
  2. Backtraces section: Show what code the thread was executing at the time of the crash.
From developer.apple.com

Runtime Errors:

This exception indicates that a trace trap interrupts the process when encounter an unrecoverable error, such as force unwrapping of an optional value that is nil.

Runtime Error

On ARM processors the exception info in the crash report looks like:

Exception Type: EXC_BREAKPOINT (SIGTRAP)

Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5

On Intel processors the exception info in the crash report looks like:

Exception Type: EXC_BAD_INSTRUCTION (SIGILL)

Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4

To know which part of code generate these error we can check thread (Thread 0 Crashed:) in backtrace.

To know more checkout : https://developer.apple.com/documentation/xcode/addressing-crashes-from-swift-runtime-errors

https://developer.apple.com/documentation/xcode/understanding-the-exception-types-in-a-crash-report#EXC_BREAKPOINT-(SIGTRAP)-and-EXC_BAD_INSTRUCTION-(SIGILL)

Language Exception:

This type of error is occurred due to programs such as accessing an array with an index that’s out-of-bounds.

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

This type of exception also contains last exception backtrace for more information.

Last Exception Backtrace:0   CoreFoundation                    0x19aae2a48 __exceptionPreprocess + 2201   libobjc.A.dylib                   0x19a809fa4 objc_exception_throw + 55

To know more checkout : https://developer.apple.com/documentation/xcode/addressing-language-exception-crashes

System Terminations:

This type of crash occurs when an app is unresponsive. The operating system uses a watchdog that monitors launch times and app responsiveness and terminates apps that block the main thread for a significant time.

System Termination

In this case termination reason code will be 0x8badf00d (pronounced “ate bad food”)

Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d

Termination description contains more information about how the app spent its time.

For more details checkout : https://developer.apple.com/documentation/xcode/addressing-watchdog-terminations

App Configuration Errors:

This type of crash occurs in case of missing the required framework. If we use any framework in our app, the app links the frameworks at build time and also embeds a copy of the frameworks inside the app bundle during the build. If an app links a framework but doesn’t embed it, the app crashes at launch.

App Configuration

In this case exception code contains EXC_CRASH (SIGABRT)

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

To identify the framework which causes this issue we can check the termination description.

Termination Description: DYLD, dependent dylib '@rpath/MyFramework.framework/MyFramework'    not found for '<path>/MyCoolApp.app/MyCoolApp', tried but didn't find:     '/usr/lib/swift/MyFramework.framework/MyFramework'     '<path>/MyCoolApp.app/Frameworks/MyFramework.framework/MyFramework'     '@rpath/MyFramework.framework/MyFramework'     '/System/Library/Frameworks/MyFramework.framework/MyFramework'

**The exact message depends on the operating system and operating system version.

To know more checkout : https://developer.apple.com/documentation/xcode/addressing-missing-framework-crashes

Memory Access Errors:

This type of crash occurs due to unexpected use of memory. There are multiple reasons for this, such as dereferencing a pointer to an invalid memory address, writing to read-only memory, or jumping to instruction at an invalid address.

Memory Access

In this case exception type contains EXC_BAD_ACCESS (SIGSEGV) or EXC_BAD_ACCESS (SIGBUS)

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000

To know why access was invalid, we can check exception subtype-
KERN_INVALID_ADDRESS: Thread accessed unmapped memory.
KERN_PROTECTION_FAILURE: Try to use a protected memory address.
KERN_MEMORY_ERROR: Couldn’t return data at that moment
EXC_ARM_DA_ALIGN: Try to access memory that isn’t appropriately aligned.

To know memory in app which cause this, we can check VM Region Info-

VM Region Info: 0 is not in any region.  Bytes before following region: 4307009536      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL      UNUSED SPACE AT START--->        __TEXT                 0000000100b7c000-0000000100b84000 [   32K] r-x/r-x SM=COW  ...pp/MyGreatApp

To know more checkout : https://developer.apple.com/documentation/xcode/investigating-memory-access-crashes

Zombie Objects:

This type of crash occurs when Objective-C runtime tries to send messages to an object which is already deallocated from memory and no longer exists.

In this case crashes often occur in below functions:-
objc_msgSend: Send a message to the deallocated object
objc_retain: The pointer may refer to memory that was previously used for a different object.
objc_release: Tries to release an object that’s already released.

We can check thread to identify type -

Thread 0 Crashed:0   
libobjc.A.dylib 0x00000001a186d190 objc_msgSend + 16
1 Foundation 0x00000001a1f31238 __NSThreadPerformPerform + 232
2 CoreFoundation 0x00000001a1ac67e0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24

Apart from these functions, if an object call a method which is not implemented in object, cause zombie object, it identified from Last Exception Backtrace

Last Exception Backtrace:
0 CoreFoundation 0x1bf596a48 __exceptionPreprocess + 220
1 libobjc.A.dylib 0x1bf2bdfa4 objc_exception_throw + 55
2 CoreFoundation 0x1bf49a5a8 -[NSObject+ 193960 (NSObject) doesNotRecognizeSelector:] + 139

A zombie identified by an unrecognized selector has a call stack with the doesNotRecognizeSelector(_:)

To know more checkout : https://developer.apple.com/documentation/xcode/investigating-crashes-for-zombie-objects

Conclusion :

In this post we were trying to identify the common cause of crash by observing the pattern in the crash report. We tried to cover some major causes. Once we will be able to identify the cause we can quickly resolve it by taking specific action and save our time.

Thank you for reading!

--

--

i.vikash

Tech enthusiast exploring software architecture, development, and innovation. Join me on my journey of tech discovery! 🚀 #TechExploration