On-Crash Backtraces in Swift
swift.org
swift.org
On modern linux distros, simply typing `coredumpctl debug` puts you right into gdb with the core dump loaded. If debuginfod is set up (not sure what the defaults look like there across distros), it will even automatically download debug symbols for all libraries loaded at the time of the crash.
I thought I did something wrong when the crash reported looked so different. I was unaware, that since the last time I did this (ubuntu->debian .deb), the compiler had changed its error reporting.
Props to the Swift team doing the good work, and please add a .deb to the binaries artefacts!
Just link your C++ (or whatever) project with The Swift runtime (swiftrt.o and libswiftCore.so), and there you have it without writing any Swift.
-lswift_Backtracing also works, but dunno if that's "public API"
$ codesign --force --sign - --entitlements entitlements.plist foo
https://github.com/apple/swift/blob/main/docs/Backtracing.rs...
$ SWIFT_BACKTRACE="enable=yes" ./foo
Very cool!
[0] https://www.sandordargo.com/blog/2022/09/21/cpp23-stacktrace...
[1] https://www.gnu.org/software/libc/manual/html_node/Backtrace...
Swift Backtracing is not only about the symbols, it’s also interactive and lets you attach the debugger after the process crashes, which is neat.
https://forums.swift.org/t/backtraces-in-swift/61736
https://forums.swift.org/t/pitch-swift-backtracing-api/62741
I found the backtracing API design discussions in the second link especially illuminating
Does that get you a full Swift REPL like Python's debugger does?
I'll be interested in seeing how this gets integrated into the Xcode IDE, as I rarely find the need to go into the CLI, to debug, these days (although I had to, just a couple of days ago, to find a weird Apple crash, but I could work around it).
Boo! Show me my system frames!
(Also, is this available in the Xcode toolchain yet?)
> This feature is also available on macOS but is disabled by default. To enable it, set SWIFT_BACKTRACE=enable=yes and sign your program with the com.apple.security.get-task-allow entitlement.