Index: base/debug_util_posix.cc |
diff --git a/base/debug_util_posix.cc b/base/debug_util_posix.cc |
index a83e144a853d673b4096de33ab8a4e8b509e7e3c..060f443fb39747461c3f5dfa4ba1c844e5b9fa8f 100644 |
--- a/base/debug_util_posix.cc |
+++ b/base/debug_util_posix.cc |
@@ -2,8 +2,15 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "build/build_config.h" |
#include "base/debug_util.h" |
+#if defined(OS_LINUX) |
+#include <unistd.h> |
+#include <execinfo.h> |
+#endif |
+ |
+#include <stdio.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#include <sys/sysctl.h> |
@@ -90,3 +97,38 @@ bool DebugUtil::BeingDebugged() { |
void DebugUtil::BreakDebugger() { |
asm ("int3"); |
} |
+ |
+#if defined(OS_LINUX) |
+ |
+StackTrace::StackTrace() { |
+ static const unsigned kMaxCallers = 256; |
+ |
+ void* callers[kMaxCallers]; |
+ int count = backtrace(callers, kMaxCallers); |
+ trace_.resize(count); |
+ memcpy(&trace_[0], callers, sizeof(void*) * count); |
+} |
+ |
+void StackTrace::PrintBacktrace() { |
+ fflush(stderr); |
+ backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO); |
+} |
+ |
+#elif defined(OS_MACOSX) |
+ |
+// TODO(port): complete this code |
+StackTrace::StackTrace() { } |
+ |
+StackTrace::PrintBacktrace() { |
+ NOTIMPLEMENTED(); |
+ fprintf(stderr, "<printing stacktraces not implemented>\n"); |
Evan Martin
2009/01/16 18:30:08
you won't need this anymore with the above
|
+} |
+ |
+#endif // defined(OS_MACOSX) |
+ |
+const void *const *StackTrace::Addresses(size_t* count) { |
+ *count = trace_.size(); |
+ if (trace_.size()) |
+ return &trace_[0]; |
+ return NULL; |
+} |