debug.h 24.8 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_DEBUG_DEBUG_H_
#define V8_DEBUG_DEBUG_H_
7

8
#include <memory>
9 10
#include <vector>

11
#include "src/base/enum-set.h"
12
#include "src/codegen/source-position-table.h"
13
#include "src/common/globals.h"
14
#include "src/debug/debug-interface.h"
15
#include "src/debug/interface-types.h"
16
#include "src/execution/interrupts-scope.h"
17
#include "src/execution/isolate.h"
18
#include "src/handles/handles.h"
19
#include "src/objects/debug-objects.h"
20
#include "src/objects/shared-function-info.h"
21

22 23
namespace v8 {
namespace internal {
24

25
// Forward declarations.
Marja Hölttä's avatar
Marja Hölttä committed
26
class AbstractCode;
27
class DebugScope;
28 29
class InterpretedFrame;
class JavaScriptFrame;
30
class JSGeneratorObject;
31
class StackFrame;
32

33
// Step actions.
34
enum StepAction : int8_t {
35
  StepNone = -1,  // Stepping not prepared.
36
  StepOut = 0,    // Step out of the current function.
37 38
  StepOver = 1,   // Step to the next statement in the current function.
  StepInto = 2,   // Step into new functions invoked or the next statement
39
                  // in the current function.
40
  LastStepAction = StepInto
41
};
42 43

// Type of exception break. NOTE: These values are in macros.py as well.
44
enum ExceptionBreakType { BreakException = 0, BreakUncaughtException = 1 };
45

46 47
// Type of debug break. NOTE: The order matters for the predicates
// below inside BreakLocation, so be careful when adding / removing.
48 49 50
enum DebugBreakType {
  NOT_DEBUG_BREAK,
  DEBUGGER_STATEMENT,
51
  DEBUG_BREAK_AT_ENTRY,
52 53 54
  DEBUG_BREAK_SLOT,
  DEBUG_BREAK_SLOT_AT_CALL,
  DEBUG_BREAK_SLOT_AT_RETURN,
55
  DEBUG_BREAK_SLOT_AT_SUSPEND,
56
};
57

58 59 60 61 62
enum IgnoreBreakMode {
  kIgnoreIfAllFramesBlackboxed,
  kIgnoreIfTopFrameBlackboxed
};

63
class BreakLocation {
64
 public:
65
  static BreakLocation Invalid() { return BreakLocation(-1, NOT_DEBUG_BREAK); }
66 67
  static BreakLocation FromFrame(Handle<DebugInfo> debug_info,
                                 JavaScriptFrame* frame);
68

69 70
  static void AllAtCurrentStatement(Handle<DebugInfo> debug_info,
                                    JavaScriptFrame* frame,
71
                                    std::vector<BreakLocation>* result_out);
72

73 74 75 76 77 78 79
  bool IsSuspend() const { return type_ == DEBUG_BREAK_SLOT_AT_SUSPEND; }
  bool IsReturn() const { return type_ == DEBUG_BREAK_SLOT_AT_RETURN; }
  bool IsReturnOrSuspend() const { return type_ >= DEBUG_BREAK_SLOT_AT_RETURN; }
  bool IsCall() const { return type_ == DEBUG_BREAK_SLOT_AT_CALL; }
  bool IsDebugBreakSlot() const { return type_ >= DEBUG_BREAK_SLOT; }
  bool IsDebuggerStatement() const { return type_ == DEBUGGER_STATEMENT; }
  bool IsDebugBreakAtEntry() const { return type_ == DEBUG_BREAK_AT_ENTRY; }
80

81
  bool HasBreakPoint(Isolate* isolate, Handle<DebugInfo> debug_info) const;
82

83 84
  int generator_suspend_id() { return generator_suspend_id_; }
  int position() const { return position_; }
85

86 87
  debug::BreakLocationType type() const;

88
  JSGeneratorObject GetGeneratorObjectForSuspendedFrame(
89 90
      JavaScriptFrame* frame) const;

91 92
 private:
  BreakLocation(Handle<AbstractCode> abstract_code, DebugBreakType type,
93 94
                int code_offset, int position, int generator_obj_reg_index,
                int generator_suspend_id)
95 96 97
      : abstract_code_(abstract_code),
        code_offset_(code_offset),
        type_(type),
98
        position_(position),
99 100
        generator_obj_reg_index_(generator_obj_reg_index),
        generator_suspend_id_(generator_suspend_id) {
101 102
    DCHECK_NE(NOT_DEBUG_BREAK, type_);
  }
103

104 105 106 107
  BreakLocation(int position, DebugBreakType type)
      : code_offset_(0),
        type_(type),
        position_(position),
108 109
        generator_obj_reg_index_(0),
        generator_suspend_id_(-1) {}
110

111 112 113
  static int BreakIndexFromCodeOffset(Handle<DebugInfo> debug_info,
                                      Handle<AbstractCode> abstract_code,
                                      int offset);
114

115 116 117 118 119 120 121
  void SetDebugBreak();
  void ClearDebugBreak();

