r/cpp • u/Xadartt • Apr 16 '26
C++23 std::stacktrace: Never Debug Blind Again
https://medium.com/@sagar.necindia/c-23-std-stacktrace-never-debug-blind-again-6625924d520c
75
Upvotes
r/cpp • u/Xadartt • Apr 16 '26
View all comments
Show parent comment
0
u/jwakely libstdc++ tamer, LWG chair Apr 17 '26 edited Apr 17 '26
For some definition of "properly use". The API of
std::stacktracegives you the symbolic information like function names and filenames, that's how it's meant to be "properly used". If you want to do something else with it, that's a you problem. It doesn't mean that getting the symbolic information is not using it "properly".I wish people would not throw around phrases like "useless" and "unusable" when they mean "not ideal for my specific use case". I really don't see any point trying to discuss things with people who do that.
Anyway, you can use
std::stacktrace_entry::native_handle()to get at the raw data used to produce symbolic information. For GCC, that's just a program counter. Your program could loop over the stacktrace entries and log the native handles, then another process could process those logs later to turn those into symbols (alongside a core dump, I guess ... since the program counter is only meaningful for a given execution of the program). (Edit: I think you could also log the memory map of all shared libs in the process, which should be enough to reconstruct the full symbols given just the binary with debug info)