• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEBUG_INTERFACE_TYPES_H_
6 #define V8_DEBUG_INTERFACE_TYPES_H_
7 
8 #include <cstdint>
9 #include <string>
10 #include <vector>
11 
12 #include "include/v8.h"
13 #include "src/globals.h"
14 
15 namespace v8 {
16 
17 namespace internal {
18 class BuiltinArguments;
19 }  // internal
20 
21 namespace debug {
22 
23 /**
24  * Defines location inside script.
25  * Lines and columns are 0-based.
26  */
27 class V8_EXPORT_PRIVATE Location {
28  public:
29   Location(int line_number, int column_number);
30   /**
31    * Create empty location.
32    */
33   Location();
34 
35   int GetLineNumber() const;
36   int GetColumnNumber() const;
37   bool IsEmpty() const;
38 
39  private:
40   int line_number_;
41   int column_number_;
42   bool is_empty_;
43 };
44 
45 /**
46  * The result of disassembling a wasm function.
47  * Consists of the disassembly string and an offset table mapping wasm byte
48  * offsets to line and column in the disassembly.
49  * The offset table entries are ordered by the byte_offset.
50  * All numbers are 0-based.
51  */
52 struct WasmDisassemblyOffsetTableEntry {
WasmDisassemblyOffsetTableEntryWasmDisassemblyOffsetTableEntry53   WasmDisassemblyOffsetTableEntry(uint32_t byte_offset, int line, int column)
54       : byte_offset(byte_offset), line(line), column(column) {}
55 
56   uint32_t byte_offset;
57   int line;
58   int column;
59 };
60 
61 struct WasmDisassembly {
62   using OffsetTable = std::vector<WasmDisassemblyOffsetTableEntry>;
WasmDisassemblyWasmDisassembly63   WasmDisassembly() {}
WasmDisassemblyWasmDisassembly64   WasmDisassembly(std::string disassembly, OffsetTable offset_table)
65       : disassembly(std::move(disassembly)),
66         offset_table(std::move(offset_table)) {}
67 
68   std::string disassembly;
69   OffsetTable offset_table;
70 };
71 
72 enum DebugAsyncActionType {
73   kDebugPromiseThen,
74   kDebugPromiseCatch,
75   kDebugPromiseFinally,
76   kDebugWillHandle,
77   kDebugDidHandle,
78   kAsyncFunctionSuspended,
79   kAsyncFunctionFinished
80 };
81 
82 enum BreakLocationType {
83   kCallBreakLocation,
84   kReturnBreakLocation,
85   kDebuggerStatementBreakLocation,
86   kCommonBreakLocation
87 };
88 
89 class V8_EXPORT_PRIVATE BreakLocation : public Location {
90  public:
BreakLocation(int line_number,int column_number,BreakLocationType type)91   BreakLocation(int line_number, int column_number, BreakLocationType type)
92       : Location(line_number, column_number), type_(type) {}
93 
type()94   BreakLocationType type() const { return type_; }
95 
96  private:
97   BreakLocationType type_;
98 };
99 
100 class ConsoleCallArguments : private v8::FunctionCallbackInfo<v8::Value> {
101  public:
Length()102   int Length() const { return v8::FunctionCallbackInfo<v8::Value>::Length(); }
103   V8_INLINE Local<Value> operator[](int i) const {
104     return v8::FunctionCallbackInfo<v8::Value>::operator[](i);
105   }
106 
107   explicit ConsoleCallArguments(const v8::FunctionCallbackInfo<v8::Value>&);
108   explicit ConsoleCallArguments(internal::BuiltinArguments&);
109 };
110 
111 class ConsoleContext {
112  public:
ConsoleContext(int id,v8::Local<v8::String> name)113   ConsoleContext(int id, v8::Local<v8::String> name) : id_(id), name_(name) {}
ConsoleContext()114   ConsoleContext() : id_(0) {}
115 
id()116   int id() const { return id_; }
name()117   v8::Local<v8::String> name() const { return name_; }
118 
119  private:
120   int id_;
121   v8::Local<v8::String> name_;
122 };
123 
124 class ConsoleDelegate {
125  public:
Debug(const ConsoleCallArguments & args,const ConsoleContext & context)126   virtual void Debug(const ConsoleCallArguments& args,
127                      const ConsoleContext& context) {}
Error(const ConsoleCallArguments & args,const ConsoleContext & context)128   virtual void Error(const ConsoleCallArguments& args,
129                      const ConsoleContext& context) {}
Info(const ConsoleCallArguments & args,const ConsoleContext & context)130   virtual void Info(const ConsoleCallArguments& args,
131                     const ConsoleContext& context) {}
Log(const ConsoleCallArguments & args,const ConsoleContext & context)132   virtual void Log(const ConsoleCallArguments& args,
133                    const ConsoleContext& context) {}
Warn(const ConsoleCallArguments & args,const ConsoleContext & context)134   virtual void Warn(const ConsoleCallArguments& args,
135                     const ConsoleContext& context) {}
Dir(const ConsoleCallArguments & args,const ConsoleContext & context)136   virtual void Dir(const ConsoleCallArguments& args,
137                    const ConsoleContext& context) {}
DirXml(const ConsoleCallArguments & args,const ConsoleContext & context)138   virtual void DirXml(const ConsoleCallArguments& args,
139                       const ConsoleContext& context) {}
Table(const ConsoleCallArguments & args,const ConsoleContext & context)140   virtual void Table(const ConsoleCallArguments& args,
141                      const ConsoleContext& context) {}
Trace(const ConsoleCallArguments & args,const ConsoleContext & context)142   virtual void Trace(const ConsoleCallArguments& args,
143                      const ConsoleContext& context) {}
Group(const ConsoleCallArguments & args,const ConsoleContext & context)144   virtual void Group(const ConsoleCallArguments& args,
145                      const ConsoleContext& context) {}
GroupCollapsed(const ConsoleCallArguments & args,const ConsoleContext & context)146   virtual void GroupCollapsed(const ConsoleCallArguments& args,
147                               const ConsoleContext& context) {}
GroupEnd(const ConsoleCallArguments & args,const ConsoleContext & context)148   virtual void GroupEnd(const ConsoleCallArguments& args,
149                         const ConsoleContext& context) {}
Clear(const ConsoleCallArguments & args,const ConsoleContext & context)150   virtual void Clear(const ConsoleCallArguments& args,
151                      const ConsoleContext& context) {}
Count(const ConsoleCallArguments & args,const ConsoleContext & context)152   virtual void Count(const ConsoleCallArguments& args,
153                      const ConsoleContext& context) {}
CountReset(const ConsoleCallArguments & args,const ConsoleContext & context)154   virtual void CountReset(const ConsoleCallArguments& args,
155                           const ConsoleContext& context) {}
Assert(const ConsoleCallArguments & args,const ConsoleContext & context)156   virtual void Assert(const ConsoleCallArguments& args,
157                       const ConsoleContext& context) {}
Profile(const ConsoleCallArguments & args,const ConsoleContext & context)158   virtual void Profile(const ConsoleCallArguments& args,
159                        const ConsoleContext& context) {}
ProfileEnd(const ConsoleCallArguments & args,const ConsoleContext & context)160   virtual void ProfileEnd(const ConsoleCallArguments& args,
161                           const ConsoleContext& context) {}
Time(const ConsoleCallArguments & args,const ConsoleContext & context)162   virtual void Time(const ConsoleCallArguments& args,
163                     const ConsoleContext& context) {}
TimeEnd(const ConsoleCallArguments & args,const ConsoleContext & context)164   virtual void TimeEnd(const ConsoleCallArguments& args,
165                        const ConsoleContext& context) {}
TimeStamp(const ConsoleCallArguments & args,const ConsoleContext & context)166   virtual void TimeStamp(const ConsoleCallArguments& args,
167                          const ConsoleContext& context) {}
168   virtual ~ConsoleDelegate() = default;
169 };
170 
171 typedef int BreakpointId;
172 
173 }  // namespace debug
174 }  // namespace v8
175 
176 #endif  // V8_DEBUG_INTERFACE_TYPES_H_
177