  Handle<AbstractCode> abstract_code_;
  int code_offset_;
  DebugBreakType type_;
  int position_;
122
  int generator_obj_reg_index_;
123
  int generator_suspend_id_;
124

125
  friend class BreakIterator;
126
};
127

128
class V8_EXPORT_PRIVATE BreakIterator {
129
 public:
130
  explicit BreakIterator(Handle<DebugInfo> debug_info);
131 132
  BreakIterator(const BreakIterator&) = delete;
  BreakIterator& operator=(const BreakIterator&) = delete;
133

134 135 136
  BreakLocation GetBreakLocation();
  bool Done() const { return source_position_iterator_.done(); }
  void Next();
137

138
  void SkipToPosition(int position);
139 140
  void SkipTo(int count) {
    while (count-- > 0) Next();
141
  }
142

143
  int code_offset() { return source_position_iterator_.code_offset(); }
144 145 146
  int break_index() const { return break_index_; }
  inline int position() const { return position_; }
  inline int statement_position() const { return statement_position_; }
147

148 149
  void ClearDebugBreak();
  void SetDebugBreak();
150

151
 private:
152
  int BreakIndexFromPosition(int position);
153

154
  Isolate* isolate();
155

156 157
  DebugBreakType GetDebugBreakType();

158 159 160 161 162
  Handle<DebugInfo> debug_info_;
  int break_index_;
  int position_;
  int statement_position_;
  SourcePositionTableIterator source_position_iterator_;
163
  DISALLOW_GARBAGE_COLLECTION(no_gc_)
164
};
165 166 167 168 169

// Linked list holding debug info objects. The debug info objects are kept as
// weak handles to avoid a debug info object to keep a function alive.
class DebugInfoListNode {
 public:
170
  DebugInfoListNode(Isolate* isolate, DebugInfo debug_info);
171
  ~DebugInfoListNode();
172 173 174

  DebugInfoListNode* next() { return next_; }
  void set_next(DebugInfoListNode* next) { next_ = next; }
dcarney's avatar
dcarney committed
175 176
  Handle<DebugInfo> debug_info() { return Handle<DebugInfo>(debug_info_); }

177 178
 private:
  // Global (weak) handle to the debug info object.
179
  Address* debug_info_;
180 181 182 183 184

  // Next pointer for linked list.
  DebugInfoListNode* next_;
};

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
class DebugFeatureTracker {
 public:
  enum Feature {
    kActive = 1,
    kBreakPoint = 2,
    kStepping = 3,
    kHeapSnapshot = 4,
    kAllocationTracking = 5,
    kProfiler = 6,
    kLiveEdit = 7,
  };

  explicit DebugFeatureTracker(Isolate* isolate)
      : isolate_(isolate), bitfield_(0) {}
  void Track(Feature feature);

 private:
  Isolate* isolate_;
  uint32_t bitfield_;
};

206 207 208 209 210 211 212
// This class contains the debugger support. The main purpose is to handle
// setting break points in the code.
//
// This class controls the debug info for all functions which currently have
// active breakpoints in them. This debug info is held in the heap root object
// debug_info which is a FixedArray. Each entry in this list is of class
// DebugInfo.
213
class V8_EXPORT_PRIVATE Debug {
214
 public:
215 216 217
  Debug(const Debug&) = delete;
  Debug& operator=(const Debug&) = delete;

218
  // Debug event triggers.
219 220
  void OnDebugBreak(Handle<FixedArray> break_points_hit, StepAction stepAction,
                    debug::BreakReasons break_reasons = {});
221
  void OnInstrumentationBreak();
222

223 224
  base::Optional<Object> OnThrow(Handle<Object> exception)
      V8_WARN_UNUSED_RESULT;
225
  void OnPromiseReject(Handle<Object> promise, Handle<Object> value);
226
  void OnCompileError(Handle<Script> script);
227
  void OnAfterCompile(Handle<Script> script);
228

229 230
  void HandleDebugBreak(IgnoreBreakMode ignore_break_mode,
                        debug::BreakReasons break_reasons);
231

232 233 234
  // The break target may not be the top-most frame, since we may be
  // breaking before entering a function that cannot contain break points.
  void Break(JavaScriptFrame* frame, Handle<JSFunction> break_target);
235

236 237 238 239
  // Scripts handling.
  Handle<FixedArray> GetLoadedScripts();

