• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
9 
10 #include "src/base/bit-field.h"
11 #include "src/objects/fixed-array.h"
12 #include "src/objects/objects.h"
13 #include "src/objects/struct.h"
14 #include "torque-generated/bit-fields.h"
15 
16 // Has to be the last include (doesn't have include guards):
17 #include "src/objects/object-macros.h"
18 
19 namespace v8 {
20 namespace internal {
21 
22 class BreakPoint;
23 class BytecodeArray;
24 
25 #include "torque-generated/src/objects/debug-objects-tq.inc"
26 
27 // The DebugInfo class holds additional information for a function being
28 // debugged.
29 class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
30  public:
31   NEVER_READ_ONLY_SPACE
32   DEFINE_TORQUE_GENERATED_DEBUG_INFO_FLAGS()
33 
34   // DebugInfo can be detached from the SharedFunctionInfo iff it is empty.
35   bool IsEmpty() const;
36 
37   // --- Debug execution ---
38   // -----------------------
39 
40   enum ExecutionMode { kBreakpoints = 0, kSideEffects = kDebugExecutionMode };
41 
42   // Returns current debug execution mode. Debug execution mode defines by
43   // applied to bytecode patching. False for breakpoints, true for side effect
44   // checks.
45   ExecutionMode DebugExecutionMode() const;
46   void SetDebugExecutionMode(ExecutionMode value);
47 
48   // Specifies whether the associated function has an instrumented bytecode
49   // array. If so, OriginalBytecodeArray returns the non-instrumented bytecode,
50   // and DebugBytecodeArray returns the instrumented bytecode.
51   inline bool HasInstrumentedBytecodeArray();
52 
53   inline BytecodeArray OriginalBytecodeArray();
54   inline BytecodeArray DebugBytecodeArray();
55 
56   // --- Break points ---
57   // --------------------
58 
59   bool HasBreakInfo() const;
60 
61   // Clears all fields related to break points.
62   void ClearBreakInfo(Isolate* isolate);
63 
64   // Accessors to flag whether to break before entering the function.
65   // This is used to break for functions with no source, e.g. builtins.
66   void SetBreakAtEntry();
67   void ClearBreakAtEntry();
68   bool BreakAtEntry() const;
69 
70   // Check if there is a break point at a source position.
71   bool HasBreakPoint(Isolate* isolate, int source_position);
72   // Attempt to clear a break point. Return true if successful.
73   static bool ClearBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
74                               Handle<BreakPoint> break_point);
75   // Set a break point.
76   static void SetBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
77                             int source_position,
78                             Handle<BreakPoint> break_point);
79   // Get the break point objects for a source position.
80   Handle<Object> GetBreakPoints(Isolate* isolate, int source_position);
81   // Find the break point info holding this break point object.
82   static Handle<Object> FindBreakPointInfo(Isolate* isolate,
83                                            Handle<DebugInfo> debug_info,
84                                            Handle<BreakPoint> break_point);
85   // Get the number of break points for this function.
86   int GetBreakPointCount(Isolate* isolate);
87 
88   // Returns whether we should be able to break before entering the function.
89   // This is true for functions with no source, e.g. builtins.
90   bool CanBreakAtEntry() const;
91 
92   // --- Debugger hint flags ---
93   // ---------------------------
94 
95   // Indicates that the function should be skipped during stepping.
96   DECL_BOOLEAN_ACCESSORS(debug_is_blackboxed)
97 
98   // Indicates that |debug_is_blackboxed| has been computed and set.
99   DECL_BOOLEAN_ACCESSORS(computed_debug_is_blackboxed)
100 
101   // Indicates the side effect state.
102   DECL_INT_ACCESSORS(side_effect_state)
103 
104   enum SideEffectState {
105     kNotComputed = 0,
106     kHasSideEffects = 1,
107     kRequiresRuntimeChecks = 2,
108     kHasNoSideEffect = 3,
109   };
110 
111   SideEffectState GetSideEffectState(Isolate* isolate);
112 
113   // Id assigned to the function for debugging.
114   // This could also be implemented as a weak hash table.
115   DECL_INT_ACCESSORS(debugging_id)
116 
117   // Bit positions in |debugger_hints|.
118   DEFINE_TORQUE_GENERATED_DEBUGGER_HINTS()
119 
120   static const int kNoDebuggingId = 0;
121 
122   // --- Block Coverage ---
123   // ----------------------
124 
125   bool HasCoverageInfo() const;
126 
127   // Clears all fields related to block coverage.
128   void ClearCoverageInfo(Isolate* isolate);
129 
130   static const int kEstimatedNofBreakPointsInFunction = 4;
131 
132  private:
133   // Get the break point info object for a source position.
134   Object GetBreakPointInfo(Isolate* isolate, int source_position);
135 
136   TQ_OBJECT_CONSTRUCTORS(DebugInfo)
137 };
138 
139 // The BreakPointInfo class holds information for break points set in a
140 // function. The DebugInfo object holds a BreakPointInfo object for each code
141 // position with one or more break points.
142 class BreakPointInfo
143     : public TorqueGeneratedBreakPointInfo<BreakPointInfo, Struct> {
144  public:
145   // Removes a break point.
146   static void ClearBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
147                               Handle<BreakPoint> break_point);
148   // Set a break point.
149   static void SetBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
150                             Handle<BreakPoint> break_point);
151   // Check if break point info has this break point.
152   static bool HasBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
153                             Handle<BreakPoint> break_point);
154   // Check if break point info has break point with this id.
155   static MaybeHandle<BreakPoint> GetBreakPointById(Isolate* isolate,
156                                                    Handle<BreakPointInfo> info,
157                                                    int breakpoint_id);
158   // Get the number of break points for this code offset.
159   int GetBreakPointCount(Isolate* isolate);
160 
161   int GetStatementPosition(Handle<DebugInfo> debug_info);
162 
163   TQ_OBJECT_CONSTRUCTORS(BreakPointInfo)
164 };
165 
166 // Holds information related to block code coverage.
167 class CoverageInfo
168     : public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> {
169  public:
170   int StartSourcePosition(int slot_index) const;
171   int EndSourcePosition(int slot_index) const;
172   int BlockCount(int slot_index) const;
173 
174   void InitializeSlot(int slot_index, int start_pos, int end_pos);
175   void ResetBlockCount(int slot_index);
176 
177   // Computes the size for a CoverageInfo instance of a given length.
SizeFor(int slot_count)178   static int SizeFor(int slot_count) {
179     return OBJECT_POINTER_ALIGN(kHeaderSize + slot_count * Slot::kSize);
180   }
181 
182   // Print debug info.
183   void CoverageInfoPrint(std::ostream& os,
184                          std::unique_ptr<char[]> function_name = nullptr);
185 
186   class BodyDescriptor;  // GC visitor.
187 
188   // Description of layout within each slot.
189   using Slot = TorqueGeneratedCoverageInfoSlotOffsets;
190 
191  private:
192   int SlotFieldOffset(int slot_index, int field_offset) const;
193 
194   TQ_OBJECT_CONSTRUCTORS(CoverageInfo)
195 };
196 
197 // Holds breakpoint related information. This object is used by inspector.
198 class BreakPoint : public TorqueGeneratedBreakPoint<BreakPoint, Struct> {
199  public:
200   TQ_OBJECT_CONSTRUCTORS(BreakPoint)
201 };
202 
203 // Holds Wasm values. This is used by the inspector.
204 class WasmValue : public TorqueGeneratedWasmValue<WasmValue, Struct> {
205  public:
206   NEVER_READ_ONLY_SPACE
207 
208   TQ_OBJECT_CONSTRUCTORS(WasmValue)
209 };
210 
211 }  // namespace internal
212 }  // namespace v8
213 
214 #include "src/objects/object-macros-undef.h"
215 
216 #endif  // V8_OBJECTS_DEBUG_OBJECTS_H_
217