Revision: 19993
Author:   [email protected]
Date:     Mon Mar 17 13:33:19 2014 UTC
Log:      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=

Review URL: https://codereview.chromium.org/200343003
http://code.google.com/p/v8/source/detail?r=19993

Modified:
 /branches/bleeding_edge/src/checks.cc
 /branches/bleeding_edge/src/checks.h

=======================================
--- /branches/bleeding_edge/src/checks.cc       Tue Jan 14 09:37:45 2014 UTC
+++ /branches/bleeding_edge/src/checks.cc       Mon Mar 17 13:33:19 2014 UTC
@@ -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,21 +77,23 @@
   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 v8::internal


// Contains protection against recursive calls (faults while handling faults).
@@ -102,7 +108,7 @@
   i::OS::VPrintError(format, arguments);
   va_end(arguments);
   i::OS::PrintError("\n#\n");
-  DumpBacktrace();
+  v8::internal::DumpBacktrace();
   fflush(stderr);
   i::OS::Abort();
 }
@@ -136,10 +142,3 @@
              unexpected_source, value_source, *value_str);
   }
 }
-
-
-namespace v8 { namespace internal {
-
-  intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
-
-} }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/checks.h        Wed Feb 12 13:27:13 2014 UTC
+++ /branches/bleeding_edge/src/checks.h        Mon Mar 17 13:33:19 2014 UTC
@@ -306,8 +306,12 @@
 #define SLOW_ASSERT(condition) ((void) 0)
 const bool FLAG_enable_slow_asserts = false;
 #endif
-}  // namespace internal
-}  // namespace v8
+
+// Exposed for making debugging easier (to see where your function is being
+// called, just add a call to DumpBacktrace).
+void DumpBacktrace();
+
+} }  // namespace v8::internal


 // The ASSERT macro is equivalent to CHECK except that it only

--
--
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