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.
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/execution.h"
14 #include "src/factory.h"
15 #include "src/flags.h"
16 #include "src/frames-inl.h"
17 #include "src/hashmap.h"
18 #include "src/liveedit.h"
19 #include "src/string-stream.h"
20 #include "src/v8threads.h"
22 #include "include/v8-debug.h"
28 // Forward declarations.
32 // Step actions. NOTE: These values are in macros.py as well.
34 StepNone = -1, // Stepping not prepared.
35 StepOut = 0, // Step out of the current function.
36 StepNext = 1, // Step to the next statement in the current function.
37 StepIn = 2, // Step into new functions invoked or the next statement
38 // in the current function.
39 StepMin = 3, // Perform a minimum step in the current function.
40 StepInMin = 4, // Step into new functions invoked or perform a minimum step
41 // in the current function.
42 StepFrame = 5 // Step into a new frame or return to previous frame.
46 // Type of exception break. NOTE: These values are in macros.py as well.
47 enum ExceptionBreakType {
49 BreakUncaughtException = 1
53 // Type of exception break.
54 enum BreakLocatorType {
55 ALL_BREAK_LOCATIONS = 0,
56 SOURCE_BREAK_LOCATIONS = 1,
61 // The different types of breakpoint position alignments.
62 // Must match Debug.BreakPositionAlignment in debug-debugger.js
63 enum BreakPositionAlignment {
64 STATEMENT_ALIGNED = 0,
65 BREAK_POSITION_ALIGNED = 1
71 // Find the break point at the supplied address, or the closest one before
73 static BreakLocation FromAddress(Handle<DebugInfo> debug_info,
74 BreakLocatorType type, Address pc);
76 static void FromAddressSameStatement(Handle<DebugInfo> debug_info,
77 BreakLocatorType type, Address pc,
78 List<BreakLocation>* result_out);
80 static BreakLocation FromPosition(Handle<DebugInfo> debug_info,
81 BreakLocatorType type, int position,
82 BreakPositionAlignment alignment);
84 bool IsDebugBreak() const;
85 inline bool IsExit() const { return RelocInfo::IsJSReturn(rmode_); }
86 inline bool IsConstructCall() const {
87 return RelocInfo::IsConstructCall(rmode_);
89 inline bool IsCodeTarget() const { return RelocInfo::IsCodeTarget(rmode_); }
91 Handle<Code> CodeTarget() const;
92 Handle<Code> OriginalCodeTarget() const;
94 bool IsStepInLocation() const;
95 inline bool HasBreakPoint() const {
96 return debug_info_->HasBreakPoint(pc_offset_);
99 Handle<Object> BreakPointObjects() const;
101 void SetBreakPoint(Handle<Object> break_point_object);
102 void ClearBreakPoint(Handle<Object> break_point_object);
107 inline RelocInfo rinfo() const {
108 return RelocInfo(pc(), rmode(), data_, code());
111 inline RelocInfo original_rinfo() const {
112 return RelocInfo(original_pc(), original_rmode(), original_data_,
116 inline int position() const { return position_; }
117 inline int statement_position() const { return statement_position_; }
119 inline Address pc() const { return code()->entry() + pc_offset_; }
120 inline Address original_pc() const {
121 return original_code()->entry() + original_pc_offset_;
124 inline RelocInfo::Mode rmode() const { return rmode_; }
125 inline RelocInfo::Mode original_rmode() const { return original_rmode_; }
127 inline Code* code() const { return debug_info_->code(); }
128 inline Code* original_code() const { return debug_info_->original_code(); }
131 BreakLocation(Handle<DebugInfo> debug_info, RelocInfo* rinfo,
132 RelocInfo* original_rinfo, int position, int statement_position)
133 : debug_info_(debug_info),
134 pc_offset_(static_cast<int>(rinfo->pc() - debug_info->code()->entry())),
135 original_pc_offset_(static_cast<int>(
136 original_rinfo->pc() - debug_info->original_code()->entry())),
137 rmode_(rinfo->rmode()),
138 original_rmode_(original_rinfo->rmode()),
139 data_(rinfo->data()),
140 original_data_(original_rinfo->data()),
142 statement_position_(statement_position) {}
146 Iterator(Handle<DebugInfo> debug_info, BreakLocatorType type);
148 BreakLocation GetBreakLocation() {
149 return BreakLocation(debug_info_, rinfo(), original_rinfo(), position(),
150 statement_position());
153 inline bool Done() const { return RinfoDone(); }
156 void SkipTo(int count) {
157 while (count-- > 0) Next();
160 inline RelocInfo::Mode rmode() { return reloc_iterator_.rinfo()->rmode(); }
161 inline RelocInfo::Mode original_rmode() {
162 return reloc_iterator_.rinfo()->rmode();
165 inline RelocInfo* rinfo() { return reloc_iterator_.rinfo(); }
166 inline RelocInfo* original_rinfo() {
167 return reloc_iterator_original_.rinfo();
170 inline Address pc() { return rinfo()->pc(); }
171 inline Address original_pc() { return original_rinfo()->pc(); }
173 int break_index() const { return break_index_; }
175 inline int position() const { return position_; }
176 inline int statement_position() const { return statement_position_; }
179 bool RinfoDone() const;
182 Handle<DebugInfo> debug_info_;
183 BreakLocatorType type_;
184 RelocIterator reloc_iterator_;
185 RelocIterator reloc_iterator_original_;
188 int statement_position_;
190 DisallowHeapAllocation no_gc_;
192 DISALLOW_COPY_AND_ASSIGN(Iterator);
197 static int BreakIndexFromAddress(Handle<DebugInfo> debug_info,
198 BreakLocatorType type, Address pc);
200 void ClearDebugBreak();
201 void RestoreFromOriginal(int length_in_bytes);
203 void SetDebugBreak();
204 void SetDebugBreakAtReturn();
205 void SetDebugBreakAtSlot();
206 void SetDebugBreakAtIC();
208 inline bool IsDebuggerStatement() const {
209 return RelocInfo::IsDebuggerStatement(rmode_);
211 inline bool IsDebugBreakSlot() const {
212 return RelocInfo::IsDebugBreakSlot(rmode_);
215 Handle<DebugInfo> debug_info_;
217 int original_pc_offset_;
218 RelocInfo::Mode rmode_;
219 RelocInfo::Mode original_rmode_;
221 intptr_t original_data_;
223 int statement_position_;
227 // Cache of all script objects in the heap. When a script is added a weak handle
228 // to it is created and that weak handle is stored in the cache. The weak handle
229 // callback takes care of removing the script from the cache. The key used in
230 // the cache is the script id.
231 class ScriptCache : private HashMap {
233 explicit ScriptCache(Isolate* isolate);
234 virtual ~ScriptCache() { Clear(); }
236 // Add script to the cache.
237 void Add(Handle<Script> script);
239 // Return the scripts in the cache.
240 Handle<FixedArray> GetScripts();
243 // Calculate the hash value from the key (script id).
244 static uint32_t Hash(int key) {
245 return ComputeIntegerHash(key, v8::internal::kZeroHashSeed);
248 // Clear the cache releasing all the weak handles.
251 // Weak handle callback for scripts in the cache.
252 static void HandleWeakScript(
253 const v8::WeakCallbackData<v8::Value, void>& data);
259 // Linked list holding debug info objects. The debug info objects are kept as
260 // weak handles to avoid a debug info object to keep a function alive.
261 class DebugInfoListNode {
263 explicit DebugInfoListNode(DebugInfo* debug_info);
264 virtual ~DebugInfoListNode() { ClearInfo(); }
266 DebugInfoListNode* next() { return next_; }
267 void set_next(DebugInfoListNode* next) { next_ = next; }
268 Handle<DebugInfo> debug_info() { return Handle<DebugInfo>(debug_info_); }
273 // Global (weak) handle to the debug info object.
274 DebugInfo** debug_info_;
276 // Next pointer for linked list.
277 DebugInfoListNode* next_;
282 // Message delivered to the message handler callback. This is either a debugger
283 // event or the response to a command.
284 class MessageImpl: public v8::Debug::Message {
286 // Create a message object for a debug event.
287 static MessageImpl NewEvent(DebugEvent event,
289 Handle<JSObject> exec_state,
290 Handle<JSObject> event_data);
292 // Create a message object for the response to a debug command.
293 static MessageImpl NewResponse(DebugEvent event,
295 Handle<JSObject> exec_state,
296 Handle<JSObject> event_data,
297 Handle<String> response_json,
298 v8::Debug::ClientData* client_data);
300 // Implementation of interface v8::Debug::Message.
301 virtual bool IsEvent() const;
302 virtual bool IsResponse() const;
303 virtual DebugEvent GetEvent() const;
304 virtual bool WillStartRunning() const;
305 virtual v8::Handle<v8::Object> GetExecutionState() const;
306 virtual v8::Handle<v8::Object> GetEventData() const;
307 virtual v8::Handle<v8::String> GetJSON() const;
308 virtual v8::Handle<v8::Context> GetEventContext() const;
309 virtual v8::Debug::ClientData* GetClientData() const;
310 virtual v8::Isolate* GetIsolate() const;
313 MessageImpl(bool is_event,
316 Handle<JSObject> exec_state,
317 Handle<JSObject> event_data,
318 Handle<String> response_json,
319 v8::Debug::ClientData* client_data);
321 bool is_event_; // Does this message represent a debug event?
322 DebugEvent event_; // Debug event causing the break.
323 bool running_; // Will the VM start running after this event?
324 Handle<JSObject> exec_state_; // Current execution state.
325 Handle<JSObject> event_data_; // Data associated with the event.
326 Handle<String> response_json_; // Response JSON if message holds a response.
327 v8::Debug::ClientData* client_data_; // Client data passed with the request.
331 // Details of the debug event delivered to the debug event listener.
332 class EventDetailsImpl : public v8::Debug::EventDetails {
334 EventDetailsImpl(DebugEvent event,
335 Handle<JSObject> exec_state,
336 Handle<JSObject> event_data,
337 Handle<Object> callback_data,
338 v8::Debug::ClientData* client_data);
339 virtual DebugEvent GetEvent() const;
340 virtual v8::Handle<v8::Object> GetExecutionState() const;
341 virtual v8::Handle<v8::Object> GetEventData() const;
342 virtual v8::Handle<v8::Context> GetEventContext() const;
343 virtual v8::Handle<v8::Value> GetCallbackData() const;
344 virtual v8::Debug::ClientData* GetClientData() const;
346 DebugEvent event_; // Debug event causing the break.
347 Handle<JSObject> exec_state_; // Current execution state.
348 Handle<JSObject> event_data_; // Data associated with the event.
349 Handle<Object> callback_data_; // User data passed with the callback
350 // when it was registered.
351 v8::Debug::ClientData* client_data_; // Data passed to DebugBreakForCommand.
355 // Message send by user to v8 debugger or debugger output message.
356 // In addition to command text it may contain a pointer to some user data
357 // which are expected to be passed along with the command reponse to message
359 class CommandMessage {
361 static CommandMessage New(const Vector<uint16_t>& command,
362 v8::Debug::ClientData* data);
365 // Deletes user data and disposes of the text.
367 Vector<uint16_t> text() const { return text_; }
368 v8::Debug::ClientData* client_data() const { return client_data_; }
370 CommandMessage(const Vector<uint16_t>& text,
371 v8::Debug::ClientData* data);
373 Vector<uint16_t> text_;
374 v8::Debug::ClientData* client_data_;
378 // A Queue of CommandMessage objects. A thread-safe version is
379 // LockingCommandMessageQueue, based on this class.
380 class CommandMessageQueue BASE_EMBEDDED {
382 explicit CommandMessageQueue(int size);
383 ~CommandMessageQueue();
384 bool IsEmpty() const { return start_ == end_; }
385 CommandMessage Get();
386 void Put(const CommandMessage& message);
387 void Clear() { start_ = end_ = 0; } // Queue is empty after Clear().
389 // Doubles the size of the message queue, and copies the messages.
392 CommandMessage* messages_;
395 int size_; // The size of the queue buffer. Queue can hold size-1 messages.
399 // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage
400 // messages. The message data is not managed by LockingCommandMessageQueue.
401 // Pointers to the data are passed in and out. Implemented by adding a
402 // Mutex to CommandMessageQueue. Includes logging of all puts and gets.
403 class LockingCommandMessageQueue BASE_EMBEDDED {
405 LockingCommandMessageQueue(Logger* logger, int size);
406 bool IsEmpty() const;
407 CommandMessage Get();
408 void Put(const CommandMessage& message);
412 CommandMessageQueue queue_;
413 mutable base::Mutex mutex_;
414 DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue);
418 // This class contains the debugger support. The main purpose is to handle
419 // setting break points in the code.
421 // This class controls the debug info for all functions which currently have
422 // active breakpoints in them. This debug info is held in the heap root object
423 // debug_info which is a FixedArray. Each entry in this list is of class
427 // Debug event triggers.
428 void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
430 void OnThrow(Handle<Object> exception);
431 void OnPromiseReject(Handle<JSObject> promise, Handle<Object> value);
432 void OnCompileError(Handle<Script> script);
433 void OnBeforeCompile(Handle<Script> script);
434 void OnAfterCompile(Handle<Script> script);
435 void OnPromiseEvent(Handle<JSObject> data);
436 void OnAsyncTaskEvent(Handle<JSObject> data);
439 void SetEventListener(Handle<Object> callback, Handle<Object> data);
440 void SetMessageHandler(v8::Debug::MessageHandler handler);
441 void EnqueueCommandMessage(Vector<const uint16_t> command,
442 v8::Debug::ClientData* client_data = NULL);
443 // Enqueue a debugger command to the command queue for event listeners.
444 void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL);
445 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun,
446 Handle<Object> data);
447 Handle<Context> GetDebugContext();
448 void HandleDebugBreak();
449 void ProcessDebugMessages(bool debug_command_only);
453 void Break(Arguments args, JavaScriptFrame*);
454 void SetAfterBreakTarget(JavaScriptFrame* frame);
457 Handle<FixedArray> GetLoadedScripts();
459 // Break point handling.
460 bool SetBreakPoint(Handle<JSFunction> function,
461 Handle<Object> break_point_object,
462 int* source_position);
463 bool SetBreakPointForScript(Handle<Script> script,
464 Handle<Object> break_point_object,
465 int* source_position,
466 BreakPositionAlignment alignment);
467 void ClearBreakPoint(Handle<Object> break_point_object);
468 void ClearAllBreakPoints();
469 void FloodWithOneShot(Handle<JSFunction> function,
470 BreakLocatorType type = ALL_BREAK_LOCATIONS);
471 void FloodBoundFunctionWithOneShot(Handle<JSFunction> function);
472 void FloodDefaultConstructorWithOneShot(Handle<JSFunction> function);
473 void FloodWithOneShotGeneric(Handle<JSFunction> function,
474 Handle<Object> holder = Handle<Object>());
475 void FloodHandlerWithOneShot();
476 void ChangeBreakOnException(ExceptionBreakType type, bool enable);
477 bool IsBreakOnException(ExceptionBreakType type);
479 // Stepping handling.
480 void PrepareStep(StepAction step_action,
482 StackFrame::Id frame_id);
483 void ClearStepping();
485 bool IsStepping() { return thread_local_.step_count_ > 0; }
486 bool StepNextContinue(BreakLocation* location, JavaScriptFrame* frame);
487 bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
488 void HandleStepIn(Handle<Object> function_obj, Handle<Object> holder,
489 Address fp, bool is_constructor);
490 bool StepOutActive() { return thread_local_.step_out_fp_ != 0; }
492 // Purge all code objects that have no debug break slots.
493 void PrepareForBreakPoints();
495 // Returns whether the operation succeeded. Compilation can only be triggered
496 // if a valid closure is passed as the second argument, otherwise the shared
497 // function needs to be compiled already.
498 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared,
499 Handle<JSFunction> function);
500 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared);
501 static bool HasDebugInfo(Handle<SharedFunctionInfo> shared);
503 // This function is used in FunctionNameUsing* tests.
504 Handle<Object> FindSharedFunctionInfoInScript(Handle<Script> script,
507 // Returns true if the current stub call is patched to call the debugger.
508 static bool IsDebugBreak(Address addr);
510 static Handle<Object> GetSourceBreakLocations(
511 Handle<SharedFunctionInfo> shared,
512 BreakPositionAlignment position_aligment);
514 // Check whether a global object is the debug global object.
515 bool IsDebugGlobal(GlobalObject* global);
517 // Check whether this frame is just about to return.
518 bool IsBreakAtReturn(JavaScriptFrame* frame);
520 // Support for LiveEdit
521 void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id,
522 LiveEdit::FrameDropMode mode,
523 Object** restarter_frame_function_pointer);
525 // Passed to MakeWeak.
526 static void HandlePhantomDebugInfo(
527 const PhantomCallbackData<DebugInfoListNode>& data);
529 // Threading support.
530 char* ArchiveDebug(char* to);
531 char* RestoreDebug(char* from);
532 static int ArchiveSpacePerThread();
533 void FreeThreadResources() { }
535 // Record function from which eval was called.
536 static void RecordEvalCaller(Handle<Script> script);
538 bool CheckExecutionState(int id) {
539 return !debug_context().is_null() && break_id() != 0 && break_id() == id;
543 DebugScope* debugger_entry() {
544 return reinterpret_cast<DebugScope*>(
545 base::NoBarrier_Load(&thread_local_.current_debug_scope_));
547 inline Handle<Context> debug_context() { return debug_context_; }
548 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
549 bool live_edit_enabled() const {
550 return FLAG_enable_liveedit && live_edit_enabled_ ;
553 inline bool is_active() const { return is_active_; }
554 inline bool is_loaded() const { return !debug_context_.is_null(); }
555 inline bool has_break_points() const { return has_break_points_; }
556 inline bool in_debug_scope() const {
557 return !!base::NoBarrier_Load(&thread_local_.current_debug_scope_);
559 void set_disable_break(bool v) { break_disabled_ = v; }
561 StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; }
562 int break_id() { return thread_local_.break_id_; }
564 // Support for embedding into generated code.
565 Address is_active_address() {
566 return reinterpret_cast<Address>(&is_active_);
569 Address after_break_target_address() {
570 return reinterpret_cast<Address>(&after_break_target_);
573 Address restarter_frame_function_pointer_address() {
574 Object*** address = &thread_local_.restarter_frame_function_pointer_;
575 return reinterpret_cast<Address>(address);
578 Address step_in_fp_addr() {
579 return reinterpret_cast<Address>(&thread_local_.step_into_fp_);
582 StepAction last_step_action() { return thread_local_.last_step_action_; }
585 explicit Debug(Isolate* isolate);
589 void SetNextBreakId() {
590 thread_local_.break_id_ = ++thread_local_.break_count_;
593 // Check whether there are commands in the command queue.
594 inline bool has_commands() const { return !command_queue_.IsEmpty(); }
595 inline bool ignore_events() const { return is_suppressed_ || !is_active_; }
596 inline bool break_disabled() const {
597 return break_disabled_ || in_debug_event_listener_;
600 void OnException(Handle<Object> exception, Handle<Object> promise);
602 // Constructors for debug event objects.
603 MUST_USE_RESULT MaybeHandle<Object> MakeJSObject(
604 const char* constructor_name,
606 Handle<Object> argv[]);
607 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState();
608 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent(
609 Handle<Object> break_points_hit);
610 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent(
611 Handle<Object> exception,
613 Handle<Object> promise);
614 MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent(
615 Handle<Script> script, v8::DebugEvent type);
616 MUST_USE_RESULT MaybeHandle<Object> MakePromiseEvent(
617 Handle<JSObject> promise_event);
618 MUST_USE_RESULT MaybeHandle<Object> MakeAsyncTaskEvent(
619 Handle<JSObject> task_event);
621 // Mirror cache handling.
622 void ClearMirrorCache();
624 MaybeHandle<Object> PromiseHasUserDefinedRejectHandler(
625 Handle<JSObject> promise);
627 void CallEventCallback(v8::DebugEvent event,
628 Handle<Object> exec_state,
629 Handle<Object> event_data,
630 v8::Debug::ClientData* client_data);
631 void ProcessCompileEventInDebugScope(v8::DebugEvent event,
632 Handle<Script> script);
633 void ProcessDebugEvent(v8::DebugEvent event,
634 Handle<JSObject> event_data,
636 void NotifyMessageHandler(v8::DebugEvent event,
637 Handle<JSObject> exec_state,
638 Handle<JSObject> event_data,
640 void InvokeMessageHandler(MessageImpl message);
642 static bool CompileDebuggerScript(Isolate* isolate, int index);
644 void ActivateStepIn(StackFrame* frame);
646 void ActivateStepOut(StackFrame* frame);
647 void ClearStepNext();
648 void RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info);
649 void RemoveDebugInfo(DebugInfo** debug_info);
650 void RemoveDebugInfo(DebugInfoListNode* node);
651 void RemoveDebugInfo(DebugInfoListNode* prev, DebugInfoListNode* node);
652 Handle<Object> CheckBreakPoints(Handle<Object> break_point);
653 bool CheckBreakPoint(Handle<Object> break_point_object);
655 inline void AssertDebugContext() {
656 DCHECK(isolate_->context() == *debug_context());
657 DCHECK(in_debug_scope());
663 Handle<Context> debug_context_;
664 Handle<Object> event_listener_;
665 Handle<Object> event_listener_data_;
667 v8::Debug::MessageHandler message_handler_;
669 static const int kQueueInitialSize = 4;
670 base::Semaphore command_received_; // Signaled for each command received.
671 LockingCommandMessageQueue command_queue_;
672 LockingCommandMessageQueue event_command_queue_;
676 bool live_edit_enabled_;
677 bool has_break_points_;
678 bool break_disabled_;
679 bool in_debug_event_listener_;
680 bool break_on_exception_;
681 bool break_on_uncaught_exception_;
683 ScriptCache* script_cache_; // Cache of all scripts in the heap.
684 DebugInfoListNode* debug_info_list_; // List of active debug info objects.
686 // Storage location for jump when exiting debug break calls.
687 // Note that this address is not GC safe. It should be computed immediately
688 // before returning to the DebugBreakCallHelper.
689 Address after_break_target_;
694 // Top debugger entry.
695 base::AtomicWord current_debug_scope_;
697 // Counter for generating next break id.
703 // Frame id for the frame of the current break.
704 StackFrame::Id break_frame_id_;
706 // Step action for last step performed.
707 StepAction last_step_action_;
709 // Source statement position from last step next action.
710 int last_statement_position_;
712 // Number of steps left to perform before debug event.
715 // Frame pointer from last step next or step frame action.
718 // Number of queued steps left to perform before debug event.
719 int queued_step_count_;
721 // Frame pointer for frame from which step in was performed.
722 Address step_into_fp_;
724 // Frame pointer for the frame where debugger should be called when current
725 // step out action is completed.
726 Address step_out_fp_;
728 // Stores the way how LiveEdit has patched the stack. It is used when
729 // debugger returns control back to user script.
730 LiveEdit::FrameDropMode frame_drop_mode_;
732 // When restarter frame is on stack, stores the address
733 // of the pointer to function being restarted. Otherwise (most of the time)
734 // stores NULL. This pointer is used with 'step in' implementation.
735 Object** restarter_frame_function_pointer_;
738 // Storage location for registers when handling debug break calls
739 ThreadLocal thread_local_;
743 friend class Isolate;
744 friend class DebugScope;
745 friend class DisableBreak;
746 friend class LiveEdit;
747 friend class SuppressDebug;
749 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc
750 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc
752 DISALLOW_COPY_AND_ASSIGN(Debug);
756 DECLARE_RUNTIME_FUNCTION(Debug_Break);
759 // This scope is used to load and enter the debug context and create a new
760 // break state. Leaving the scope will restore the previous state.
761 // On failure to load, FailedToEnter returns true.
762 class DebugScope BASE_EMBEDDED {
764 explicit DebugScope(Debug* debug);
767 // Check whether loading was successful.
768 inline bool failed() { return failed_; }
770 // Get the active context from before entering the debugger.
771 inline Handle<Context> GetContext() { return save_.context(); }
774 Isolate* isolate() { return debug_->isolate_; }
777 DebugScope* prev_; // Previous scope if entered recursively.
778 StackFrame::Id break_frame_id_; // Previous break frame id.
779 int break_id_; // Previous break id.
780 bool failed_; // Did the debug context fail to load?
781 SaveContext save_; // Saves previous context.
782 PostponeInterruptsScope no_termination_exceptons_;
786 // Stack allocated class for disabling break.
787 class DisableBreak BASE_EMBEDDED {
789 explicit DisableBreak(Debug* debug, bool disable_break)
791 previous_break_disabled_(debug->break_disabled_),
792 previous_in_debug_event_listener_(debug->in_debug_event_listener_) {
793 debug_->break_disabled_ = disable_break;
794 debug_->in_debug_event_listener_ = disable_break;
797 debug_->break_disabled_ = previous_break_disabled_;
798 debug_->in_debug_event_listener_ = previous_in_debug_event_listener_;
803 bool previous_break_disabled_;
804 bool previous_in_debug_event_listener_;
805 DISALLOW_COPY_AND_ASSIGN(DisableBreak);
809 class SuppressDebug BASE_EMBEDDED {
811 explicit SuppressDebug(Debug* debug)
812 : debug_(debug), old_state_(debug->is_suppressed_) {
813 debug_->is_suppressed_ = true;
815 ~SuppressDebug() { debug_->is_suppressed_ = old_state_; }
820 DISALLOW_COPY_AND_ASSIGN(SuppressDebug);
824 // Code generator routines.
825 class DebugCodegen : public AllStatic {
827 static void GenerateSlot(MacroAssembler* masm);
828 static void GenerateCallICStubDebugBreak(MacroAssembler* masm);
829 static void GenerateLoadICDebugBreak(MacroAssembler* masm);
830 static void GenerateStoreICDebugBreak(MacroAssembler* masm);
831 static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm);
832 static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm);
833 static void GenerateCompareNilICDebugBreak(MacroAssembler* masm);
834 static void GenerateReturnDebugBreak(MacroAssembler* masm);
835 static void GenerateCallFunctionStubDebugBreak(MacroAssembler* masm);
836 static void GenerateCallConstructStubDebugBreak(MacroAssembler* masm);
837 static void GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm);
838 static void GenerateSlotDebugBreak(MacroAssembler* masm);
839 static void GeneratePlainReturnLiveEdit(MacroAssembler* masm);
841 // FrameDropper is a code replacement for a JavaScript frame with possibly
842 // several frames above.
843 // There is no calling conventions here, because it never actually gets
844 // called, it only gets returned to.
845 static void GenerateFrameDropperLiveEdit(MacroAssembler* masm);
849 } } // namespace v8::internal
851 #endif // V8_DEBUG_H_