v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
debug-objects.h
Go to the documentation of this file.
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"
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):
18
19namespace v8 {
20namespace internal {
21
22class BreakPoint;
23class BytecodeArray;
24class StructBodyDescriptor;
25
26#include "torque-generated/src/objects/debug-objects-tq.inc"
27
28// The DebugInfo class holds additional information for a function being
29// debugged.
30class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
31 public:
33 DEFINE_TORQUE_GENERATED_DEBUG_INFO_FLAGS()
34
35 // DebugInfo can be detached from the SharedFunctionInfo iff it is empty.
36 bool IsEmpty() const;
37
38 // --- Debug execution ---
39 // -----------------------
40
41 enum ExecutionMode : uint8_t {
43 kSideEffects = kDebugExecutionMode
44 };
45
46 // Returns current debug execution mode. Debug execution mode defines by
47 // applied to bytecode patching. False for breakpoints, true for side effect
48 // checks.
51
52 // Specifies whether the associated function has an instrumented bytecode
53 // array. If so, OriginalBytecodeArray returns the non-instrumented bytecode,
54 // and DebugBytecodeArray returns the instrumented bytecode.
55 inline bool HasInstrumentedBytecodeArray();
56
59
62
63 // --- Break points ---
64 // --------------------
65
66 bool HasBreakInfo() const;
67
68 // Clears all fields related to break points.
70
71 // Accessors to flag whether to break before entering the function.
72 // This is used to break for functions with no source, e.g. builtins.
73 void SetBreakAtEntry();
74 void ClearBreakAtEntry();
75 bool BreakAtEntry() const;
76
77 // Check if there is a break point at a source position.
78 bool HasBreakPoint(Isolate* isolate, int source_position);
79 // Attempt to clear a break point. Return true if successful.
80 static bool ClearBreakPoint(Isolate* isolate,
81 DirectHandle<DebugInfo> debug_info,
82 DirectHandle<BreakPoint> break_point);
83 // Set a break point.
84 static void SetBreakPoint(Isolate* isolate,
85 DirectHandle<DebugInfo> debug_info,
86 int source_position,
87 DirectHandle<BreakPoint> break_point);
88 // Get the break point objects for a source position.
89 DirectHandle<Object> GetBreakPoints(Isolate* isolate, int source_position);
90 // Find the break point info holding this break point object.
92 Isolate* isolate, DirectHandle<DebugInfo> debug_info,
93 DirectHandle<BreakPoint> break_point);
94 // Get the number of break points for this function.
95 int GetBreakPointCount(Isolate* isolate);
96
97 // Returns whether we should be able to break before entering the function.
98 // This is true for functions with no source, e.g. builtins.
99 bool CanBreakAtEntry() const;
100
101 // --- Debugger hint flags ---
102 // ---------------------------
103
104 // Indicates that the function should be skipped during stepping.
106
107 // Indicates that |debug_is_blackboxed| has been computed and set.
108 DECL_BOOLEAN_ACCESSORS(computed_debug_is_blackboxed)
109
110 // Indicates the side effect state.
111 DECL_INT_ACCESSORS(side_effect_state)
112
119
121
122 // Id assigned to the function for debugging.
123 // This could also be implemented as a weak hash table.
125
126 // Bit positions in |debugger_hints|.
127 DEFINE_TORQUE_GENERATED_DEBUGGER_HINTS()
128
129 static const int kNoDebuggingId = 0;
130
131 // --- Block Coverage ---
132 // ----------------------
133
134 bool HasCoverageInfo() const;
135
136 // Clears all fields related to block coverage.
137 void ClearCoverageInfo(Isolate* isolate);
138
140
141 class BodyDescriptor;
142
143 private:
144 // Get the break point info object for a source position.
145 Tagged<Object> GetBreakPointInfo(Isolate* isolate, int source_position);
146
148};
149
150// The BreakPointInfo class holds information for break points set in a
151// function. The DebugInfo object holds a BreakPointInfo object for each code
152// position with one or more break points.
154 : public TorqueGeneratedBreakPointInfo<BreakPointInfo, Struct> {
155 public:
156 // Removes a break point.
157 static void ClearBreakPoint(Isolate* isolate,
159 DirectHandle<BreakPoint> break_point);
160 // Set a break point.
161 static void SetBreakPoint(Isolate* isolate, DirectHandle<BreakPointInfo> info,
162 DirectHandle<BreakPoint> break_point);
163 // Check if break point info has this break point.
164 static bool HasBreakPoint(Isolate* isolate, DirectHandle<BreakPointInfo> info,
165 DirectHandle<BreakPoint> break_point);
166 // Check if break point info has break point with this id.
167 static MaybeDirectHandle<BreakPoint> GetBreakPointById(
168 Isolate* isolate, DirectHandle<BreakPointInfo> info, int breakpoint_id);
169 // Get the number of break points for this code offset.
170 int GetBreakPointCount(Isolate* isolate);
171
173
175
177};
178
179// Holds information related to block code coverage.
181 : public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> {
182 public:
183 void InitializeSlot(int slot_index, int start_pos, int end_pos);
184 void ResetBlockCount(int slot_index);
185
186 // Computes the size for a CoverageInfo instance of a given length.
187 static int SizeFor(int slot_count) {
188 return OBJECT_POINTER_ALIGN(kHeaderSize + slot_count * Slot::kSize);
189 }
190
191 // Print debug info.
192 void CoverageInfoPrint(std::ostream& os,
193 std::unique_ptr<char[]> function_name = nullptr);
194
195 class BodyDescriptor; // GC visitor.
196
197 // Description of layout within each slot.
198 using Slot = TorqueGeneratedCoverageInfoSlotOffsets;
199
201};
202
203// Holds breakpoint related information. This object is used by inspector.
204class BreakPoint : public TorqueGeneratedBreakPoint<BreakPoint, Struct> {
205 public:
207
209};
210
212 : public TorqueGeneratedStackFrameInfo<StackFrameInfo, Struct> {
213 public:
215
216 static int GetSourcePosition(DirectHandle<StackFrameInfo> info);
217
218 // The script for the stack frame.
219 inline Tagged<Script> script() const;
220
221 // The bytecode offset or source position for the stack frame.
222 DECL_INT_ACCESSORS(bytecode_offset_or_source_position)
223
224 // Indicates that the frame corresponds to a 'new' invocation.
226
227 // Dispatched behavior.
229
230 // Bit positions in |flags|.
231 DEFINE_TORQUE_GENERATED_STACK_FRAME_INFO_FLAGS()
232
234
235 private:
237};
238
240 : public TorqueGeneratedStackTraceInfo<StackTraceInfo, Struct> {
241 public:
243
244 // Access to the stack frames.
245 int length() const;
246 Tagged<StackFrameInfo> get(int index) const;
247
248 // Dispatched behavior.
250
252
253 private:
255};
256
258 : public TorqueGeneratedErrorStackData<ErrorStackData, Struct> {
259 public:
261
262 inline bool HasFormattedStack() const;
263 DECL_ACCESSORS(formatted_stack, Tagged<Object>)
264 inline bool HasCallSiteInfos() const;
265 DECL_GETTER(call_site_infos, Tagged<FixedArray>)
266
268
270
272};
273
274} // namespace internal
275} // namespace v8
276
277#include "src/objects/object-macros-undef.h"
278
279#endif // V8_OBJECTS_DEBUG_OBJECTS_H_
int GetStatementPosition(Handle< DebugInfo > debug_info)
TorqueGeneratedCoverageInfoSlotOffsets Slot
static int SizeFor(int slot_count)
static const int kEstimatedNofBreakPointsInFunction
bool HasBreakPoint(Isolate *isolate, int source_position)
V8_EXPORT_PRIVATE void ClearBreakInfo(Isolate *isolate)
static bool ClearBreakPoint(Isolate *isolate, DirectHandle< DebugInfo > debug_info, DirectHandle< BreakPoint > break_point)
static DirectHandle< Object > FindBreakPointInfo(Isolate *isolate, DirectHandle< DebugInfo > debug_info, DirectHandle< BreakPoint > break_point)
void SetDebugExecutionMode(ExecutionMode value)
DirectHandle< Object > GetBreakPoints(Isolate *isolate, int source_position)
void ClearCoverageInfo(Isolate *isolate)
Tagged< Object > GetBreakPointInfo(Isolate *isolate, int source_position)
NEVER_READ_ONLY_SPACE bool IsEmpty() const
SideEffectState GetSideEffectState(Isolate *isolate)
Tagged< BytecodeArray > OriginalBytecodeArray(Isolate *isolate)
ExecutionMode DebugExecutionMode() const
static const int kNoDebuggingId
static void SetBreakPoint(Isolate *isolate, DirectHandle< DebugInfo > debug_info, int source_position, DirectHandle< BreakPoint > break_point)
Tagged< BytecodeArray > DebugBytecodeArray(Isolate *isolate)
int GetBreakPointCount(Isolate *isolate)
#define OBJECT_POINTER_ALIGN(value)
Definition globals.h:1783
DebugInfo::DebugIsBlackboxedBit debugging_id
#define DECL_ACCESSORS(name,...)
#define DECL_GETTER(name,...)
#define DECL_TRUSTED_POINTER_ACCESSORS(name, type)
#define DECL_VERIFIER(Name)
#define DECL_BOOLEAN_ACCESSORS(name)
#define NEVER_READ_ONLY_SPACE
#define DECL_INT_ACCESSORS(name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define V8_EXPORT_PRIVATE
Definition macros.h:460