diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-11-30 19:38:52 +0100 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-11-30 19:38:52 +0100 |
commit | 6adf749164d7bc98bf34173b1f9d64804913d734 (patch) | |
tree | e15bd9dd8512fdbb61736db4d2d0b1f218bb81f0 /src/OSSupport/StackTrace.cpp | |
parent | Removed old MobType category. (diff) | |
parent | Hopefully fixed random build fails (diff) | |
download | cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar.gz cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar.bz2 cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar.lz cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar.xz cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.tar.zst cuberite-6adf749164d7bc98bf34173b1f9d64804913d734.zip |
Diffstat (limited to 'src/OSSupport/StackTrace.cpp')
-rw-r--r-- | src/OSSupport/StackTrace.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp new file mode 100644 index 000000000..a56568457 --- /dev/null +++ b/src/OSSupport/StackTrace.cpp @@ -0,0 +1,44 @@ + +// StackTrace.cpp + +// Implements the functions to print current stack traces + +#include "Globals.h" +#include "StackTrace.h" +#ifdef _WIN32 + #include "../StackWalker.h" +#else + #include <execinfo.h> + #include <unistd.h> +#endif + + + + + +void PrintStackTrace(void) +{ + #ifdef _WIN32 + // Reuse the StackWalker from the LeakFinder project already bound to MCS + // Define a subclass of the StackWalker that outputs everything to stdout + class PrintingStackWalker : + public StackWalker + { + virtual void OnOutput(LPCSTR szText) override + { + puts(szText); + } + } sw; + sw.ShowCallstack(); + #else + // Use the backtrace() function to get and output the stackTrace: + // Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes + void * stackTrace[30]; + size_t numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); + backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO); + #endif +} + + + + |