Index: src/platform-linux.cc |
diff --git a/src/platform-linux.cc b/src/platform-linux.cc |
index 8022ba2d5af110ab24f155872736ed3d9a6b5f9d..d05dbb7c9181c8fecd6ea160eeef5a75a9b9f35e 100644 |
--- a/src/platform-linux.cc |
+++ b/src/platform-linux.cc |
@@ -38,6 +38,11 @@ |
#include <sys/types.h> |
#include <stdlib.h> |
+#if defined(__GLIBC__) |
+#include <execinfo.h> |
+#include <cxxabi.h> |
+#endif |
+ |
// Ubuntu Dapper requires memory pages to be marked as |
// executable. Otherwise, OS raises an exception when executing code |
// in that page. |
@@ -415,6 +420,37 @@ void OS::DebugBreak() { |
} |
+void OS::DumpBacktrace() { |
+#if defined(__GLIBC__) |
+ void* trace[100]; |
+ int size = backtrace(trace, ARRAY_SIZE(trace)); |
+ char** symbols = backtrace_symbols(trace, size); |
+ fprintf(stderr, "\n==== C stack trace ===============================\n\n"); |
+ if (size == 0) { |
+ fprintf(stderr, "(empty)\n"); |
+ } else if (symbols == NULL) { |
+ fprintf(stderr, "(no symbols)\n"); |
+ } else { |
+ for (int i = 1; i < size; ++i) { |
+ fprintf(stderr, "%2d: ", i); |
+ char mangled[201]; |
+ if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { |
+ int status; |
+ size_t length; |
+ char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); |
+ fprintf(stderr, "%s\n", demangled ? demangled : mangled); |
+ free(demangled); |
+ } else { |
+ fprintf(stderr, "??\n"); |
+ } |
+ } |
+ } |
+ fflush(stderr); |
+ free(symbols); |
+#endif |
+} |
+ |
+ |
class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
public: |
PosixMemoryMappedFile(FILE* file, void* memory, int size) |