diff options
author | Mattes D <github@xoft.cz> | 2014-11-30 11:10:28 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-11-30 11:10:28 +0100 |
commit | d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77 (patch) | |
tree | 62f795395e2b5fa42922b784e7da85b6de122eb5 /src/OSSupport/StackTrace.cpp | |
parent | Merge pull request #1622 from M10360/master (diff) | |
parent | Fixed MCADefrag compilation. (diff) | |
download | cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar.gz cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar.bz2 cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar.lz cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar.xz cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.tar.zst cuberite-d8e6931fe69a337d35fd7ee6cd9febe6d6d73d77.zip |
Diffstat (limited to 'src/OSSupport/StackTrace.cpp')
-rw-r--r-- | src/OSSupport/StackTrace.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp new file mode 100644 index 000000000..57c547fa1 --- /dev/null +++ b/src/OSSupport/StackTrace.cpp @@ -0,0 +1,43 @@ + +// 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> +#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 +} + + + + |