Aussie AI
Debug Stacktrace
-
Book Excerpt from "Generative AI in C++"
-
by David Spuler, Ph.D.
Debug Stacktrace
There are various situations where it can be useful to have a programmatic method for reporting the “stack trace” or “backtrace” of the function call stack in C++. Some examples include:
- Your assertion macro can report the full stack trace on failure.
- Self-testing code similarly can report the location.
- Debug wrapper functions too.
- Writing your own memory allocation tracker library.
C++ is about to have standard stacktrace capabilities
with its standardization in C++23.
This is available via the “std::stacktrace
” facility, such as printing the current stack via:
std::cout << "Stacktrace: " << std::stacktrace::current() << std::endl;
The C++23 stacktrace
library is already supported by GCC and early support in MSVS
is available via a compiler flag “/std:c++latest
”.
There are also two different longstanding implementations of stacktrace capabilities:
glibc backtrace
and Boost StackTrace
.
The C++23 standardized version is based on Boost's version.
• Next: • Up: Table of Contents |
The new AI programming book by Aussie AI co-founders:
Get your copy from Amazon: Generative AI in C++ |