  // Break point handling.
240
  enum BreakPointKind { kRegular, kInstrumentation };
241
  bool SetBreakpoint(Handle<SharedFunctionInfo> shared,
242 243
                     Handle<BreakPoint> break_point, int* source_position);
  void ClearBreakPoint(Handle<BreakPoint> break_point);
244 245
  void ChangeBreakOnException(ExceptionBreakType type, bool enable);
  bool IsBreakOnException(ExceptionBreakType type);
246

247 248
  void SetTerminateOnResume();

249 250
  bool SetBreakPointForScript(Handle<Script> script, Handle<String> condition,
                              int* source_position, int* id);
251
  bool SetBreakpointForFunction(Handle<SharedFunctionInfo> shared,
252 253
                                Handle<String> condition, int* id,
                                BreakPointKind kind = kRegular);
254
  void RemoveBreakpoint(int id);
255
#if V8_ENABLE_WEBASSEMBLY
256 257
  void SetInstrumentationBreakpointForWasmScript(Handle<Script> script,
                                                 int* id);
258
  void RemoveBreakpointForWasmScript(Handle<Script> script, int id);
259

260
  void RecordWasmScriptWithBreakpoints(Handle<Script> script);
261
#endif  // V8_ENABLE_WEBASSEMBLY
262

263 264
  // Find breakpoints from the debug info and the break location and check
  // whether they are hit. Return an empty handle if not, or a FixedArray with
265 266
  // hit BreakPoint objects. has_break_points is set to true if position has
  // any non-instrumentation breakpoint.
267
  MaybeHandle<FixedArray> GetHitBreakPoints(Handle<DebugInfo> debug_info,
268 269
                                            int position,
                                            bool* has_break_points);
270

271
  // Stepping handling.
272
  void PrepareStep(StepAction step_action);
273
  void PrepareStepIn(Handle<JSFunction> function);
274
  void PrepareStepInSuspendedGenerator();
275
  void PrepareStepOnThrow();
276
  void ClearStepping();
277
  void PrepareRestartFrame(JavaScriptFrame* frame, int inlined_frame_index);
278

279 280 281
  void SetBreakOnNextFunctionCall();
  void ClearBreakOnNextFunctionCall();

282 283 284
  void DiscardBaselineCode(SharedFunctionInfo shared);
  void DiscardAllBaselineCode();

285
  void DeoptimizeFunction(Handle<SharedFunctionInfo> shared);
286
  void PrepareFunctionForDebugExecution(Handle<SharedFunctionInfo> shared);
287
  void InstallDebugBreakTrampoline();
288
  bool GetPossibleBreakpoints(Handle<Script> script, int start_position,
289
                              int end_position, bool restrict_to_function,
290
                              std::vector<BreakLocation>* locations);
291

292
  bool IsBlackboxed(Handle<SharedFunctionInfo> shared);
293
  bool ShouldBeSkipped();
294

295 296
  bool CanBreakAtEntry(Handle<SharedFunctionInfo> shared);

297
  void SetDebugDelegate(debug::DebugDelegate* delegate);
298

299
  // Returns whether the operation succeeded.
300 301 302
  bool EnsureBreakInfo(Handle<SharedFunctionInfo> shared);
  void CreateBreakInfo(Handle<SharedFunctionInfo> shared);
  Handle<DebugInfo> GetOrCreateDebugInfo(Handle<SharedFunctionInfo> shared);
303

304 305 306 307
  void InstallCoverageInfo(Handle<SharedFunctionInfo> shared,
                           Handle<CoverageInfo> coverage_info);
  void RemoveAllCoverageInfos();

308
  // This function is used in FunctionNameUsing* tests.
309 310 311 312 313 314 315 316 317 318
  Handle<Object> FindInnermostContainingFunctionInfo(Handle<Script> script,
                                                     int position);

