V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
debug-objects.h
1 // Copyright 2017 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_OBJECTS_DEBUG_OBJECTS_H_
6 #define V8_OBJECTS_DEBUG_OBJECTS_H_
7 
8 #include "src/objects.h"
9 #include "src/objects/fixed-array.h"
10 
11 // Has to be the last include (doesn't have include guards):
12 #include "src/objects/object-macros.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class BreakPoint;
18 class BytecodeArray;
19 
20 // The DebugInfo class holds additional information for a function being
21 // debugged.
22 class DebugInfo : public Struct, public NeverReadOnlySpaceObject {
23  public:
24  enum Flag {
25  kNone = 0,
26  kHasBreakInfo = 1 << 0,
27  kPreparedForDebugExecution = 1 << 1,
28  kHasCoverageInfo = 1 << 2,
29  kBreakAtEntry = 1 << 3,
30  kCanBreakAtEntry = 1 << 4,
31  kDebugExecutionMode = 1 << 5
32  };
33 
34  typedef base::Flags<Flag> Flags;
35 
36  // A bitfield that lists uses of the current instance.
37  DECL_INT_ACCESSORS(flags)
38 
39  // The shared function info for the source being debugged.
40  DECL_ACCESSORS(shared, SharedFunctionInfo)
41 
42  // Bit field containing various information collected for debugging.
43  DECL_INT_ACCESSORS(debugger_hints)
44 
45  // Script field from shared function info.
46  DECL_ACCESSORS(script, Object)
47 
48  // DebugInfo can be detached from the SharedFunctionInfo iff it is empty.
49  bool IsEmpty() const;
50 
51  // --- Debug execution ---
52  // -----------------------
53 
54  enum ExecutionMode { kBreakpoints = 0, kSideEffects = kDebugExecutionMode };
55 
56  // Returns current debug execution mode. Debug execution mode defines by
57  // applied to bytecode patching. False for breakpoints, true for side effect
58  // checks.
59  ExecutionMode DebugExecutionMode() const;
60  void SetDebugExecutionMode(ExecutionMode value);
61 
62  // Specifies whether the associated function has an instrumented bytecode
63  // array. If so, OriginalBytecodeArray returns the non-instrumented bytecode,
64  // and DebugBytecodeArray returns the instrumented bytecode.
65  inline bool HasInstrumentedBytecodeArray();
66 
67  inline BytecodeArray OriginalBytecodeArray();
68  inline BytecodeArray DebugBytecodeArray();
69 
70  // --- Break points ---
71  // --------------------
72 
73  bool HasBreakInfo() const;
74 
75  // Clears all fields related to break points.
76  void ClearBreakInfo(Isolate* isolate);
77 
78  // Accessors to flag whether to break before entering the function.
79  // This is used to break for functions with no source, e.g. builtins.
80  void SetBreakAtEntry();
81  void ClearBreakAtEntry();
82  bool BreakAtEntry() const;
83 
84  // The original uninstrumented bytecode array for functions with break
85  // points - the instrumented bytecode is held in the shared function info.
86  DECL_ACCESSORS(original_bytecode_array, Object)
87 
88  // The debug instrumented bytecode array for functions with break points
89  // - also pointed to by the shared function info.
90  DECL_ACCESSORS(debug_bytecode_array, Object)
91 
92  // Fixed array holding status information for each active break point.
93  DECL_ACCESSORS2(break_points, FixedArray)
94 
95  // Check if there is a break point at a source position.
96  bool HasBreakPoint(Isolate* isolate, int source_position);
97  // Attempt to clear a break point. Return true if successful.
98  static bool ClearBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
99  Handle<BreakPoint> break_point);
100  // Set a break point.
101  static void SetBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
102  int source_position,
103  Handle<BreakPoint> break_point);
104  // Get the break point objects for a source position.
105  Handle<Object> GetBreakPoints(Isolate* isolate, int source_position);
106  // Find the break point info holding this break point object.
107  static Handle<Object> FindBreakPointInfo(Isolate* isolate,
108  Handle<DebugInfo> debug_info,
109  Handle<BreakPoint> break_point);
110  // Get the number of break points for this function.
111  int GetBreakPointCount(Isolate* isolate);
112 
113  // Returns whether we should be able to break before entering the function.
114  // This is true for functions with no source, e.g. builtins.
115  bool CanBreakAtEntry() const;
116 
117  // --- Debugger hint flags ---
118  // ---------------------------
119 
120  // Indicates that the function should be skipped during stepping.
121  DECL_BOOLEAN_ACCESSORS(debug_is_blackboxed)
122 
123  // Indicates that |debug_is_blackboxed| has been computed and set.
124  DECL_BOOLEAN_ACCESSORS(computed_debug_is_blackboxed)
125 
126  // Indicates the side effect state.
127  DECL_INT_ACCESSORS(side_effect_state)
128 
129  enum SideEffectState {
130  kNotComputed = 0,
131  kHasSideEffects = 1,
132  kRequiresRuntimeChecks = 2,
133  kHasNoSideEffect = 3,
134  };
135 
136  SideEffectState GetSideEffectState(Isolate* isolate);
137 
138  // Id assigned to the function for debugging.
139  // This could also be implemented as a weak hash table.
140  DECL_INT_ACCESSORS(debugging_id);
141 
142 // Bit positions in |debugger_hints|.
143 #define DEBUGGER_HINTS_BIT_FIELDS(V, _) \
144  V(SideEffectStateBits, int, 2, _) \
145  V(DebugIsBlackboxedBit, bool, 1, _) \
146  V(ComputedDebugIsBlackboxedBit, bool, 1, _) \
147  V(DebuggingIdBits, int, 20, _)
148 
149  DEFINE_BIT_FIELDS(DEBUGGER_HINTS_BIT_FIELDS)
150 #undef DEBUGGER_HINTS_BIT_FIELDS
151 
152  static const int kNoDebuggingId = 0;
153 
154  // --- Block Coverage ---
155  // ----------------------
156 
157  bool HasCoverageInfo() const;
158 
159  // Clears all fields related to block coverage.
160  void ClearCoverageInfo(Isolate* isolate);
161  DECL_ACCESSORS(coverage_info, Object)
162 
163  DECL_CAST(DebugInfo)
164 
165  // Dispatched behavior.
166  DECL_PRINTER(DebugInfo)
167  DECL_VERIFIER(DebugInfo)
168 
169 // Layout description.
170 #define DEBUG_INFO_FIELDS(V) \
171  V(kSharedFunctionInfoOffset, kTaggedSize) \
172  V(kDebuggerHintsOffset, kTaggedSize) \
173  V(kScriptOffset, kTaggedSize) \
174  V(kOriginalBytecodeArrayOffset, kTaggedSize) \
175  V(kDebugBytecodeArrayOffset, kTaggedSize) \
176  V(kBreakPointsStateOffset, kTaggedSize) \
177  V(kFlagsOffset, kTaggedSize) \
178  V(kCoverageInfoOffset, kTaggedSize) \
179  /* Total size. */ \
180  V(kSize, 0)
181 
182  DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, DEBUG_INFO_FIELDS)
183 #undef DEBUG_INFO_FIELDS
184 
185  static const int kEstimatedNofBreakPointsInFunction = 4;
186 
187  private:
188  // Get the break point info object for a source position.
189  Object* GetBreakPointInfo(Isolate* isolate, int source_position);
190 
191  DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
192 };
193 
194 // The BreakPointInfo class holds information for break points set in a
195 // function. The DebugInfo object holds a BreakPointInfo object for each code
196 // position with one or more break points.
197 class BreakPointInfo : public Tuple2 {
198  public:
199  // The position in the source for the break position.
200  DECL_INT_ACCESSORS(source_position)
201  // List of related JavaScript break points.
202  DECL_ACCESSORS(break_points, Object)
203 
204  // Removes a break point.
205  static void ClearBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
206  Handle<BreakPoint> break_point);
207  // Set a break point.
208  static void SetBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
209  Handle<BreakPoint> break_point);
210  // Check if break point info has this break point.
211  static bool HasBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
212  Handle<BreakPoint> break_point);
213  // Get the number of break points for this code offset.
214  int GetBreakPointCount(Isolate* isolate);
215 
216  int GetStatementPosition(Handle<DebugInfo> debug_info);
217 
218  DECL_CAST(BreakPointInfo)
219 
220  static const int kSourcePositionOffset = kValue1Offset;
221  static const int kBreakPointsOffset = kValue2Offset;
222 
223  private:
224  DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
225 };
226 
227 // Holds information related to block code coverage.
228 class CoverageInfo : public FixedArray {
229  public:
230  int SlotCount() const;
231 
232  int StartSourcePosition(int slot_index) const;
233  int EndSourcePosition(int slot_index) const;
234  int BlockCount(int slot_index) const;
235 
236  void InitializeSlot(int slot_index, int start_pos, int end_pos);
237  void IncrementBlockCount(int slot_index);
238  void ResetBlockCount(int slot_index);
239 
240  static int FixedArrayLengthForSlotCount(int slot_count) {
241  return slot_count * kSlotIndexCount + kFirstSlotIndex;
242  }
243 
244  DECL_CAST2(CoverageInfo)
245 
246  // Print debug info.
247  void Print(std::unique_ptr<char[]> function_name);
248 
249  private:
250  static int FirstIndexForSlot(int slot_index) {
251  return kFirstSlotIndex + slot_index * kSlotIndexCount;
252  }
253 
254  static const int kFirstSlotIndex = 0;
255 
256  // Each slot is assigned a group of indices starting at kFirstSlotIndex.
257  // Within this group, semantics are as follows:
258  static const int kSlotStartSourcePositionIndex = 0;
259  static const int kSlotEndSourcePositionIndex = 1;
260  static const int kSlotBlockCountIndex = 2;
261  static const int kSlotIndexCount = 3;
262 
263  OBJECT_CONSTRUCTORS(CoverageInfo, FixedArray);
264 };
265 
266 // Holds breakpoint related information. This object is used by inspector.
267 class BreakPoint : public Tuple2 {
268  public:
269  DECL_INT_ACCESSORS(id)
270  DECL_ACCESSORS2(condition, String)
271 
272  DECL_CAST(BreakPoint)
273 
274  static const int kIdOffset = kValue1Offset;
275  static const int kConditionOffset = kValue2Offset;
276 
277  private:
278  DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPoint);
279 };
280 
281 } // namespace internal
282 } // namespace v8
283 
284 #include "src/objects/object-macros-undef.h"
285 
286 #endif // V8_OBJECTS_DEBUG_OBJECTS_H_
Definition: libplatform.h:13