News for hackers. Stuff that matters.
[dead]
Re: by krackers on Wednesday November 08, 2023 @07:38PM (#38199343)
If you're on mac (where I assume the two are already available), what compiler flags need to be passed in to do this?
Re: by torarnv on Wednesday November 08, 2023 @11:43PM (#38201272)
$ 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: by eatonphil on Wednesday November 08, 2023 @08:01PM (#38199531)
Looks like <stacktrace> 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

Re: by favorited on Wednesday November 08, 2023 @09:59PM (#38200572)
If you're on the Mac, your process is probably linking the Swift runtime anyway. Foundation.framework is being reimplemented in Swift, so if your process links Foundation (or even just CF), you've got the Swift runtime.
Re: by anarazel on Thursday November 09, 2023 @12:28AM (#38201509)
I don't think <stacktrace> is async signal safe, and thus shouldn't be used for in-process crash reporting.
Re: by yaglo on Thursday November 09, 2023 @04:27AM (#38202831)
It’s a nicer experience during development out of the box, without having to do anything manually.

Swift Backtrace is not only about the symbols, it’s also interactive and lets you attach the debugger after the process crashes, which is neat.