Reviewers: Michael Starzinger,

Message:
ptal

Description:
Expose DumpBacktrace for debugging purposes.

After this change, you can just call DumpBacktrace in any function. Previously the only function printing stack traces was V8_Fatal, but that also terminated
the program, so not very useful for debugging.

Note that DumpBacktrace is roughly equivalent to base::debug::StackTrace
functionality in Chromium, except less fancy, but it's enough for us.

[email protected]
BUG=

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

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

Affected files (+22, -19 lines):
  M src/checks.h
  M src/checks.cc


Index: src/checks.cc
diff --git a/src/checks.cc b/src/checks.cc
index 62e04ff205c4629ac54a0d2531a9d6a43986cfa4..ac80fac61ea9aefa60abc60c52a8db201115b947 100644
--- a/src/checks.cc
+++ b/src/checks.cc
@@ -38,30 +38,34 @@
 #include "platform.h"
 #include "v8.h"

+namespace v8 {
+namespace internal {
+
+intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }

 // Attempts to dump a backtrace (if supported).
-static V8_INLINE void DumpBacktrace() {
+void DumpBacktrace() {
 #if V8_LIBC_GLIBC || V8_OS_BSD
   void* trace[100];
   int size = backtrace(trace, ARRAY_SIZE(trace));
   char** symbols = backtrace_symbols(trace, size);
- i::OS::PrintError("\n==== C stack trace ===============================\n\n"); + OS::PrintError("\n==== C stack trace ===============================\n\n");
   if (size == 0) {
-    i::OS::PrintError("(empty)\n");
+    OS::PrintError("(empty)\n");
   } else if (symbols == NULL) {
-    i::OS::PrintError("(no symbols)\n");
+    OS::PrintError("(no symbols)\n");
   } else {
     for (int i = 1; i < size; ++i) {
-      i::OS::PrintError("%2d: ", i);
+      OS::PrintError("%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);
-        i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
+        OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
         free(demangled);
       } else {
-        i::OS::PrintError("??\n");
+        OS::PrintError("??\n");
       }
     }
   }
@@ -73,22 +77,25 @@ static V8_INLINE void DumpBacktrace() {
   bt_init_accessor(&acc, BT_SELF);
   bt_load_memmap(&acc, &memmap);
   bt_sprn_memmap(&memmap, out, sizeof(out));
-  i::OS::PrintError(out);
+  OS::PrintError(out);
   bt_addr_t trace[100];
   int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace));
- i::OS::PrintError("\n==== C stack trace ===============================\n\n"); + OS::PrintError("\n==== C stack trace ===============================\n\n");
   if (size == 0) {
-    i::OS::PrintError("(empty)\n");
+    OS::PrintError("(empty)\n");
   } else {
     bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
                    out, sizeof(out), NULL);
-    i::OS::PrintError(out);
+    OS::PrintError(out);
   }
   bt_unload_memmap(&memmap);
   bt_release_accessor(&acc);
 #endif  // V8_LIBC_GLIBC || V8_OS_BSD
 }

+}  // namespace internal
+}  // namespace v8
+

// Contains protection against recursive calls (faults while handling faults). extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { @@ -102,7 +109,7 @@ extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
   i::OS::VPrintError(format, arguments);
   va_end(arguments);
   i::OS::PrintError("\n#\n");
-  DumpBacktrace();
+  v8::internal::DumpBacktrace();
   fflush(stderr);
   i::OS::Abort();
 }
@@ -136,10 +143,3 @@ void CheckNonEqualsHelper(const char* file,
              unexpected_source, value_source, *value_str);
   }
 }
-
-
-namespace v8 { namespace internal {
-
-  intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
-
-} }  // namespace v8::internal
Index: src/checks.h
diff --git a/src/checks.h b/src/checks.h
index 57f18526186c5adbc19d011c771fa1c66e72215d..c623600dab6fa1eea63a7aa3b1542f5fca23834d 100644
--- a/src/checks.h
+++ b/src/checks.h
@@ -306,6 +306,9 @@ extern bool FLAG_enable_slow_asserts;
 #define SLOW_ASSERT(condition) ((void) 0)
 const bool FLAG_enable_slow_asserts = false;
 #endif
+
+void DumpBacktrace();
+
 }  // namespace internal
 }  // namespace v8



--
--
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/d/optout.

Reply via email to