Debugging Swift Crashes Using ‘atos’ in Xcode: A Detailed Guide

Anas Poovalloor
3 min readJul 5, 2024

--

Debugging crashes in a Swift application can be challenging, especially when all you have is a crash log with memory addresses. One powerful tool to aid in this process is atos, a command-line utility that converts memory addresses into human-readable symbols. This guide will walk you through the steps to effectively use atos to debug Swift crashes in Xcode.

Step-by-Step Guide

  1. Locate the Crash Log
    When your app crashes, Xcode generates a crash log. You can find this log in the device console or in the Organizer window under “Devices and Simulators.”
    In Xcode:
    → Go to Window > Organizer.
    → Select your device from the list on the left.
    → Find the crash log under the “Crashes” tab.
    On the Device:
    → Go to Settings > Privacy & Security > Analytics & Improvements > Analytics Data on your iOS device.
    → Look for crash logs that match your app.
  2. Identify the Address
    In the crash log, identify the hexadecimal memory address associated with the crash. It usually appears after 0x and is a long string of numbers and letters.
    Example snippet from a crash log:
    Exception Type: EXC_BAD_ACCESS (SIGSEGV)
    Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000100001234
    Here, 0x0000000100001234 is the address we need.
  3. Find the Binary
    Locate the binary (.app or .ipa file) that corresponds to the version of the app that crashed. This is usually in your Xcode build folder or archived app folder.
    From Xcode Archive:
    → Go to Window > Organizer.
    → Select the relevant archive.
    → Click Show in Finder to locate the binary.
    From Build Folder:
    → Navigate to your project directory.
    → Locate the DerivedData folder.
    → Find the Build/Products/Debug-iphoneos or Release-iphoneos directory.
  4. Open Terminal
    Open the Terminal app on your Mac.
  5. Navigate to the Binary Location
    Use the cd command to navigate to the folder where the binary (.app or .ipa) is located.
    cd /path/to/YourApp.app
  6. Run the atos Command
    In Terminal, type the following command:
    atos -arch ARCHITECTURE -o APP_BINARY MEMORY_ADDRESS
    • Replace ARCHITECTURE with the architecture of your binary (e.g., arm64 for devices, x86_64 for simulators).
    • Replace APP_BINARY with the path to your .app or .ipa file.
    • Replace MEMORY_ADDRESS with the hexadecimal memory address from the crash log.
    Example:
    atos -arch arm64 -o YourApp.app/YourApp 0x0000000100001234
  7. View the Symbolic Output
    After executing the command, atos will attempt to translate the memory address into a readable format. It will typically output the function name, along with the file and line number where the crash occurred.
    Example output:
    -[YourClass yourMethod] (in YourApp) (YourClass.swift:123)
atos — Terminal Screenshot

Tips for Effective Debugging

  1. Ensure Correct Architecture:
    - Use arm64 for physical devices.
    - Use x86_64 for simulators.
  2. Use Debug Symbols:
    - Ensure that your build includes debug symbols (dSYM). Without these symbols, atos may not provide meaningful output.
  3. Copy Exact Memory Address:
    - Double-check the memory address from the crash log to avoid errors.
  4. Symbolicate in Xcode:
    - Sometimes, Xcode can automatically symbolicate crash logs if it has access to the correct symbols. Use Xcode’s built-in tools for an easier experience.

Troubleshooting `atos`

  • Output Shows Address: If atos outputs the address itself instead of symbolic information, check:
    - Correct architecture (arm64 vs. x86_64).
    - Correct path to the binary.
    - Presence of debug symbols.
  • No Symbols Available: If your app binary is stripped of symbols, atos will not provide useful output. Ensure you are using a build with debug symbols included.

By following these steps, you can leverage atos to translate memory addresses in crash logs back into human-readable function names and source code locations. This greatly aids in debugging and understanding the cause of crashes in your Swift applications.

Debugging with atos provides deep insights into where your Swift application might be failing. While Xcode offers robust tools for symbolication, atos can be particularly useful for manual crash log analysis and debugging when automatic tools fall short. By mastering this utility, you can enhance your debugging toolkit and better understand your app’s runtime behavior.

Happy debugging!

--

--