Live data from Hacker News

On-Crash Backtraces in Swift

swift.org

11–20 of 21 posts

Re: On-Crash Backtraces in Swift

#12
post #3
post #2

The best part of is that you can get all this goodness even without having Swift code in your codebase. 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.

If you're on mac (where I assume the two are already available), what compiler flags need to be passed in to do this?

$ clang++ foo.cpp -o foo -framework Foundation

-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!

Re: On-Crash Backtraces in Swift

#13
post #2

The best part of is that you can get all this goodness even without having Swift code in your codebase. 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.

Looks like is already part of C++23 [0]. But if you must use an older C++, why link the entire Swift runtime rather than something GCC's builtin backtraces [1] or libbacktrace [2]? [0] https://www.sandordargo.com/blog/2022/09/21/cpp23-stacktrace... [1] https://www.gnu.org/software/libc/manual/html_node/Backtrace... [2] https://github.com/ianlancetaylor/libbacktrace

I don't think is async signal safe, and thus shouldn't be used for in-process crash reporting.

Re: On-Crash Backtraces in Swift

#14
post #2

The best part of is that you can get all this goodness even without having Swift code in your codebase. 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.

Looks like is already part of C++23 [0]. But if you must use an older C++, why link the entire Swift runtime rather than something GCC's builtin backtraces [1] or libbacktrace [2]? [0] https://www.sandordargo.com/blog/2022/09/21/cpp23-stacktrace... [1] https://www.gnu.org/software/libc/manual/html_node/Backtrace... [2] https://github.com/ianlancetaylor/libbacktrace

It’s a nicer experience during development out of the box, without having to do anything manually.

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.

Re: On-Crash Backtraces in Swift

#15
I'm not so keen on programs trying to be clever like this. How about making the system debugger better, which will benefit all programs? Actually that's not even necessary as abrt / coredumpctl on Linux are pretty good these days, even being able to automatically file a bug report with your distro.

Re: On-Crash Backtraces in Swift

#16
> On Apple platforms or on Windows, you could look at the crash logs captured by the operating system’s built-in crash reporter, but on Linux that’s typically all you had to go on.

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.

Re: On-Crash Backtraces in Swift

#18
This can be useful.

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).

Re: On-Crash Backtraces in Swift

#20

This can be useful. 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).

Within Xcode, you don’t really need it because you’re already running with a debugger when you launch your program.
Post reply on HN