  Handle<SharedFunctionInfo> FindClosestSharedFunctionInfoFromPosition(
      int position, Handle<Script> script,
      Handle<SharedFunctionInfo> outer_shared);

  bool FindSharedFunctionInfosIntersectingRange(
      Handle<Script> script, int start_position, int end_position,
      std::vector<Handle<SharedFunctionInfo>>* candidates);
319

320
  static Handle<Object> GetSourceBreakLocations(
321
      Isolate* isolate, Handle<SharedFunctionInfo> shared);
322

323
  // Check whether this frame is just about to return.
324
  bool IsBreakAtReturn(JavaScriptFrame* frame);
325

326
  bool AllFramesOnStackAreBlackboxed();
327

328 329 330 331 332
  // Set new script source, throw an exception if error occurred. When preview
  // is true: try to set source, throw exception if any without actual script
  // change. stack_changed is true if after editing script on pause stack is
  // changed and client should request stack trace again.
  bool SetScriptSource(Handle<Script> script, Handle<String> source,
333 334
                       bool preview, bool allow_top_frame_live_editing,
                       debug::LiveEditResult* result);
335

336 337
  int GetFunctionDebuggingId(Handle<JSFunction> function);

338
  // Threading support.
339 340
  char* ArchiveDebug(char* to);
  char* RestoreDebug(char* from);
341
  static int ArchiveSpacePerThread();
342
  void FreeThreadResources() {}
343
  void Iterate(RootVisitor* v);
344
  void InitThread(const ExecutionAccess& lock) { ThreadInit(); }
345

Yang Guo's avatar
Yang Guo committed
346
  bool CheckExecutionState() { return is_active(); }
347

348 349 350 351 352 353
  void StartSideEffectCheckMode();
  void StopSideEffectCheckMode();

  void ApplySideEffectChecks(Handle<DebugInfo> debug_info);
  void ClearSideEffectChecks(Handle<DebugInfo> debug_info);

354 355
  bool PerformSideEffectCheck(Handle<JSFunction> function,
                              Handle<Object> receiver);
356 357 358 359 360

  enum AccessorKind { kNotAccessor, kGetter, kSetter };
  bool PerformSideEffectCheckForCallback(Handle<Object> callback_info,
                                         Handle<Object> receiver,
                                         AccessorKind accessor_kind);
361
  bool PerformSideEffectCheckAtBytecode(InterpretedFrame* frame);
362
  bool PerformSideEffectCheckForObject(Handle<Object> object);
363

364 365
  // Flags and states.
  inline bool is_active() const { return is_active_; }
366
  inline bool in_debug_scope() const {
367
    return !!base::Relaxed_Load(&thread_local_.current_debug_scope_);
368
  }
369 370 371 372
  inline bool needs_check_on_function_call() const {
    return hook_on_function_call_;
  }

373
  void set_break_points_active(bool v) { break_points_active_ = v; }
374
  bool break_points_active() const { return break_points_active_; }
375

376
  StackFrameId break_frame_id() { return thread_local_.break_frame_id_; }
377

378
  Handle<Object> return_value_handle();
379 380
  Object return_value() { return thread_local_.return_value_; }
  void set_return_value(Object value) { thread_local_.return_value_ = value; }
381

382
  // Support for embedding into generated code.
383
  Address is_active_address() { return reinterpret_cast<Address>(&is_active_); }
384

385 386 387 388
  Address hook_on_function_call_address() {
    return reinterpret_cast<Address>(&hook_on_function_call_);
  }

389 390 391 392
  Address suspended_generator_address() {
    return reinterpret_cast<Address>(&thread_local_.suspended_generator_);
  }

393
  StepAction last_step_action() { return thread_local_.last_step_action_; }
394 395 396
  bool break_on_next_function_call() const {
    return thread_local_.break_on_next_function_call_;
  }
397

398 399 400 401
  bool scheduled_break_on_function_call() const {
    return thread_local_.scheduled_break_on_next_function_call_;
  }

402
  bool IsRestartFrameScheduled() const {
403 404
    return thread_local_.restart_frame_id_ != StackFrameId::NO_ID;
  }
405 406 407 408 409 410 411
  bool ShouldRestartFrame(StackFrameId id) const {
    return IsRestartFrameScheduled() && thread_local_.restart_frame_id_ == id;
  }
  void clear_restart_frame() {
    thread_local_.restart_frame_id_ = StackFrameId::NO_ID;
    thread_local_.restart_inline_frame_index_ = -1;
  }
412 413 414
  int restart_inline_frame_index() const {
    return thread_local_.restart_inline_frame_index_;
  }
415

416 417
  inline bool break_disabled() const { return break_disabled_; }

418 419
  DebugFeatureTracker* feature_tracker() { return &feature_tracker_; }

420 421 422 423
  // For functions in which we cannot set a break point, use a canonical
  // source position for break points.
  static const int kBreakAtEntryPosition = 0;

424 425 426
  // Use -1 to encode instrumentation breakpoints.
  static const int kInstrumentationId = -1;

427 428
  void RemoveBreakInfoAndMaybeFree(Handle<DebugInfo> debug_info);

429 430
  static char* Iterate(RootVisitor* v, char* thread_storage);

431
 private:
432
  explicit Debug(Isolate* isolate);
433
  ~Debug();
434

435
  void UpdateDebugInfosForExecutionMode();
436
  void UpdateState();
437
  void UpdateHookOnFunctionCall();
438 439
  void Unload();

440 441 442
  // Return the number of virtual frames below debugger entry.
  int CurrentFrameCount();

443
  inline bool ignore_events() const {
444 445
    return is_suppressed_ || !is_active_ ||
           isolate_->debug_execution_mode() == DebugInfo::kSideEffects;
446
  }
447

448
  void clear_suspended_generator() {
449
    thread_local_.suspended_generator_ = Smi::zero();
450 451 452
  }

