summaryrefslogtreecommitdiffstats
path: root/source/core/slang-platform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-platform.cpp')
-rw-r--r--source/core/slang-platform.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index 2c2bdd25e..aab1f3044 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -15,6 +15,11 @@
#include <dlfcn.h>
#endif
+
+#if SLANG_LINUX_FAMILY
+#include <execinfo.h>
+#endif
+
namespace Slang
{
// SharedLibrary
@@ -331,4 +336,25 @@ static const PlatformFlags s_familyFlags[int(PlatformFamily::CountOf)] = {
#endif
}
+/* static */ void PlatformUtil::backtrace()
+{
+#if SLANG_LINUX_FAMILY
+ // Print stack trace for debugging assistance
+ void* stackTrace[64];
+ int stackDepth = ::backtrace(stackTrace, 64);
+ char** symbols = ::backtrace_symbols(stackTrace, stackDepth);
+ if (symbols)
+ {
+ for (int i = 0; i < stackDepth; ++i)
+ {
+ fprintf(stdout, "%s\n", symbols[i]);
+ }
+ free(symbols);
+ }
+ fprintf(stdout, "\n");
+#else
+ fprintf(stdout, "Stack trace not available on this platform.\n");
+#endif
+}
+
} // namespace Slang