Or design your software in such a way that the stacktrace is not needed for debugging. Which is hard, for sure, but the current trend of depending on stacktraces for everything (Java, Python, for example) is a bit too extreme IMO. For a comparison, in Ocaml I tend to use a result type monad for things that can fail at which point the compiler makes sure I do something with all errors.
Recall how it was compiled:
As the GCC manual says with respect to combinging
Owithg: “The shortcuts taken by optimized code may occasionally produce surprising results.”And relatedly from the clang man page:
So one should recompile for the purpose of debugging?
Yes.
GCC has
-Og, which turns on all optimizations that can’t affect debugging.Or design your software in such a way that the stacktrace is not needed for debugging. Which is hard, for sure, but the current trend of depending on stacktraces for everything (Java, Python, for example) is a bit too extreme IMO. For a comparison, in Ocaml I tend to use a result type monad for things that can fail at which point the compiler makes sure I do something with all errors.