summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/StackTrace.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-11-29 23:06:10 +0100
committerMattes D <github@xoft.cz>2014-11-29 23:06:10 +0100
commit201313a9f84192ad7f2fcd7e4ab2cc793a85b96f (patch)
treedacc0cc4d1d81cda9c4c9c8bf8fc1fff0dff2f13 /src/OSSupport/StackTrace.cpp
parentMerge pull request #1619 from mc-server/WarningFixes (diff)
downloadcuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar.gz
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar.bz2
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar.lz
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar.xz
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.tar.zst
cuberite-201313a9f84192ad7f2fcd7e4ab2cc793a85b96f.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/StackTrace.cpp43
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
+}
+
+
+
+