  bool has_suspended_generator() const {
453
    return thread_local_.suspended_generator_ != Smi::zero();
454 455
  }

456
  bool IsExceptionBlackboxed(bool uncaught);
457

458 459
  void OnException(Handle<Object> exception, Handle<Object> promise,
                   v8::debug::ExceptionType exception_type);
460

461
  void ProcessCompileEvent(bool has_compile_error, Handle<Script> script);
462

463
  // Find the closest source position for a break point for a given position.
464
  int FindBreakablePosition(Handle<DebugInfo> debug_info, int source_position);
465 466 467 468 469 470 471
  // Instrument code to break at break points.
  void ApplyBreakPoints(Handle<DebugInfo> debug_info);
  // Clear code from instrumentation.
  void ClearBreakPoints(Handle<DebugInfo> debug_info);
  // Clear all code from instrumentation.
  void ClearAllBreakPoints();
  // Instrument a function with one-shots.
472 473
  void FloodWithOneShot(Handle<SharedFunctionInfo> function,
                        bool returns_only = false);
474
  // Clear all one-shot instrumentations, but restore break points.
475
  void ClearOneShot();
476

477 478
  bool IsFrameBlackboxed(JavaScriptFrame* frame);

479
  void ActivateStepOut(StackFrame* frame);
480 481
  bool IsBreakOnInstrumentation(Handle<DebugInfo> debug_info,
                                const BreakLocation& location);
482 483
  MaybeHandle<FixedArray> CheckBreakPoints(Handle<DebugInfo> debug_info,
                                           BreakLocation* location,
484 485 486 487 488
                                           bool* has_break_points);
  MaybeHandle<FixedArray> CheckBreakPointsForLocations(
      Handle<DebugInfo> debug_info, std::vector<BreakLocation>& break_locations,
      bool* has_break_points);

489 490 491
  MaybeHandle<FixedArray> GetHitBreakpointsAtCurrentStatement(
      JavaScriptFrame* frame, bool* hasBreakpoints);

492
  bool IsMutedAtCurrentLocation(JavaScriptFrame* frame);
493 494 495
  // Check whether a BreakPoint object is hit. Evaluate condition depending
  // on whether this is a regular break location or a break at function entry.
  bool CheckBreakPoint(Handle<BreakPoint> break_point, bool is_break_at_entry);
496

497
  inline void AssertDebugContext() { DCHECK(in_debug_scope()); }
498

499
  void ThreadInit();
500

501 502
  void PrintBreakLocation();

503 504
  void ClearAllDebuggerHints();

505
  // Wraps logic for clearing and maybe freeing all debug infos.
506
  using DebugInfoClearFunction = std::function<void(Handle<DebugInfo>)>;
507
  void ClearAllDebugInfos(const DebugInfoClearFunction& clear_function);
508

509 510 511 512
  void FindDebugInfo(Handle<DebugInfo> debug_info, DebugInfoListNode** prev,
                     DebugInfoListNode** curr);
  void FreeDebugInfoListNode(DebugInfoListNode* prev, DebugInfoListNode* node);

513 514 515
  void SetTemporaryObjectTrackingDisabled(bool disabled);
  bool GetTemporaryObjectTrackingDisabled() const;

516
  debug::DebugDelegate* debug_delegate_ = nullptr;
517

518
  // Debugger is active, i.e. there is a debug event listener attached.
519
  bool is_active_;
520 521 522 523
  // Debugger needs to be notified on every new function call.
  // Used for stepping and read-only checks
  bool hook_on_function_call_;
  // Suppress debug events.
524
  bool is_suppressed_;
525 526
  // Running liveedit.
  bool running_live_edit_ = false;
527
  // Do not trigger debug break events.
528
  bool break_disabled_;
529
  // Do not break on break points.
530
  bool break_points_active_;
531
  // Trigger debug break events for all exceptions.
532
  bool break_on_exception_;
533
  // Trigger debug break events for uncaught exceptions.
534
  bool break_on_uncaught_exception_;
535 536
  // Termination exception because side effect check has failed.
  bool side_effect_check_failed_;
537

538 539
  // List of active debug info objects.
  DebugInfoListNode* debug_info_list_;
540

541 542 543 544
  // Used for side effect check to mark temporary objects.
  class TemporaryObjectsTracker;
  std::unique_ptr<TemporaryObjectsTracker> temporary_objects_;

545 546
  Handle<RegExpMatchInfo> regexp_match_info_;

547 548 549
  // Used to collect histogram data on debugger feature usage.
  DebugFeatureTracker feature_tracker_;

550
  // Per-thread data.
551 552
  class ThreadLocal {
   public:
553
    // Top debugger entry.
554
    base::AtomicWord current_debug_scope_;
555

556
    // Frame id for the frame of the current break.
557
    StackFrameId break_frame_id_;
558

559 560 561
    // Step action for last step performed.
    StepAction last_step_action_;

562 563
    // If set, next PrepareStepIn will ignore this function until stepped into
    // another function, at which point this will be cleared.
564
    Object ignore_step_into_function_;
565 566 567 568

