Swift.org Blog Alastair Houghton Nov 8, 2023

Swift 5.9 Backtraces and Debugging

Article Summary

Alastair Houghton from Apple's Swift runtime team just dropped a game-changer for debugging: Swift 5.9 now catches crashes and lets you inspect them interactively before your program dies.

Swift 5.9 introduces a sophisticated out-of-process crash handler that transforms cryptic segfaults into readable, interactive debugging sessions. The feature is particularly powerful on Linux (where it's enabled by default) but also works on macOS with manual configuration.

Key Takeaways

Critical Insight

Swift 5.9's crash handler turns opaque segfaults into readable, interactive debugging sessions with source context and concurrency-aware backtraces.

The interactive prompt includes commands most developers don't know exist yet, including live memory inspection without attaching a debugger.

About This Article

Problem

When programs crashed due to deep recursion or stack overflow, developers got buried in thousands of stack frames. Most of these came from system code and compiler thunks, making it hard to find the actual bug.

Solution

Alastair Houghton's team added configurable frame limits to the crash logs. By default, it captures 64 total frames with 16 at the stack top. The tool also filters out system frames and Swift thunks automatically, leaving only the application code that matters.

Impact

The backtracer now automatically demangles Swift and C++ names and skips irrelevant runtime frames. Developers can find what caused a crash in recursive scenarios without having to manually parse logs or resolve symbols.