Reviewers: titzer, Dmitry Lomov (chromium), rossberg,

Description:
Implement OS::DumpBacktrace() for Mac OS.

Please review this at https://codereview.chromium.org/18431004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/platform-macos.cc


Index: src/platform-macos.cc
diff --git a/src/platform-macos.cc b/src/platform-macos.cc
index e8c25fae93ad0cce3ec54a96a50270fc762c47f8..7677507ec59d0a51c5b7d6d0bfc605f75ecdda9e 100644
--- a/src/platform-macos.cc
+++ b/src/platform-macos.cc
@@ -53,6 +53,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <cxxabi.h>

 #undef MAP_TYPE

@@ -189,7 +190,33 @@ void OS::DebugBreak() {


 void OS::DumpBacktrace() {
-  // Currently unsupported.
+ // If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
+  if (backtrace == NULL) return;
+  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) { // NOLINT
+        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);
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to