LCOV - code coverage report
Current view: top level - src/inspector - v8-stack-trace-impl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2019-02-19 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2016 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_
       6             : #define V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_
       7             : 
       8             : #include <memory>
       9             : #include <vector>
      10             : 
      11             : #include "include/v8-inspector.h"
      12             : #include "include/v8.h"
      13             : #include "src/base/macros.h"
      14             : #include "src/inspector/protocol/Runtime.h"
      15             : #include "src/inspector/string-16.h"
      16             : 
      17             : namespace v8_inspector {
      18             : 
      19             : class AsyncStackTrace;
      20             : class V8Debugger;
      21             : class WasmTranslation;
      22             : struct V8StackTraceId;
      23             : 
      24             : class StackFrame {
      25             :  public:
      26             :   explicit StackFrame(v8::Isolate* isolate, v8::Local<v8::StackFrame> frame);
      27      128858 :   ~StackFrame() = default;
      28             : 
      29             :   void translate(WasmTranslation* wasmTranslation);
      30             : 
      31             :   const String16& functionName() const;
      32             :   const String16& scriptId() const;
      33             :   const String16& sourceURL() const;
      34             :   int lineNumber() const;    // 0-based.
      35             :   int columnNumber() const;  // 0-based.
      36             :   std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject(
      37             :       V8InspectorClient* client) const;
      38             :   bool isEqual(StackFrame* frame) const;
      39             : 
      40             :  private:
      41             :   String16 m_functionName;
      42             :   String16 m_scriptId;
      43             :   String16 m_sourceURL;
      44             :   int m_lineNumber;    // 0-based.
      45             :   int m_columnNumber;  // 0-based.
      46             :   bool m_hasSourceURLComment;
      47             : };
      48             : 
      49      241036 : class V8StackTraceImpl : public V8StackTrace {
      50             :  public:
      51             :   static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*,
      52             :                                                         bool capture);
      53             :   static int maxCallStackSizeToCapture;
      54             :   static std::unique_ptr<V8StackTraceImpl> create(V8Debugger*,
      55             :                                                   int contextGroupId,
      56             :                                                   v8::Local<v8::StackTrace>,
      57             :                                                   int maxStackSize);
      58             :   static std::unique_ptr<V8StackTraceImpl> capture(V8Debugger*,
      59             :                                                    int contextGroupId,
      60             :                                                    int maxStackSize);
      61             : 
      62             :   ~V8StackTraceImpl() override;
      63             :   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl(
      64             :       V8Debugger* debugger) const;
      65             : 
      66             :   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl(
      67             :       V8Debugger* debugger, int maxAsyncDepth) const;
      68             : 
      69             :   // V8StackTrace implementation.
      70             :   // This method drops the async stack trace.
      71             :   std::unique_ptr<V8StackTrace> clone() override;
      72             :   StringView firstNonEmptySourceURL() const override;
      73             :   bool isEmpty() const override;
      74             :   StringView topSourceURL() const override;
      75             :   int topLineNumber() const override;    // 1-based.
      76             :   int topColumnNumber() const override;  // 1-based.
      77             :   StringView topScriptId() const override;
      78             :   StringView topFunctionName() const override;
      79             :   std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject()
      80             :       const override;
      81             :   std::unique_ptr<StringBuffer> toString() const override;
      82             : 
      83             :   bool isEqualIgnoringTopFrame(V8StackTraceImpl* stackTrace) const;
      84             : 
      85             :  private:
      86             :   V8StackTraceImpl(std::vector<std::shared_ptr<StackFrame>> frames,
      87             :                    int maxAsyncDepth,
      88             :                    std::shared_ptr<AsyncStackTrace> asyncParent,
      89             :                    const V8StackTraceId& externalParent);
      90             : 
      91             :   class StackFrameIterator {
      92             :    public:
      93             :     explicit StackFrameIterator(const V8StackTraceImpl* stackTrace);
      94             : 
      95             :     void next();
      96             :     StackFrame* frame();
      97             :     bool done();
      98             : 
      99             :    private:
     100             :     std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentIt;
     101             :     std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentEnd;
     102             :     AsyncStackTrace* m_parent;
     103             :   };
     104             : 
     105             :   std::vector<std::shared_ptr<StackFrame>> m_frames;
     106             :   int m_maxAsyncDepth;
     107             :   std::weak_ptr<AsyncStackTrace> m_asyncParent;
     108             :   V8StackTraceId m_externalParent;
     109             : 
     110             :   DISALLOW_COPY_AND_ASSIGN(V8StackTraceImpl);
     111             : };
     112             : 
     113       10425 : class AsyncStackTrace {
     114             :  public:
     115             :   static std::shared_ptr<AsyncStackTrace> capture(V8Debugger*,
     116             :                                                   int contextGroupId,
     117             :                                                   const String16& description,
     118             :                                                   int maxStackSize);
     119             :   static uintptr_t store(V8Debugger* debugger,
     120             :                          std::shared_ptr<AsyncStackTrace> stack);
     121             : 
     122             :   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject(
     123             :       V8Debugger* debugger, int maxAsyncDepth) const;
     124             : 
     125             :   // If async stack has suspended task id, it means that at moment when we
     126             :   // capture current stack trace we suspended corresponded asynchronous
     127             :   // execution flow and it is possible to request pause for a momemnt when
     128             :   // that flow is resumed.
     129             :   // E.g. every time when we suspend async function we mark corresponded async
     130             :   // stack as suspended and every time when this function is resumed we remove
     131             :   // suspendedTaskId.
     132             :   void setSuspendedTaskId(void* task);
     133             :   void* suspendedTaskId() const;
     134             : 
     135             :   int contextGroupId() const;
     136             :   const String16& description() const;
     137             :   std::weak_ptr<AsyncStackTrace> parent() const;
     138             :   bool isEmpty() const;
     139             :   const V8StackTraceId& externalParent() const { return m_externalParent; }
     140             : 
     141             :   const std::vector<std::shared_ptr<StackFrame>>& frames() const {
     142             :     return m_frames;
     143             :   }
     144             : 
     145             :  private:
     146             :   AsyncStackTrace(int contextGroupId, const String16& description,
     147             :                   std::vector<std::shared_ptr<StackFrame>> frames,
     148             :                   std::shared_ptr<AsyncStackTrace> asyncParent,
     149             :                   const V8StackTraceId& externalParent);
     150             : 
     151             :   int m_contextGroupId;
     152             :   uintptr_t m_id;
     153             :   void* m_suspendedTaskId;
     154             :   String16 m_description;
     155             : 
     156             :   std::vector<std::shared_ptr<StackFrame>> m_frames;
     157             :   std::weak_ptr<AsyncStackTrace> m_asyncParent;
     158             :   V8StackTraceId m_externalParent;
     159             : 
     160             :   DISALLOW_COPY_AND_ASSIGN(AsyncStackTrace);
     161             : };
     162             : 
     163             : }  // namespace v8_inspector
     164             : 
     165             : #endif  // V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_

Generated by: LCOV version 1.10