5 #ifndef V8_DEBUG_DEBUG_H_ 6 #define V8_DEBUG_DEBUG_H_ 10 #include "src/allocation.h" 11 #include "src/base/atomicops.h" 12 #include "src/base/hashmap.h" 13 #include "src/base/platform/platform.h" 14 #include "src/debug/debug-interface.h" 15 #include "src/debug/interface-types.h" 16 #include "src/execution.h" 17 #include "src/flags.h" 18 #include "src/frames.h" 19 #include "src/globals.h" 20 #include "src/heap/factory.h" 21 #include "src/objects/debug-objects.h" 22 #include "src/runtime/runtime.h" 23 #include "src/source-position-table.h" 24 #include "src/string-stream.h" 25 #include "src/v8threads.h" 32 class JSGeneratorObject;
35 enum StepAction : int8_t {
41 LastStepAction = StepIn
45 enum ExceptionBreakType {
47 BreakUncaughtException = 1
54 DEBUG_BREAK_SLOT_AT_CALL,
55 DEBUG_BREAK_SLOT_AT_RETURN,
56 DEBUG_BREAK_SLOT_AT_SUSPEND,
60 enum IgnoreBreakMode {
61 kIgnoreIfAllFramesBlackboxed,
62 kIgnoreIfTopFrameBlackboxed
72 std::vector<BreakLocation>* result_out);
74 inline bool IsSuspend()
const {
return type_ == DEBUG_BREAK_SLOT_AT_SUSPEND; }
75 inline bool IsReturn()
const {
return type_ == DEBUG_BREAK_SLOT_AT_RETURN; }
76 inline bool IsReturnOrSuspend()
const {
77 return type_ >= DEBUG_BREAK_SLOT_AT_RETURN;
79 inline bool IsCall()
const {
return type_ == DEBUG_BREAK_SLOT_AT_CALL; }
80 inline bool IsDebugBreakSlot()
const {
return type_ >= DEBUG_BREAK_SLOT; }
81 inline bool IsDebuggerStatement()
const {
82 return type_ == DEBUGGER_STATEMENT;
84 inline bool IsDebugBreakAtEntry()
const {
85 bool result = type_ == DEBUG_BREAK_AT_ENTRY;
91 inline int position()
const {
return position_; }
93 debug::BreakLocationType
type()
const;
100 int code_offset,
int position,
int generator_obj_reg_index)
101 : abstract_code_(abstract_code),
102 code_offset_(code_offset),
105 generator_obj_reg_index_(generator_obj_reg_index) {
106 DCHECK_NE(NOT_DEBUG_BREAK, type_);
113 generator_obj_reg_index_(0) {}
119 void SetDebugBreak();
120 void ClearDebugBreak();
124 DebugBreakType type_;
126 int generator_obj_reg_index_;
136 bool Done()
const {
return source_position_iterator_.done(); }
139 void SkipToPosition(
int position);
140 void SkipTo(
int count) {
141 while (count-- > 0) Next();
144 int code_offset() {
return source_position_iterator_.code_offset(); }
145 int break_index()
const {
return break_index_; }
146 inline int position()
const {
return position_; }
147 inline int statement_position()
const {
return statement_position_; }
149 void ClearDebugBreak();
150 void SetDebugBreak();
153 int BreakIndexFromPosition(
int position);
157 DebugBreakType GetDebugBreakType();
162 int statement_position_;
195 kAllocationTracking = 5,
201 : isolate_(isolate), bitfield_(0) {}
202 void Track(Feature feature);
227 void HandleDebugBreak(IgnoreBreakMode ignore_break_mode);
240 void ChangeBreakOnException(ExceptionBreakType
type,
bool enable);
241 bool IsBreakOnException(ExceptionBreakType
type);
244 int* source_position,
int*
id);
247 void RemoveBreakpoint(
int id);
256 void PrepareStep(StepAction step_action);
258 void PrepareStepInSuspendedGenerator();
259 void PrepareStepOnThrow();
260 void ClearStepping();
262 void SetBreakOnNextFunctionCall();
263 void ClearBreakOnNextFunctionCall();
267 void InstallDebugBreakTrampoline();
268 bool GetPossibleBreakpoints(
Handle<Script> script,
int start_position,
269 int end_position,
bool restrict_to_function,
270 std::vector<BreakLocation>* locations);
285 void RemoveAllCoverageInfos();
300 bool AllFramesOnStackAreBlackboxed();
312 char* ArchiveDebug(
char* to);
313 char* RestoreDebug(
char* from);
314 static int ArchiveSpacePerThread();
315 void FreeThreadResources() { }
319 bool CheckExecutionState() {
return is_active(); }
321 void StartSideEffectCheckMode();
322 void StopSideEffectCheckMode();
330 enum AccessorKind { kNotAccessor, kGetter, kSetter };
331 bool PerformSideEffectCheckForCallback(
Handle<Object> callback_info,
333 AccessorKind accessor_kind);
338 inline bool is_active()
const {
return is_active_; }
339 inline bool in_debug_scope()
const {
340 return !!base::Relaxed_Load(&thread_local_.current_debug_scope_);
342 inline bool needs_check_on_function_call()
const {
343 return hook_on_function_call_;
346 void set_break_points_active(
bool v) { break_points_active_ = v; }
347 bool break_points_active()
const {
return break_points_active_; }
349 StackFrame::Id break_frame_id() {
return thread_local_.break_frame_id_; }
352 Object* return_value() {
return thread_local_.return_value_; }
353 void set_return_value(
Object* value) { thread_local_.return_value_ = value; }
357 return reinterpret_cast<Address>(&is_active_);
360 Address hook_on_function_call_address() {
361 return reinterpret_cast<Address>(&hook_on_function_call_);
364 Address suspended_generator_address() {
365 return reinterpret_cast<Address>(&thread_local_.suspended_generator_);
369 return reinterpret_cast<Address>(&thread_local_.restart_fp_);
371 bool will_restart()
const {
372 return thread_local_.restart_fp_ != kNullAddress;
375 StepAction last_step_action() {
return thread_local_.last_step_action_; }
376 bool break_on_next_function_call()
const {
377 return thread_local_.break_on_next_function_call_;
384 static const int kBreakAtEntryPosition = 0;
392 void UpdateDebugInfosForExecutionMode();
394 void UpdateHookOnFunctionCall();
398 int CurrentFrameCount();
400 inline bool ignore_events()
const {
401 return is_suppressed_ || !is_active_ ||
402 isolate_->debug_execution_mode() == DebugInfo::kSideEffects;
404 inline bool break_disabled()
const {
return break_disabled_; }
406 void clear_suspended_generator() {
407 thread_local_.suspended_generator_ = Smi::kZero;
410 bool has_suspended_generator()
const {
411 return thread_local_.suspended_generator_ != Smi::kZero;
414 bool IsExceptionBlackboxed(
bool uncaught);
417 v8::debug::ExceptionType exception_type);
419 void ProcessCompileEvent(
bool has_compile_error,
Handle<Script> script);
428 void ClearAllBreakPoints();
431 bool returns_only =
false);
440 bool* has_break_points =
nullptr);
446 inline void AssertDebugContext() {
447 DCHECK(in_debug_scope());
452 void PrintBreakLocation();
454 void ClearAllDebuggerHints();
457 typedef std::function<void(Handle<DebugInfo>)> DebugInfoClearFunction;
458 void ClearAllDebugInfos(
const DebugInfoClearFunction& clear_function);
470 bool hook_on_function_call_;
474 bool running_live_edit_ =
false;
476 bool break_disabled_;
478 bool break_points_active_;
480 bool break_on_exception_;
482 bool break_on_uncaught_exception_;
484 bool side_effect_check_failed_;
491 std::unique_ptr<TemporaryObjectsTracker> temporary_objects_;
502 base::AtomicWord current_debug_scope_;
505 StackFrame::Id break_frame_id_;
508 StepAction last_step_action_;
512 Object* ignore_step_into_function_;
515 bool fast_forward_to_return_;
518 int last_statement_position_;
521 int last_frame_count_;
524 int target_frame_count_;
530 Object* suspended_generator_;
536 int last_breakpoint_id_;
540 bool break_on_next_function_call_;
544 ThreadLocal thread_local_;
555 friend void CheckDebuggerUnloaded();
557 DISALLOW_COPY_AND_ASSIGN(
Debug);
568 Isolate* isolate() {
return debug_->isolate_; }
572 StackFrame::Id break_frame_id_;
594 : debug_(debug), previous_break_disabled_(debug->break_disabled_) {
595 debug_->break_disabled_ = disable;
598 debug_->break_disabled_ = previous_break_disabled_;
603 bool previous_break_disabled_;
610 : debug_(debug), old_state_(debug->is_suppressed_) {
611 debug_->is_suppressed_ =
true;
624 enum DebugBreakCallHelperMode {
625 SAVE_RESULT_REGISTER,
626 IGNORE_RESULT_REGISTER
634 static void GenerateHandleDebuggerStatement(
MacroAssembler* masm);
644 #endif // V8_DEBUG_DEBUG_H_