1 // Copyright 2012 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_DEBUG_DEBUG_H_ 6 #define V8_DEBUG_DEBUG_H_ 7 8 #include "src/allocation.h" 9 #include "src/arguments.h" 10 #include "src/assembler.h" 11 #include "src/base/atomicops.h" 12 #include "src/base/platform/platform.h" 13 #include "src/debug/liveedit.h" 14 #include "src/execution.h" 15 #include "src/factory.h" 16 #include "src/flags.h" 17 #include "src/frames.h" 18 #include "src/hashmap.h" 19 #include "src/runtime/runtime.h" 20 #include "src/string-stream.h" 21 #include "src/v8threads.h" 22 23 #include "include/v8-debug.h" 24 25 namespace v8 { 26 namespace internal { 27 28 29 // Forward declarations. 30 class DebugScope; 31 32 33 // Step actions. NOTE: These values are in macros.py as well. 34 enum StepAction : int8_t { 35 StepNone = -1, // Stepping not prepared. 36 StepOut = 0, // Step out of the current function. 37 StepNext = 1, // Step to the next statement in the current function. 38 StepIn = 2, // Step into new functions invoked or the next statement 39 // in the current function. 40 StepFrame = 3 // Step into a new frame or return to previous frame. 41 }; 42 43 44 // Type of exception break. NOTE: These values are in macros.py as well. 45 enum ExceptionBreakType { 46 BreakException = 0, 47 BreakUncaughtException = 1 48 }; 49 50 51 // Type of exception break. 52 enum BreakLocatorType { ALL_BREAK_LOCATIONS, CALLS_AND_RETURNS }; 53 54 55 // The different types of breakpoint position alignments. 56 // Must match Debug.BreakPositionAlignment in debug.js 57 enum BreakPositionAlignment { 58 STATEMENT_ALIGNED = 0, 59 BREAK_POSITION_ALIGNED = 1 60 }; 61 62 63 class BreakLocation { 64 public: 65 // Find the break point at the supplied address, or the closest one before 66 // the address. 67 static BreakLocation FromAddress(Handle<DebugInfo> debug_info, Address pc); 68 69 static void FromAddressSameStatement(Handle<DebugInfo> debug_info, Address pc, 70 List<BreakLocation>* result_out); 71 72 static BreakLocation FromPosition(Handle<DebugInfo> debug_info, int position, 73 BreakPositionAlignment alignment); 74 75 bool IsDebugBreak() const; 76 77 inline bool IsReturn() const { 78 return RelocInfo::IsDebugBreakSlotAtReturn(rmode_); 79 } 80 inline bool IsCall() const { 81 return RelocInfo::IsDebugBreakSlotAtCall(rmode_); 82 } 83 inline bool HasBreakPoint() const { 84 return debug_info_->HasBreakPoint(pc_offset_); 85 } 86 87 Handle<Object> BreakPointObjects() const; 88 89 void SetBreakPoint(Handle<Object> break_point_object); 90 void ClearBreakPoint(Handle<Object> break_point_object); 91 92 void SetOneShot(); 93 void ClearOneShot(); 94 95 96 inline RelocInfo rinfo() const { 97 return RelocInfo(debug_info_->GetIsolate(), pc(), rmode(), data_, code()); 98 } 99 100 inline int position() const { return position_; } 101 inline int statement_position() const { return statement_position_; } 102 103 inline Address pc() const { return code()->entry() + pc_offset_; } 104 105 inline RelocInfo::Mode rmode() const { return rmode_; } 106 107 inline Code* code() const { return debug_info_->code(); } 108 109 private: 110 BreakLocation(Handle<DebugInfo> debug_info, RelocInfo* rinfo, int position, 111 int statement_position); 112 113 class Iterator { 114 public: 115 Iterator(Handle<DebugInfo> debug_info, BreakLocatorType type); 116 117 BreakLocation GetBreakLocation() { 118 return BreakLocation(debug_info_, rinfo(), position(), 119 statement_position()); 120 } 121 122 inline bool Done() const { return reloc_iterator_.done(); } 123 void Next(); 124 125 void SkipTo(int count) { 126 while (count-- > 0) Next(); 127 } 128 129 inline RelocInfo::Mode rmode() { return reloc_iterator_.rinfo()->rmode(); } 130 inline RelocInfo* rinfo() { return reloc_iterator_.rinfo(); } 131 inline Address pc() { return rinfo()->pc(); } 132 int break_index() const { return break_index_; } 133 inline int position() const { return position_; } 134 inline int statement_position() const { return statement_position_; } 135 136 private: 137 static int GetModeMask(BreakLocatorType type); 138 139 Handle<DebugInfo> debug_info_; 140 RelocIterator reloc_iterator_; 141 int break_index_; 142 int position_; 143 int statement_position_; 144 145 DisallowHeapAllocation no_gc_; 146 147 DISALLOW_COPY_AND_ASSIGN(Iterator); 148 }; 149 150 friend class Debug; 151 152 static int BreakIndexFromAddress(Handle<DebugInfo> debug_info, Address pc); 153 154 void SetDebugBreak(); 155 void ClearDebugBreak(); 156 157 inline bool IsDebuggerStatement() const { 158 return RelocInfo::IsDebuggerStatement(rmode_); 159 } 160 inline bool IsDebugBreakSlot() const { 161 return RelocInfo::IsDebugBreakSlot(rmode_); 162 } 163 164 Handle<DebugInfo> debug_info_; 165 int pc_offset_; 166 RelocInfo::Mode rmode_; 167 intptr_t data_; 168 int position_; 169 int statement_position_; 170 }; 171 172 173 // Linked list holding debug info objects. The debug info objects are kept as 174 // weak handles to avoid a debug info object to keep a function alive. 175 class DebugInfoListNode { 176 public: 177 explicit DebugInfoListNode(DebugInfo* debug_info); 178 ~DebugInfoListNode(); 179 180 DebugInfoListNode* next() { return next_; } 181 void set_next(DebugInfoListNode* next) { next_ = next; } 182 Handle<DebugInfo> debug_info() { return Handle<DebugInfo>(debug_info_); } 183 184 private: 185 // Global (weak) handle to the debug info object. 186 DebugInfo** debug_info_; 187 188 // Next pointer for linked list. 189 DebugInfoListNode* next_; 190 }; 191 192 193 194 // Message delivered to the message handler callback. This is either a debugger 195 // event or the response to a command. 196 class MessageImpl: public v8::Debug::Message { 197 public: 198 // Create a message object for a debug event. 199 static MessageImpl NewEvent(DebugEvent event, 200 bool running, 201 Handle<JSObject> exec_state, 202 Handle<JSObject> event_data); 203 204 // Create a message object for the response to a debug command. 205 static MessageImpl NewResponse(DebugEvent event, 206 bool running, 207 Handle<JSObject> exec_state, 208 Handle<JSObject> event_data, 209 Handle<String> response_json, 210 v8::Debug::ClientData* client_data); 211 212 // Implementation of interface v8::Debug::Message. 213 virtual bool IsEvent() const; 214 virtual bool IsResponse() const; 215 virtual DebugEvent GetEvent() const; 216 virtual bool WillStartRunning() const; 217 virtual v8::Local<v8::Object> GetExecutionState() const; 218 virtual v8::Local<v8::Object> GetEventData() const; 219 virtual v8::Local<v8::String> GetJSON() const; 220 virtual v8::Local<v8::Context> GetEventContext() const; 221 virtual v8::Debug::ClientData* GetClientData() const; 222 virtual v8::Isolate* GetIsolate() const; 223 224 private: 225 MessageImpl(bool is_event, 226 DebugEvent event, 227 bool running, 228 Handle<JSObject> exec_state, 229 Handle<JSObject> event_data, 230 Handle<String> response_json, 231 v8::Debug::ClientData* client_data); 232 233 bool is_event_; // Does this message represent a debug event? 234 DebugEvent event_; // Debug event causing the break. 235 bool running_; // Will the VM start running after this event? 236 Handle<JSObject> exec_state_; // Current execution state. 237 Handle<JSObject> event_data_; // Data associated with the event. 238 Handle<String> response_json_; // Response JSON if message holds a response. 239 v8::Debug::ClientData* client_data_; // Client data passed with the request. 240 }; 241 242 243 // Details of the debug event delivered to the debug event listener. 244 class EventDetailsImpl : public v8::Debug::EventDetails { 245 public: 246 EventDetailsImpl(DebugEvent event, 247 Handle<JSObject> exec_state, 248 Handle<JSObject> event_data, 249 Handle<Object> callback_data, 250 v8::Debug::ClientData* client_data); 251 virtual DebugEvent GetEvent() const; 252 virtual v8::Local<v8::Object> GetExecutionState() const; 253 virtual v8::Local<v8::Object> GetEventData() const; 254 virtual v8::Local<v8::Context> GetEventContext() const; 255 virtual v8::Local<v8::Value> GetCallbackData() const; 256 virtual v8::Debug::ClientData* GetClientData() const; 257 private: 258 DebugEvent event_; // Debug event causing the break. 259 Handle<JSObject> exec_state_; // Current execution state. 260 Handle<JSObject> event_data_; // Data associated with the event. 261 Handle<Object> callback_data_; // User data passed with the callback 262 // when it was registered. 263 v8::Debug::ClientData* client_data_; // Data passed to DebugBreakForCommand. 264 }; 265 266 267 // Message send by user to v8 debugger or debugger output message. 268 // In addition to command text it may contain a pointer to some user data 269 // which are expected to be passed along with the command reponse to message 270 // handler. 271 class CommandMessage { 272 public: 273 static CommandMessage New(const Vector<uint16_t>& command, 274 v8::Debug::ClientData* data); 275 CommandMessage(); 276 277 // Deletes user data and disposes of the text. 278 void Dispose(); 279 Vector<uint16_t> text() const { return text_; } 280 v8::Debug::ClientData* client_data() const { return client_data_; } 281 private: 282 CommandMessage(const Vector<uint16_t>& text, 283 v8::Debug::ClientData* data); 284 285 Vector<uint16_t> text_; 286 v8::Debug::ClientData* client_data_; 287 }; 288 289 290 // A Queue of CommandMessage objects. A thread-safe version is 291 // LockingCommandMessageQueue, based on this class. 292 class CommandMessageQueue BASE_EMBEDDED { 293 public: 294 explicit CommandMessageQueue(int size); 295 ~CommandMessageQueue(); 296 bool IsEmpty() const { return start_ == end_; } 297 CommandMessage Get(); 298 void Put(const CommandMessage& message); 299 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). 300 private: 301 // Doubles the size of the message queue, and copies the messages. 302 void Expand(); 303 304 CommandMessage* messages_; 305 int start_; 306 int end_; 307 int size_; // The size of the queue buffer. Queue can hold size-1 messages. 308 }; 309 310 311 // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage 312 // messages. The message data is not managed by LockingCommandMessageQueue. 313 // Pointers to the data are passed in and out. Implemented by adding a 314 // Mutex to CommandMessageQueue. Includes logging of all puts and gets. 315 class LockingCommandMessageQueue BASE_EMBEDDED { 316 public: 317 LockingCommandMessageQueue(Logger* logger, int size); 318 bool IsEmpty() const; 319 CommandMessage Get(); 320 void Put(const CommandMessage& message); 321 void Clear(); 322 private: 323 Logger* logger_; 324 CommandMessageQueue queue_; 325 mutable base::Mutex mutex_; 326 DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue); 327 }; 328 329 330 class DebugFeatureTracker { 331 public: 332 enum Feature { 333 kActive = 1, 334 kBreakPoint = 2, 335 kStepping = 3, 336 kHeapSnapshot = 4, 337 kAllocationTracking = 5, 338 kProfiler = 6, 339 kLiveEdit = 7, 340 }; 341 342 explicit DebugFeatureTracker(Isolate* isolate) 343 : isolate_(isolate), bitfield_(0) {} 344 void Track(Feature feature); 345 346 private: 347 Isolate* isolate_; 348 uint32_t bitfield_; 349 }; 350 351 352 // This class contains the debugger support. The main purpose is to handle 353 // setting break points in the code. 354 // 355 // This class controls the debug info for all functions which currently have 356 // active breakpoints in them. This debug info is held in the heap root object 357 // debug_info which is a FixedArray. Each entry in this list is of class 358 // DebugInfo. 359 class Debug { 360 public: 361 // Debug event triggers. 362 void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); 363 364 void OnThrow(Handle<Object> exception); 365 void OnPromiseReject(Handle<JSObject> promise, Handle<Object> value); 366 void OnCompileError(Handle<Script> script); 367 void OnBeforeCompile(Handle<Script> script); 368 void OnAfterCompile(Handle<Script> script); 369 void OnPromiseEvent(Handle<JSObject> data); 370 void OnAsyncTaskEvent(Handle<JSObject> data); 371 372 // API facing. 373 void SetEventListener(Handle<Object> callback, Handle<Object> data); 374 void SetMessageHandler(v8::Debug::MessageHandler handler); 375 void EnqueueCommandMessage(Vector<const uint16_t> command, 376 v8::Debug::ClientData* client_data = NULL); 377 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<Object> fun, 378 Handle<Object> data); 379 Handle<Context> GetDebugContext(); 380 void HandleDebugBreak(); 381 void ProcessDebugMessages(bool debug_command_only); 382 383 // Internal logic 384 bool Load(); 385 void Break(Arguments args, JavaScriptFrame*); 386 void SetAfterBreakTarget(JavaScriptFrame* frame); 387 388 // Scripts handling. 389 Handle<FixedArray> GetLoadedScripts(); 390 391 // Break point handling. 392 bool SetBreakPoint(Handle<JSFunction> function, 393 Handle<Object> break_point_object, 394 int* source_position); 395 bool SetBreakPointForScript(Handle<Script> script, 396 Handle<Object> break_point_object, 397 int* source_position, 398 BreakPositionAlignment alignment); 399 void ClearBreakPoint(Handle<Object> break_point_object); 400 void ClearAllBreakPoints(); 401 void FloodWithOneShot(Handle<JSFunction> function, 402 BreakLocatorType type = ALL_BREAK_LOCATIONS); 403 void ChangeBreakOnException(ExceptionBreakType type, bool enable); 404 bool IsBreakOnException(ExceptionBreakType type); 405 406 // Stepping handling. 407 void PrepareStep(StepAction step_action); 408 void PrepareStepIn(Handle<JSFunction> function); 409 void PrepareStepOnThrow(); 410 void ClearStepping(); 411 void ClearStepOut(); 412 void EnableStepIn(); 413 414 void GetStepinPositions(JavaScriptFrame* frame, StackFrame::Id frame_id, 415 List<int>* results_out); 416 417 bool PrepareFunctionForBreakPoints(Handle<SharedFunctionInfo> shared); 418 419 // Returns whether the operation succeeded. Compilation can only be triggered 420 // if a valid closure is passed as the second argument, otherwise the shared 421 // function needs to be compiled already. 422 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared, 423 Handle<JSFunction> function); 424 void CreateDebugInfo(Handle<SharedFunctionInfo> shared); 425 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); 426 427 template <typename C> 428 bool CompileToRevealInnerFunctions(C* compilable); 429 430 // This function is used in FunctionNameUsing* tests. 431 Handle<Object> FindSharedFunctionInfoInScript(Handle<Script> script, 432 int position); 433 434 static Handle<Object> GetSourceBreakLocations( 435 Handle<SharedFunctionInfo> shared, 436 BreakPositionAlignment position_aligment); 437 438 // Check whether a global object is the debug global object. 439 bool IsDebugGlobal(JSGlobalObject* global); 440 441 // Check whether this frame is just about to return. 442 bool IsBreakAtReturn(JavaScriptFrame* frame); 443 444 // Support for LiveEdit 445 void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, 446 LiveEdit::FrameDropMode mode); 447 448 // Threading support. 449 char* ArchiveDebug(char* to); 450 char* RestoreDebug(char* from); 451 static int ArchiveSpacePerThread(); 452 void FreeThreadResources() { } 453 454 // Record function from which eval was called. 455 static void RecordEvalCaller(Handle<Script> script); 456 457 bool CheckExecutionState(int id) { 458 return is_active() && !debug_context().is_null() && break_id() != 0 && 459 break_id() == id; 460 } 461 462 // Flags and states. 463 DebugScope* debugger_entry() { 464 return reinterpret_cast<DebugScope*>( 465 base::NoBarrier_Load(&thread_local_.current_debug_scope_)); 466 } 467 inline Handle<Context> debug_context() { return debug_context_; } 468 469 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } 470 bool live_edit_enabled() const { 471 return FLAG_enable_liveedit && live_edit_enabled_; 472 } 473 474 inline bool is_active() const { return is_active_; } 475 inline bool is_loaded() const { return !debug_context_.is_null(); } 476 inline bool in_debug_scope() const { 477 return !!base::NoBarrier_Load(&thread_local_.current_debug_scope_); 478 } 479 void set_break_points_active(bool v) { break_points_active_ = v; } 480 bool break_points_active() const { return break_points_active_; } 481 482 StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; } 483 int break_id() { return thread_local_.break_id_; } 484 485 // Support for embedding into generated code. 486 Address is_active_address() { 487 return reinterpret_cast<Address>(&is_active_); 488 } 489 490 Address after_break_target_address() { 491 return reinterpret_cast<Address>(&after_break_target_); 492 } 493 494 Address step_in_enabled_address() { 495 return reinterpret_cast<Address>(&thread_local_.step_in_enabled_); 496 } 497 498 StepAction last_step_action() { return thread_local_.last_step_action_; } 499 500 DebugFeatureTracker* feature_tracker() { return &feature_tracker_; } 501 502 private: 503 explicit Debug(Isolate* isolate); 504 505 void UpdateState(); 506 void Unload(); 507 void SetNextBreakId() { 508 thread_local_.break_id_ = ++thread_local_.break_count_; 509 } 510 511 // Check whether there are commands in the command queue. 512 inline bool has_commands() const { return !command_queue_.IsEmpty(); } 513 inline bool ignore_events() const { return is_suppressed_ || !is_active_; } 514 inline bool break_disabled() const { 515 return break_disabled_ || in_debug_event_listener_; 516 } 517 518 void OnException(Handle<Object> exception, Handle<Object> promise); 519 520 // Constructors for debug event objects. 521 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState(); 522 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent( 523 Handle<Object> break_points_hit); 524 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent( 525 Handle<Object> exception, 526 bool uncaught, 527 Handle<Object> promise); 528 MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent( 529 Handle<Script> script, v8::DebugEvent type); 530 MUST_USE_RESULT MaybeHandle<Object> MakePromiseEvent( 531 Handle<JSObject> promise_event); 532 MUST_USE_RESULT MaybeHandle<Object> MakeAsyncTaskEvent( 533 Handle<JSObject> task_event); 534 535 // Mirror cache handling. 536 void ClearMirrorCache(); 537 538 MaybeHandle<Object> PromiseHasUserDefinedRejectHandler( 539 Handle<JSObject> promise); 540 541 void CallEventCallback(v8::DebugEvent event, 542 Handle<Object> exec_state, 543 Handle<Object> event_data, 544 v8::Debug::ClientData* client_data); 545 void ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script); 546 void ProcessDebugEvent(v8::DebugEvent event, 547 Handle<JSObject> event_data, 548 bool auto_continue); 549 void NotifyMessageHandler(v8::DebugEvent event, 550 Handle<JSObject> exec_state, 551 Handle<JSObject> event_data, 552 bool auto_continue); 553 void InvokeMessageHandler(MessageImpl message); 554 555 void ClearOneShot(); 556 void ActivateStepOut(StackFrame* frame); 557 void RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info); 558 Handle<Object> CheckBreakPoints(Handle<Object> break_point); 559 bool CheckBreakPoint(Handle<Object> break_point_object); 560 MaybeHandle<Object> CallFunction(const char* name, int argc, 561 Handle<Object> args[]); 562 563 inline void AssertDebugContext() { 564 DCHECK(isolate_->context() == *debug_context()); 565 DCHECK(in_debug_scope()); 566 } 567 568 void ThreadInit(); 569 570 // Global handles. 571 Handle<Context> debug_context_; 572 Handle<Object> event_listener_; 573 Handle<Object> event_listener_data_; 574 575 v8::Debug::MessageHandler message_handler_; 576 577 static const int kQueueInitialSize = 4; 578 base::Semaphore command_received_; // Signaled for each command received. 579 LockingCommandMessageQueue command_queue_; 580 581 bool is_active_; 582 bool is_suppressed_; 583 bool live_edit_enabled_; 584 bool break_disabled_; 585 bool break_points_active_; 586 bool in_debug_event_listener_; 587 bool break_on_exception_; 588 bool break_on_uncaught_exception_; 589 590 DebugInfoListNode* debug_info_list_; // List of active debug info objects. 591 592 // Storage location for jump when exiting debug break calls. 593 // Note that this address is not GC safe. It should be computed immediately 594 // before returning to the DebugBreakCallHelper. 595 Address after_break_target_; 596 597 // Used to collect histogram data on debugger feature usage. 598 DebugFeatureTracker feature_tracker_; 599 600 // Per-thread data. 601 class ThreadLocal { 602 public: 603 // Top debugger entry. 604 base::AtomicWord current_debug_scope_; 605 606 // Counter for generating next break id. 607 int break_count_; 608 609 // Current break id. 610 int break_id_; 611 612 // Frame id for the frame of the current break. 613 StackFrame::Id break_frame_id_; 614 615 // Step action for last step performed. 616 StepAction last_step_action_; 617 618 // Source statement position from last step next action. 619 int last_statement_position_; 620 621 // Frame pointer from last step next or step frame action. 622 Address last_fp_; 623 624 // Frame pointer of the target frame we want to arrive at. 625 Address target_fp_; 626 627 // Whether functions are flooded on entry for step-in and step-frame. 628 // If we stepped out to the embedder, disable flooding to spill stepping 629 // to the next call that the embedder makes. 630 bool step_in_enabled_; 631 632 // Stores the way how LiveEdit has patched the stack. It is used when 633 // debugger returns control back to user script. 634 LiveEdit::FrameDropMode frame_drop_mode_; 635 }; 636 637 // Storage location for registers when handling debug break calls 638 ThreadLocal thread_local_; 639 640 Isolate* isolate_; 641 642 friend class Isolate; 643 friend class DebugScope; 644 friend class DisableBreak; 645 friend class LiveEdit; 646 friend class SuppressDebug; 647 648 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc 649 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc 650 651 DISALLOW_COPY_AND_ASSIGN(Debug); 652 }; 653 654 655 // This scope is used to load and enter the debug context and create a new 656 // break state. Leaving the scope will restore the previous state. 657 // On failure to load, FailedToEnter returns true. 658 class DebugScope BASE_EMBEDDED { 659 public: 660 explicit DebugScope(Debug* debug); 661 ~DebugScope(); 662 663 // Check whether loading was successful. 664 inline bool failed() { return failed_; } 665 666 // Get the active context from before entering the debugger. 667 inline Handle<Context> GetContext() { return save_.context(); } 668 669 private: 670 Isolate* isolate() { return debug_->isolate_; } 671 672 Debug* debug_; 673 DebugScope* prev_; // Previous scope if entered recursively. 674 StackFrame::Id break_frame_id_; // Previous break frame id. 675 int break_id_; // Previous break id. 676 bool failed_; // Did the debug context fail to load? 677 SaveContext save_; // Saves previous context. 678 PostponeInterruptsScope no_termination_exceptons_; 679 }; 680 681 682 // Stack allocated class for disabling break. 683 class DisableBreak BASE_EMBEDDED { 684 public: 685 explicit DisableBreak(Debug* debug, bool disable_break) 686 : debug_(debug), 687 previous_break_disabled_(debug->break_disabled_), 688 previous_in_debug_event_listener_(debug->in_debug_event_listener_) { 689 debug_->break_disabled_ = disable_break; 690 debug_->in_debug_event_listener_ = disable_break; 691 } 692 ~DisableBreak() { 693 debug_->break_disabled_ = previous_break_disabled_; 694 debug_->in_debug_event_listener_ = previous_in_debug_event_listener_; 695 } 696 697 private: 698 Debug* debug_; 699 bool previous_break_disabled_; 700 bool previous_in_debug_event_listener_; 701 DISALLOW_COPY_AND_ASSIGN(DisableBreak); 702 }; 703 704 705 class SuppressDebug BASE_EMBEDDED { 706 public: 707 explicit SuppressDebug(Debug* debug) 708 : debug_(debug), old_state_(debug->is_suppressed_) { 709 debug_->is_suppressed_ = true; 710 } 711 ~SuppressDebug() { debug_->is_suppressed_ = old_state_; } 712 713 private: 714 Debug* debug_; 715 bool old_state_; 716 DISALLOW_COPY_AND_ASSIGN(SuppressDebug); 717 }; 718 719 720 // Code generator routines. 721 class DebugCodegen : public AllStatic { 722 public: 723 enum DebugBreakCallHelperMode { 724 SAVE_RESULT_REGISTER, 725 IGNORE_RESULT_REGISTER 726 }; 727 728 static void GenerateDebugBreakStub(MacroAssembler* masm, 729 DebugBreakCallHelperMode mode); 730 731 // FrameDropper is a code replacement for a JavaScript frame with possibly 732 // several frames above. 733 // There is no calling conventions here, because it never actually gets 734 // called, it only gets returned to. 735 static void GenerateFrameDropperLiveEdit(MacroAssembler* masm); 736 737 738 static void GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode); 739 740 static void PatchDebugBreakSlot(Isolate* isolate, Address pc, 741 Handle<Code> code); 742 static void ClearDebugBreakSlot(Isolate* isolate, Address pc); 743 }; 744 745 746 } // namespace internal 747 } // namespace v8 748 749 #endif // V8_DEBUG_DEBUG_H_ 750