Home | History | Annotate | Download | only in inspector
      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_V8STACKTRACEIMPL_H_
      6 #define V8_INSPECTOR_V8STACKTRACEIMPL_H_
      7 
      8 #include <vector>
      9 
     10 #include "src/base/macros.h"
     11 #include "src/inspector/protocol/Forward.h"
     12 #include "src/inspector/protocol/Runtime.h"
     13 
     14 #include "include/v8-inspector.h"
     15 
     16 namespace v8_inspector {
     17 
     18 class TracedValue;
     19 class V8Debugger;
     20 
     21 // Note: async stack trace may have empty top stack with non-empty tail to
     22 // indicate
     23 // that current native-only state had some async story.
     24 // On the other hand, any non-top async stack is guaranteed to be non-empty.
     25 class V8StackTraceImpl final : public V8StackTrace {
     26  public:
     27   static const size_t maxCallStackSizeToCapture = 200;
     28 
     29   class Frame {
     30    public:
     31     Frame();
     32     Frame(const String16& functionName, const String16& scriptId,
     33           const String16& scriptName, int lineNumber, int column = 0);
     34     ~Frame();
     35 
     36     const String16& functionName() const { return m_functionName; }
     37     const String16& scriptId() const { return m_scriptId; }
     38     const String16& sourceURL() const { return m_scriptName; }
     39     int lineNumber() const { return m_lineNumber; }
     40     int columnNumber() const { return m_columnNumber; }
     41     Frame clone() const;
     42 
     43    private:
     44     friend class V8StackTraceImpl;
     45     std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject() const;
     46     void toTracedValue(TracedValue*) const;
     47 
     48     String16 m_functionName;
     49     String16 m_scriptId;
     50     String16 m_scriptName;
     51     int m_lineNumber;
     52     int m_columnNumber;
     53   };
     54 
     55   static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*,
     56                                                         bool capture);
     57   static std::unique_ptr<V8StackTraceImpl> create(
     58       V8Debugger*, int contextGroupId, v8::Local<v8::StackTrace>,
     59       size_t maxStackSize, const String16& description = String16());
     60   static std::unique_ptr<V8StackTraceImpl> capture(
     61       V8Debugger*, int contextGroupId, size_t maxStackSize,
     62       const String16& description = String16());
     63 
     64   // This method drops the async chain. Use cloneImpl() instead.
     65   std::unique_ptr<V8StackTrace> clone() override;
     66   std::unique_ptr<V8StackTraceImpl> cloneImpl();
     67   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectForTail(
     68       V8Debugger*) const;
     69   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl()
     70       const;
     71   ~V8StackTraceImpl() override;
     72 
     73   // V8StackTrace implementation.
     74   bool isEmpty() const override { return !m_frames.size(); };
     75   StringView topSourceURL() const override;
     76   int topLineNumber() const override;
     77   int topColumnNumber() const override;
     78   StringView topScriptId() const override;
     79   StringView topFunctionName() const override;
     80   std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject()
     81       const override;
     82   std::unique_ptr<StringBuffer> toString() const override;
     83 
     84   void setCreation(std::unique_ptr<V8StackTraceImpl> creation);
     85 
     86  private:
     87   V8StackTraceImpl(int contextGroupId, const String16& description,
     88                    std::vector<Frame>& frames,
     89                    std::unique_ptr<V8StackTraceImpl> parent);
     90 
     91   int m_contextGroupId;
     92   String16 m_description;
     93   std::vector<Frame> m_frames;
     94   std::unique_ptr<V8StackTraceImpl> m_parent;
     95   std::unique_ptr<V8StackTraceImpl> m_creation;
     96 
     97   DISALLOW_COPY_AND_ASSIGN(V8StackTraceImpl);
     98 };
     99 
    100 }  // namespace v8_inspector
    101 
    102 #endif  // V8_INSPECTOR_V8STACKTRACEIMPL_H_
    103