Add stack symbols for debug v8 module 20/319020/5
authorchenhuasheng <hsheng.chen@samsung.com>
Sat, 12 Oct 2024 13:53:30 +0000 (21:53 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 15 Oct 2024 02:49:22 +0000 (02:49 +0000)
when call v8 module stack trace
current:
 3174.738 I/V8      (P 9431, T 9460): ==== C stack trace ===============================
 3174.738 I/V8      (P 9431, T 9460):
 3174.738 I/V8      (P 9431, T 9460):     /usr/share/chromium-efl/lib/libchromium-impl.so(+0x3c727f2) [0xb2f747f2]
 3174.738 I/V8      (P 9431, T 9460):     /usr/share/chromium-efl/lib/libchromium-impl.so(+0x1ec4a32) [0xb11c6a32]
 3174.738 I/V8      (P 9431, T 9460):     /usr/share/chromium-efl/lib/libchromium-impl.so(+0x1ec2994) [0xb11c4994]
 3174.738 I/V8      (P 9431, T 9460):     /usr/share/chromium-efl/lib/libchromium-impl.so(+0x1edcbb4) [0xb11debb4]
 3174.738 I/V8      (P 9431, T 9460):     /usr/share/chromium-efl/lib/libchromium-impl.so(+0x1edc6bc) [0xb11de6bc]

later:
  174.476 I/V8      (P 5491, T 5622): ==== C stack trace ===============================
  174.476 I/V8      (P 5491, T 5622):
  174.476 I/V8      (P 5491, T 5622): #0 0x0000b2f65702 v8::base::debug::StackTrace::StackTrace()
  174.476 I/V8      (P 5491, T 5622): #1 0x0000b11b79c0 v8::internal::GCTracer::Print()
  174.476 I/V8      (P 5491, T 5622): #2 0x0000b11b5914 v8::internal::GCTracer::StopObservablePause()
  174.476 I/V8      (P 5491, T 5622): #3 0x0000b11cfb4c v8::internal::Heap::CollectGarbage()::$_2::operator()()
  174.476 I/V8      (P 5491, T 5622): #4 0x0000b11cf654 heap::base::Stack::SetMarkerAndCallbackImpl<>()

How to call v8 stack trace
1. #include  "src/base/debug/stack_trace.h"
2. std::string str = v8::base::debug::StackTrace().ToString();
   v8::internal::PrintF("%s\n", str.c_str());

Change-Id: If3fc482425c3359e54b0e4f304bf15d42cebc48a
Signed-off-by: chenhuasheng <hsheng.chen@samsung.com>
base/third_party/symbolize/BUILD.gn
v8/BUILD.gn
v8/src/base/debug/stack_trace.h
v8/src/base/debug/stack_trace_posix.cc

index 63febc8232b1668e01ae298ddf91ff1b813f4bc6..096179b52c355bc0ae70eb5e7411606ba8a621ba 100644 (file)
@@ -21,7 +21,7 @@ config("symbolize_config") {
 }
 
 static_library("symbolize") {
-  visibility = [ "//base/*" ]
+  visibility = [ "//base/*", "//v8/*" ]
   sources = [
     "config.h",
     "demangle.cc",
index 758bca88fae94973683360b1cc892d653e8810bf..feb2685dfb8238a8493ff650d6c4cf5921e52810 100644 (file)
@@ -6312,6 +6312,7 @@ v8_component("v8_libbase") {
     if (use_ttrace) {
       deps += [ "//tizen_src/chromium_impl/base:trace_event_ttrace" ]
     }
+    deps += [ "//base/third_party/symbolize" ]
   } else if (current_os == "aix") {
     sources += [
       "src/base/debug/stack_trace_posix.cc",
index 2acd0029ec5b45fea111be69ac9066302a5a1a78..6661dfbde839ecff7d790d6e4c92c43b3cf77ec7 100644 (file)
@@ -20,6 +20,8 @@
 #include <unistd.h>
 #endif
 
+#include "build/build_config.h"
+
 #if V8_OS_WIN
 struct _EXCEPTION_POINTERS;
 struct _CONTEXT;
@@ -78,12 +80,15 @@ class V8_BASE_EXPORT StackTrace {
   void InitTrace(const _CONTEXT* context_record);
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  static const int kMaxTraces = 250;
+#else
   // From http://msdn.microsoft.com/en-us/library/bb204633.aspx,
   // the sum of FramesToSkip and FramesToCapture must be less than 63,
   // so set it to 62. Even if on POSIX it could be a larger value, it usually
   // doesn't give much more information.
   static const int kMaxTraces = 62;
-
+#endif
   void* trace_[kMaxTraces];
 
   // The number of valid frames in |trace_|.
index b4e6499a5ea4e2741674466845ee661f01845be5..4f8cc96a6597433b756984a7932006cdd39146c1 100644 (file)
@@ -42,6 +42,8 @@
 #include "src/base/logging.h"
 #include "src/base/macros.h"
 
+#include "base/third_party/symbolize/symbolize.h"
+
 namespace v8 {
 namespace base {
 namespace debug {
@@ -139,6 +141,40 @@ void OutputPointer(void* pointer, BacktraceOutputHandler* handler) {
   handler->HandleOutput(buf);
 }
 
+void OutputValue(size_t value, BacktraceOutputHandler* handler) {
+  // Max unsigned 64-bit number in decimal has 20 digits (18446744073709551615).
+  // Hence, 30 digits should be more than enough to represent it in decimal
+  // (including the null-terminator).
+  char buf[30] = {'\0'};
+  internal::itoa_r(static_cast<intptr_t>(value), buf, sizeof(buf), 10, 1);
+  handler->HandleOutput(buf);
+}
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void ProcessBacktraceImpl(void* const* trace,
+                          size_t size,
+                          BacktraceOutputHandler* handler) {
+  for (size_t i = 0; i < size; ++i) {
+    handler->HandleOutput("#");
+    OutputValue(i, handler);
+
+    handler->HandleOutput(" ");
+    OutputPointer(trace[i], handler);
+    handler->HandleOutput(" ");
+
+    char buf[1024] = {'\0'};
+    const void* address = static_cast<const char*>(trace[i]) - 1;
+    if (google::Symbolize(const_cast<void*>(address), buf, sizeof(buf))) {
+      handler->HandleOutput(buf);
+    } else {
+      handler->HandleOutput("<unknown>");
+    }
+
+    handler->HandleOutput("\n");
+  }
+}
+#endif
+
 void ProcessBacktrace(void* const* trace, size_t size,
                       BacktraceOutputHandler* handler) {
   // NOTE: This code MUST be async-signal safe (it's used by in-process
@@ -152,6 +188,10 @@ void ProcessBacktrace(void* const* trace, size_t size,
   // Below part is async-signal unsafe (uses malloc), so execute it only
   // when we are not executing the signal handler.
   if (in_signal_handler == 0) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    ProcessBacktraceImpl(trace, size, handler);
+    printed = true;
+#else
     std::unique_ptr<char*, FreeDeleter> trace_symbols(
         backtrace_symbols(trace, static_cast<int>(size)));
     if (trace_symbols.get()) {
@@ -165,6 +205,7 @@ void ProcessBacktrace(void* const* trace, size_t size,
 
       printed = true;
     }
+#endif
   }
 
   if (!printed) {