11cb0ef41Sopenharmony_ci// Copyright 2017 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_DEBUG_OBJECTS_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_DEBUG_OBJECTS_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <memory>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/base/bit-field.h"
111cb0ef41Sopenharmony_ci#include "src/objects/fixed-array.h"
121cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
131cb0ef41Sopenharmony_ci#include "src/objects/struct.h"
141cb0ef41Sopenharmony_ci#include "torque-generated/bit-fields.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
171cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cinamespace v8 {
201cb0ef41Sopenharmony_cinamespace internal {
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciclass BreakPoint;
231cb0ef41Sopenharmony_ciclass BytecodeArray;
241cb0ef41Sopenharmony_ciclass StructBodyDescriptor;
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/debug-objects-tq.inc"
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci// The DebugInfo class holds additional information for a function being
291cb0ef41Sopenharmony_ci// debugged.
301cb0ef41Sopenharmony_ciclass DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
311cb0ef41Sopenharmony_ci public:
321cb0ef41Sopenharmony_ci  NEVER_READ_ONLY_SPACE
331cb0ef41Sopenharmony_ci  DEFINE_TORQUE_GENERATED_DEBUG_INFO_FLAGS()
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  // DebugInfo can be detached from the SharedFunctionInfo iff it is empty.
361cb0ef41Sopenharmony_ci  bool IsEmpty() const;
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  // --- Debug execution ---
391cb0ef41Sopenharmony_ci  // -----------------------
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  enum ExecutionMode : uint8_t {
421cb0ef41Sopenharmony_ci    kBreakpoints = 0,
431cb0ef41Sopenharmony_ci    kSideEffects = kDebugExecutionMode
441cb0ef41Sopenharmony_ci  };
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  // Returns current debug execution mode. Debug execution mode defines by
471cb0ef41Sopenharmony_ci  // applied to bytecode patching. False for breakpoints, true for side effect
481cb0ef41Sopenharmony_ci  // checks.
491cb0ef41Sopenharmony_ci  ExecutionMode DebugExecutionMode() const;
501cb0ef41Sopenharmony_ci  void SetDebugExecutionMode(ExecutionMode value);
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  // Specifies whether the associated function has an instrumented bytecode
531cb0ef41Sopenharmony_ci  // array. If so, OriginalBytecodeArray returns the non-instrumented bytecode,
541cb0ef41Sopenharmony_ci  // and DebugBytecodeArray returns the instrumented bytecode.
551cb0ef41Sopenharmony_ci  inline bool HasInstrumentedBytecodeArray();
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  inline BytecodeArray OriginalBytecodeArray();
581cb0ef41Sopenharmony_ci  inline BytecodeArray DebugBytecodeArray();
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci  // --- Break points ---
611cb0ef41Sopenharmony_ci  // --------------------
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  bool HasBreakInfo() const;
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  // Clears all fields related to break points.
661cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE void ClearBreakInfo(Isolate* isolate);
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci  // Accessors to flag whether to break before entering the function.
691cb0ef41Sopenharmony_ci  // This is used to break for functions with no source, e.g. builtins.
701cb0ef41Sopenharmony_ci  void SetBreakAtEntry();
711cb0ef41Sopenharmony_ci  void ClearBreakAtEntry();
721cb0ef41Sopenharmony_ci  bool BreakAtEntry() const;
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  // Check if there is a break point at a source position.
751cb0ef41Sopenharmony_ci  bool HasBreakPoint(Isolate* isolate, int source_position);
761cb0ef41Sopenharmony_ci  // Attempt to clear a break point. Return true if successful.
771cb0ef41Sopenharmony_ci  static bool ClearBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
781cb0ef41Sopenharmony_ci                              Handle<BreakPoint> break_point);
791cb0ef41Sopenharmony_ci  // Set a break point.
801cb0ef41Sopenharmony_ci  static void SetBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info,
811cb0ef41Sopenharmony_ci                            int source_position,
821cb0ef41Sopenharmony_ci                            Handle<BreakPoint> break_point);
831cb0ef41Sopenharmony_ci  // Get the break point objects for a source position.
841cb0ef41Sopenharmony_ci  Handle<Object> GetBreakPoints(Isolate* isolate, int source_position);
851cb0ef41Sopenharmony_ci  // Find the break point info holding this break point object.
861cb0ef41Sopenharmony_ci  static Handle<Object> FindBreakPointInfo(Isolate* isolate,
871cb0ef41Sopenharmony_ci                                           Handle<DebugInfo> debug_info,
881cb0ef41Sopenharmony_ci                                           Handle<BreakPoint> break_point);
891cb0ef41Sopenharmony_ci  // Get the number of break points for this function.
901cb0ef41Sopenharmony_ci  int GetBreakPointCount(Isolate* isolate);
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  // Returns whether we should be able to break before entering the function.
931cb0ef41Sopenharmony_ci  // This is true for functions with no source, e.g. builtins.
941cb0ef41Sopenharmony_ci  bool CanBreakAtEntry() const;
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci  // --- Debugger hint flags ---
971cb0ef41Sopenharmony_ci  // ---------------------------
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci  // Indicates that the function should be skipped during stepping.
1001cb0ef41Sopenharmony_ci  DECL_BOOLEAN_ACCESSORS(debug_is_blackboxed)
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci  // Indicates that |debug_is_blackboxed| has been computed and set.
1031cb0ef41Sopenharmony_ci  DECL_BOOLEAN_ACCESSORS(computed_debug_is_blackboxed)
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci  // Indicates the side effect state.
1061cb0ef41Sopenharmony_ci  DECL_INT_ACCESSORS(side_effect_state)
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci  enum SideEffectState {
1091cb0ef41Sopenharmony_ci    kNotComputed = 0,
1101cb0ef41Sopenharmony_ci    kHasSideEffects = 1,
1111cb0ef41Sopenharmony_ci    kRequiresRuntimeChecks = 2,
1121cb0ef41Sopenharmony_ci    kHasNoSideEffect = 3,
1131cb0ef41Sopenharmony_ci  };
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci  SideEffectState GetSideEffectState(Isolate* isolate);
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci  // Id assigned to the function for debugging.
1181cb0ef41Sopenharmony_ci  // This could also be implemented as a weak hash table.
1191cb0ef41Sopenharmony_ci  DECL_INT_ACCESSORS(debugging_id)
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci  // Bit positions in |debugger_hints|.
1221cb0ef41Sopenharmony_ci  DEFINE_TORQUE_GENERATED_DEBUGGER_HINTS()
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci  static const int kNoDebuggingId = 0;
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci  // --- Block Coverage ---
1271cb0ef41Sopenharmony_ci  // ----------------------
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci  bool HasCoverageInfo() const;
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci  // Clears all fields related to block coverage.
1321cb0ef41Sopenharmony_ci  void ClearCoverageInfo(Isolate* isolate);
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci  static const int kEstimatedNofBreakPointsInFunction = 4;
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci  using BodyDescriptor = StructBodyDescriptor;
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci private:
1391cb0ef41Sopenharmony_ci  // Get the break point info object for a source position.
1401cb0ef41Sopenharmony_ci  Object GetBreakPointInfo(Isolate* isolate, int source_position);
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(DebugInfo)
1431cb0ef41Sopenharmony_ci};
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci// The BreakPointInfo class holds information for break points set in a
1461cb0ef41Sopenharmony_ci// function. The DebugInfo object holds a BreakPointInfo object for each code
1471cb0ef41Sopenharmony_ci// position with one or more break points.
1481cb0ef41Sopenharmony_ciclass BreakPointInfo
1491cb0ef41Sopenharmony_ci    : public TorqueGeneratedBreakPointInfo<BreakPointInfo, Struct> {
1501cb0ef41Sopenharmony_ci public:
1511cb0ef41Sopenharmony_ci  // Removes a break point.
1521cb0ef41Sopenharmony_ci  static void ClearBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
1531cb0ef41Sopenharmony_ci                              Handle<BreakPoint> break_point);
1541cb0ef41Sopenharmony_ci  // Set a break point.
1551cb0ef41Sopenharmony_ci  static void SetBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
1561cb0ef41Sopenharmony_ci                            Handle<BreakPoint> break_point);
1571cb0ef41Sopenharmony_ci  // Check if break point info has this break point.
1581cb0ef41Sopenharmony_ci  static bool HasBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
1591cb0ef41Sopenharmony_ci                            Handle<BreakPoint> break_point);
1601cb0ef41Sopenharmony_ci  // Check if break point info has break point with this id.
1611cb0ef41Sopenharmony_ci  static MaybeHandle<BreakPoint> GetBreakPointById(Isolate* isolate,
1621cb0ef41Sopenharmony_ci                                                   Handle<BreakPointInfo> info,
1631cb0ef41Sopenharmony_ci                                                   int breakpoint_id);
1641cb0ef41Sopenharmony_ci  // Get the number of break points for this code offset.
1651cb0ef41Sopenharmony_ci  int GetBreakPointCount(Isolate* isolate);
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  int GetStatementPosition(Handle<DebugInfo> debug_info);
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  using BodyDescriptor = StructBodyDescriptor;
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(BreakPointInfo)
1721cb0ef41Sopenharmony_ci};
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci// Holds information related to block code coverage.
1751cb0ef41Sopenharmony_ciclass CoverageInfo
1761cb0ef41Sopenharmony_ci    : public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> {
1771cb0ef41Sopenharmony_ci public:
1781cb0ef41Sopenharmony_ci  void InitializeSlot(int slot_index, int start_pos, int end_pos);
1791cb0ef41Sopenharmony_ci  void ResetBlockCount(int slot_index);
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci  // Computes the size for a CoverageInfo instance of a given length.
1821cb0ef41Sopenharmony_ci  static int SizeFor(int slot_count) {
1831cb0ef41Sopenharmony_ci    return OBJECT_POINTER_ALIGN(kHeaderSize + slot_count * Slot::kSize);
1841cb0ef41Sopenharmony_ci  }
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci  // Print debug info.
1871cb0ef41Sopenharmony_ci  void CoverageInfoPrint(std::ostream& os,
1881cb0ef41Sopenharmony_ci                         std::unique_ptr<char[]> function_name = nullptr);
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci  class BodyDescriptor;  // GC visitor.
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci  // Description of layout within each slot.
1931cb0ef41Sopenharmony_ci  using Slot = TorqueGeneratedCoverageInfoSlotOffsets;
1941cb0ef41Sopenharmony_ci
1951cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(CoverageInfo)
1961cb0ef41Sopenharmony_ci};
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci// Holds breakpoint related information. This object is used by inspector.
1991cb0ef41Sopenharmony_ciclass BreakPoint : public TorqueGeneratedBreakPoint<BreakPoint, Struct> {
2001cb0ef41Sopenharmony_ci public:
2011cb0ef41Sopenharmony_ci  using BodyDescriptor = StructBodyDescriptor;
2021cb0ef41Sopenharmony_ci
2031cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(BreakPoint)
2041cb0ef41Sopenharmony_ci};
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ciclass StackFrameInfo
2071cb0ef41Sopenharmony_ci    : public TorqueGeneratedStackFrameInfo<StackFrameInfo, Struct> {
2081cb0ef41Sopenharmony_ci public:
2091cb0ef41Sopenharmony_ci  NEVER_READ_ONLY_SPACE
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci  static int GetSourcePosition(Handle<StackFrameInfo> info);
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci  // The script for the stack frame.
2141cb0ef41Sopenharmony_ci  inline Script script() const;
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci  // The bytecode offset or source position for the stack frame.
2171cb0ef41Sopenharmony_ci  DECL_INT_ACCESSORS(bytecode_offset_or_source_position)
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci  // Indicates that the frame corresponds to a 'new' invocation.
2201cb0ef41Sopenharmony_ci  DECL_BOOLEAN_ACCESSORS(is_constructor)
2211cb0ef41Sopenharmony_ci
2221cb0ef41Sopenharmony_ci  // Dispatched behavior.
2231cb0ef41Sopenharmony_ci  DECL_VERIFIER(StackFrameInfo)
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci  // Bit positions in |flags|.
2261cb0ef41Sopenharmony_ci  DEFINE_TORQUE_GENERATED_STACK_FRAME_INFO_FLAGS()
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ci  using BodyDescriptor = StructBodyDescriptor;
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ci private:
2311cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(StackFrameInfo)
2321cb0ef41Sopenharmony_ci};
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ciclass ErrorStackData
2351cb0ef41Sopenharmony_ci    : public TorqueGeneratedErrorStackData<ErrorStackData, Struct> {
2361cb0ef41Sopenharmony_ci public:
2371cb0ef41Sopenharmony_ci  NEVER_READ_ONLY_SPACE
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci  inline bool HasFormattedStack() const;
2401cb0ef41Sopenharmony_ci  DECL_ACCESSORS(formatted_stack, Object)
2411cb0ef41Sopenharmony_ci  inline bool HasCallSiteInfos() const;
2421cb0ef41Sopenharmony_ci  DECL_ACCESSORS(call_site_infos, FixedArray)
2431cb0ef41Sopenharmony_ci
2441cb0ef41Sopenharmony_ci  static void EnsureStackFrameInfos(Isolate* isolate,
2451cb0ef41Sopenharmony_ci                                    Handle<ErrorStackData> error_stack);
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci  DECL_VERIFIER(ErrorStackData)
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci  using BodyDescriptor = StructBodyDescriptor;
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(ErrorStackData)
2521cb0ef41Sopenharmony_ci};
2531cb0ef41Sopenharmony_ci
2541cb0ef41Sopenharmony_ciclass PromiseOnStack
2551cb0ef41Sopenharmony_ci    : public TorqueGeneratedPromiseOnStack<PromiseOnStack, Struct> {
2561cb0ef41Sopenharmony_ci public:
2571cb0ef41Sopenharmony_ci  NEVER_READ_ONLY_SPACE
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  static MaybeHandle<JSObject> GetPromise(
2601cb0ef41Sopenharmony_ci      Handle<PromiseOnStack> promise_on_stack);
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci  class BodyDescriptor;
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(PromiseOnStack)
2651cb0ef41Sopenharmony_ci};
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci}  // namespace internal
2681cb0ef41Sopenharmony_ci}  // namespace v8
2691cb0ef41Sopenharmony_ci
2701cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_DEBUG_OBJECTS_H_
273