    // If set then we need to repeat StepOut action at return.
    bool fast_forward_to_return_;

569 570 571
    // Source statement position from last step next action.
    int last_statement_position_;

572
    // Frame pointer from last step next or step frame action.
573
    int last_frame_count_;
574

575
    // Frame pointer of the target frame we want to arrive at.
576
    int target_frame_count_;
577

578
    // Value of the accumulator at the point of entering the debugger.
579
    Object return_value_;
580

581
    // The suspended generator object to track when stepping.
582
    Object suspended_generator_;
583

584 585
    // Last used inspector breakpoint id.
    int last_breakpoint_id_;
586 587 588 589

    // This flag is true when SetBreakOnNextFunctionCall is called and it forces
    // debugger to break on next function call.
    bool break_on_next_function_call_;
590

591 592 593 594 595
    // This flag is true when we break via stack check (BreakReason::kScheduled)
    // We don't stay paused there but instead "step in" to the function similar
    // to what "BreakOnNextFunctionCall" does.
    bool scheduled_break_on_next_function_call_;

596 597 598
    // Throwing an exception may cause a Promise rejection.  For this purpose
    // we keep track of a stack of nested promises.
    Object promise_stack_;
599 600 601 602 603 604 605 606 607 608 609

    // Frame ID for the frame that needs to be restarted. StackFrameId::NO_ID
    // otherwise. The unwinder uses the id to restart execution in this frame
    // instead of any potential catch handler.
    StackFrameId restart_frame_id_;

