BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Swift 5.9 Backtracer is Now Concurrency-Aware, Improves Readability and Linux Support

Swift 5.9 Backtracer is Now Concurrency-Aware, Improves Readability and Linux Support

Besides extending the language through macros and borrow-stile memory management, Swift 5.9 also introduces some helpful features for program debugging, including an out-of-process crash handler, just-in-time debugging support, and backtracking to makes it easier to interpret control flow when using structured concurrency.

Out-of-process crash handling is a powerful new feature that will prevent a program from crashing normally and gives you the possibility to inspect it or attach a debugger to it.

When this new feature is enabled and your program crashes, you will be presented with a prompt allowing you to change the backtracer settings, generate a new backtrace, list loaded images, display register and memory contents, and get a listing of all of the threads in the process. Alternatively, you can attach a debugger to the crashed process and inspect its state interactively. If you do not choose any option, the program will crash after 30 seconds or a configurable amount of time.

The out-of-process crash handler is specifically relevant for Linux developers, who were used to getting just a succinct error message on the console for a program crash without any additional facilities. For this reason, the crash handler is on by default on Linux, while it must be manually enabled on macOS. On Windows, the new feature is not supported yet, but developers can access the OS built-in crash report to get additional information about what caused the crash.

Another welcome improvement is that the backtracer is now concurrency-aware, meaning it will be able to step back through asynchronous frames, such as when an async function is executed through an await statement. In such cases, the await/async call will appear like a normal call in the backtrace and will not show intermediate frames belonging to the runtime await/async mechanics. This new feature requires the backtracer to be able to look up program symbols to tell if a frame is asynchronous, though.

As a final note, the new backtracer is Swift 5.9 also improves readability by letting you configure the maximum number of frames that the backtracer will generate as well as the number of frames at the top of the stack you want to be displayed. Additionally, it will by default skip over system frames and Swift thunks, which are seldom of any interest to app developers.

About the Author

Rate this Article

Adoption
Style

BT