    // If `restart_frame_id_` is an optimized frame, then this index denotes
    // which of the inlined frames we actually want to restart. The
    // deoptimizer uses the info to materialize and drop execution into the
    // right frame.
    int restart_inline_frame_index_;
610 611
  };

612 613
  static void Iterate(RootVisitor* v, ThreadLocal* thread_local_data);

614
  // Storage location for registers when handling debug break calls
615
  ThreadLocal thread_local_;
616

617
#if V8_ENABLE_WEBASSEMBLY
618
  // This is a global handle, lazily initialized.
619
  Handle<WeakArrayList> wasm_scripts_with_break_points_;
620
#endif  // V8_ENABLE_WEBASSEMBLY
621

622 623 624
  Isolate* isolate_;

  friend class Isolate;
625
  friend class DebugScope;
626
  friend class DisableBreak;
627
  friend class DisableTemporaryObjectTracking;
628
  friend class LiveEdit;
629
  friend class SuppressDebug;
630

631
  friend Handle<FixedArray> GetDebuggedFunctions();  // In test-debug.cc
632
  friend void CheckDebuggerUnloaded();               // In test-debug.cc
633 634
};

635 636
// This scope is used to load and enter the debug context and create a new
// break state.  Leaving the scope will restore the previous state.
637
class V8_NODISCARD DebugScope {
638
 public:
639 640
  explicit DebugScope(Debug* debug);
  ~DebugScope();
641

642 643
  void set_terminate_on_resume();

644
 private:
645 646 647
  Isolate* isolate() { return debug_->isolate_; }

  Debug* debug_;
648 649
  DebugScope* prev_;             // Previous scope if entered recursively.
  StackFrameId break_frame_id_;  // Previous break frame id.
650
  PostponeInterruptsScope no_interrupts_;
651 652
  // This is used as a boolean.
  bool terminate_on_resume_ = false;
653 654
};

655 656 657 658
// This scope is used to handle return values in nested debug break points.
// When there are nested debug breaks, we use this to restore the return
// value to the previous state. This is not merged with DebugScope because
// return_value_ will not be cleared when we use DebugScope.
659
class V8_NODISCARD ReturnValueScope {
660 661 662 663 664 665 666 667
 public:
  explicit ReturnValueScope(Debug* debug);
  ~ReturnValueScope();

 private:
  Debug* debug_;
  Handle<Object> return_value_;  // Previous result.
};
668

669
// Stack allocated class for disabling break.
670
class DisableBreak {
671
 public:
672
  explicit DisableBreak(Debug* debug, bool disable = true)
673
      : debug_(debug), previous_break_disabled_(debug->break_disabled_) {
674
    debug_->break_disabled_ = disable;
675
  }
676
  ~DisableBreak() { debug_->break_disabled_ = previous_break_disabled_; }
677 678
  DisableBreak(const DisableBreak&) = delete;
  DisableBreak& operator=(const DisableBreak&) = delete;
679 680 681

 private:
  Debug* debug_;
682
  bool previous_break_disabled_;
683 684
};

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
// Stack allocated class for disabling temporary object tracking.
class DisableTemporaryObjectTracking {
 public:
  explicit DisableTemporaryObjectTracking(Debug* debug)
      : debug_(debug),
        previous_tracking_disabled_(
            debug->GetTemporaryObjectTrackingDisabled()) {
    debug_->SetTemporaryObjectTrackingDisabled(true);
  }
  ~DisableTemporaryObjectTracking() {
    debug_->SetTemporaryObjectTrackingDisabled(previous_tracking_disabled_);
  }
  DisableTemporaryObjectTracking(const DisableTemporaryObjectTracking&) =
      delete;
  DisableTemporaryObjectTracking& operator=(
      const DisableTemporaryObjectTracking&) = delete;

 private:
  Debug* debug_;
  bool previous_tracking_disabled_;
};

707
class SuppressDebug {
708 709 710 711
 public:
  explicit SuppressDebug(Debug* debug)
      : debug_(debug), old_state_(debug->is_suppressed_) {
    debug_->is_suppressed_ = true;
712
  }
713
  ~SuppressDebug() { debug_->is_suppressed_ = old_state_; }
714 715
  SuppressDebug(const SuppressDebug&) = delete;
  SuppressDebug& operator=(const SuppressDebug&) = delete;
716 717

 private:
718 719
  Debug* debug_;
  bool old_state_;
720 721
};

722 723
}  // namespace internal
}  // namespace v8
724

725
#endif  // V8_DEBUG_DEBUG_H_