0ec9024436b9a5086320da709ef2b17557c9970e
[platform/upstream/nodejs.git] / deps / v8 / src / debug.h
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_H_
6 #define V8_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/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"
21
22 #include "include/v8-debug.h"
23
24 namespace v8 {
25 namespace internal {
26
27
28 // Forward declarations.
29 class DebugScope;
30
31
32 // Step actions. NOTE: These values are in macros.py as well.
33 enum StepAction {
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.
43 };
44
45
46 // Type of exception break. NOTE: These values are in macros.py as well.
47 enum ExceptionBreakType {
48   BreakException = 0,
49   BreakUncaughtException = 1
50 };
51
52
53 // Type of exception break.
54 enum BreakLocatorType {
55   ALL_BREAK_LOCATIONS = 0,
56   SOURCE_BREAK_LOCATIONS = 1,
57   CALLS_AND_RETURNS = 2
58 };
59
60
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
66 };
67
68
69 // Class for iterating through the break points in a function and changing
70 // them.
71 class BreakLocationIterator {
72  public:
73   explicit BreakLocationIterator(Handle<DebugInfo> debug_info,
74                                  BreakLocatorType type);
75   virtual ~BreakLocationIterator();
76
77   void Next();
78   void Next(int count);
79   void FindBreakLocationFromAddress(Address pc);
80   void FindBreakLocationFromPosition(int position,
81       BreakPositionAlignment alignment);
82   void Reset();
83   bool Done() const;
84   void SetBreakPoint(Handle<Object> break_point_object);
85   void ClearBreakPoint(Handle<Object> break_point_object);
86   void SetOneShot();
87   void ClearOneShot();
88   bool IsStepInLocation(Isolate* isolate);
89   void PrepareStepIn(Isolate* isolate);
90   bool IsExit() const;
91   bool HasBreakPoint();
92   bool IsDebugBreak();
93   Object* BreakPointObjects();
94   void ClearAllDebugBreak();
95
96
97   inline int code_position() {
98     return static_cast<int>(pc() - debug_info_->code()->entry());
99   }
100   inline int break_point() { return break_point_; }
101   inline int position() { return position_; }
102   inline int statement_position() { return statement_position_; }
103   inline Address pc() { return reloc_iterator_->rinfo()->pc(); }
104   inline Code* code() { return debug_info_->code(); }
105   inline RelocInfo* rinfo() { return reloc_iterator_->rinfo(); }
106   inline RelocInfo::Mode rmode() const {
107     return reloc_iterator_->rinfo()->rmode();
108   }
109   inline RelocInfo* original_rinfo() {
110     return reloc_iterator_original_->rinfo();
111   }
112   inline RelocInfo::Mode original_rmode() const {
113     return reloc_iterator_original_->rinfo()->rmode();
114   }
115
116   bool IsDebuggerStatement();
117
118  protected:
119   bool RinfoDone() const;
120   void RinfoNext();
121
122   BreakLocatorType type_;
123   int break_point_;
124   int position_;
125   int statement_position_;
126   Handle<DebugInfo> debug_info_;
127   RelocIterator* reloc_iterator_;
128   RelocIterator* reloc_iterator_original_;
129
130  private:
131   void SetDebugBreak();
132   void ClearDebugBreak();
133
134   void SetDebugBreakAtIC();
135   void ClearDebugBreakAtIC();
136
137   bool IsDebugBreakAtReturn();
138   void SetDebugBreakAtReturn();
139   void ClearDebugBreakAtReturn();
140
141   bool IsDebugBreakSlot();
142   bool IsDebugBreakAtSlot();
143   void SetDebugBreakAtSlot();
144   void ClearDebugBreakAtSlot();
145
146   DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator);
147 };
148
149
150 // Cache of all script objects in the heap. When a script is added a weak handle
151 // to it is created and that weak handle is stored in the cache. The weak handle
152 // callback takes care of removing the script from the cache. The key used in
153 // the cache is the script id.
154 class ScriptCache : private HashMap {
155  public:
156   explicit ScriptCache(Isolate* isolate);
157   virtual ~ScriptCache() { Clear(); }
158
159   // Add script to the cache.
160   void Add(Handle<Script> script);
161
162   // Return the scripts in the cache.
163   Handle<FixedArray> GetScripts();
164
165  private:
166   // Calculate the hash value from the key (script id).
167   static uint32_t Hash(int key) {
168     return ComputeIntegerHash(key, v8::internal::kZeroHashSeed);
169   }
170
171   // Clear the cache releasing all the weak handles.
172   void Clear();
173
174   // Weak handle callback for scripts in the cache.
175   static void HandleWeakScript(
176       const v8::WeakCallbackData<v8::Value, void>& data);
177
178   Isolate* isolate_;
179 };
180
181
182 // Linked list holding debug info objects. The debug info objects are kept as
183 // weak handles to avoid a debug info object to keep a function alive.
184 class DebugInfoListNode {
185  public:
186   explicit DebugInfoListNode(DebugInfo* debug_info);
187   virtual ~DebugInfoListNode();
188
189   DebugInfoListNode* next() { return next_; }
190   void set_next(DebugInfoListNode* next) { next_ = next; }
191   Handle<DebugInfo> debug_info() { return debug_info_; }
192
193  private:
194   // Global (weak) handle to the debug info object.
195   Handle<DebugInfo> debug_info_;
196
197   // Next pointer for linked list.
198   DebugInfoListNode* next_;
199 };
200
201
202
203 // Message delivered to the message handler callback. This is either a debugger
204 // event or the response to a command.
205 class MessageImpl: public v8::Debug::Message {
206  public:
207   // Create a message object for a debug event.
208   static MessageImpl NewEvent(DebugEvent event,
209                               bool running,
210                               Handle<JSObject> exec_state,
211                               Handle<JSObject> event_data);
212
213   // Create a message object for the response to a debug command.
214   static MessageImpl NewResponse(DebugEvent event,
215                                  bool running,
216                                  Handle<JSObject> exec_state,
217                                  Handle<JSObject> event_data,
218                                  Handle<String> response_json,
219                                  v8::Debug::ClientData* client_data);
220
221   // Implementation of interface v8::Debug::Message.
222   virtual bool IsEvent() const;
223   virtual bool IsResponse() const;
224   virtual DebugEvent GetEvent() const;
225   virtual bool WillStartRunning() const;
226   virtual v8::Handle<v8::Object> GetExecutionState() const;
227   virtual v8::Handle<v8::Object> GetEventData() const;
228   virtual v8::Handle<v8::String> GetJSON() const;
229   virtual v8::Handle<v8::Context> GetEventContext() const;
230   virtual v8::Debug::ClientData* GetClientData() const;
231   virtual v8::Isolate* GetIsolate() const;
232
233  private:
234   MessageImpl(bool is_event,
235               DebugEvent event,
236               bool running,
237               Handle<JSObject> exec_state,
238               Handle<JSObject> event_data,
239               Handle<String> response_json,
240               v8::Debug::ClientData* client_data);
241
242   bool is_event_;  // Does this message represent a debug event?
243   DebugEvent event_;  // Debug event causing the break.
244   bool running_;  // Will the VM start running after this event?
245   Handle<JSObject> exec_state_;  // Current execution state.
246   Handle<JSObject> event_data_;  // Data associated with the event.
247   Handle<String> response_json_;  // Response JSON if message holds a response.
248   v8::Debug::ClientData* client_data_;  // Client data passed with the request.
249 };
250
251
252 // Details of the debug event delivered to the debug event listener.
253 class EventDetailsImpl : public v8::Debug::EventDetails {
254  public:
255   EventDetailsImpl(DebugEvent event,
256                    Handle<JSObject> exec_state,
257                    Handle<JSObject> event_data,
258                    Handle<Object> callback_data,
259                    v8::Debug::ClientData* client_data);
260   virtual DebugEvent GetEvent() const;
261   virtual v8::Handle<v8::Object> GetExecutionState() const;
262   virtual v8::Handle<v8::Object> GetEventData() const;
263   virtual v8::Handle<v8::Context> GetEventContext() const;
264   virtual v8::Handle<v8::Value> GetCallbackData() const;
265   virtual v8::Debug::ClientData* GetClientData() const;
266  private:
267   DebugEvent event_;  // Debug event causing the break.
268   Handle<JSObject> exec_state_;         // Current execution state.
269   Handle<JSObject> event_data_;         // Data associated with the event.
270   Handle<Object> callback_data_;        // User data passed with the callback
271                                         // when it was registered.
272   v8::Debug::ClientData* client_data_;  // Data passed to DebugBreakForCommand.
273 };
274
275
276 // Message send by user to v8 debugger or debugger output message.
277 // In addition to command text it may contain a pointer to some user data
278 // which are expected to be passed along with the command reponse to message
279 // handler.
280 class CommandMessage {
281  public:
282   static CommandMessage New(const Vector<uint16_t>& command,
283                             v8::Debug::ClientData* data);
284   CommandMessage();
285
286   // Deletes user data and disposes of the text.
287   void Dispose();
288   Vector<uint16_t> text() const { return text_; }
289   v8::Debug::ClientData* client_data() const { return client_data_; }
290  private:
291   CommandMessage(const Vector<uint16_t>& text,
292                  v8::Debug::ClientData* data);
293
294   Vector<uint16_t> text_;
295   v8::Debug::ClientData* client_data_;
296 };
297
298
299 // A Queue of CommandMessage objects.  A thread-safe version is
300 // LockingCommandMessageQueue, based on this class.
301 class CommandMessageQueue BASE_EMBEDDED {
302  public:
303   explicit CommandMessageQueue(int size);
304   ~CommandMessageQueue();
305   bool IsEmpty() const { return start_ == end_; }
306   CommandMessage Get();
307   void Put(const CommandMessage& message);
308   void Clear() { start_ = end_ = 0; }  // Queue is empty after Clear().
309  private:
310   // Doubles the size of the message queue, and copies the messages.
311   void Expand();
312
313   CommandMessage* messages_;
314   int start_;
315   int end_;
316   int size_;  // The size of the queue buffer.  Queue can hold size-1 messages.
317 };
318
319
320 // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage
321 // messages.  The message data is not managed by LockingCommandMessageQueue.
322 // Pointers to the data are passed in and out. Implemented by adding a
323 // Mutex to CommandMessageQueue.  Includes logging of all puts and gets.
324 class LockingCommandMessageQueue BASE_EMBEDDED {
325  public:
326   LockingCommandMessageQueue(Logger* logger, int size);
327   bool IsEmpty() const;
328   CommandMessage Get();
329   void Put(const CommandMessage& message);
330   void Clear();
331  private:
332   Logger* logger_;
333   CommandMessageQueue queue_;
334   mutable base::Mutex mutex_;
335   DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue);
336 };
337
338
339 // This class contains the debugger support. The main purpose is to handle
340 // setting break points in the code.
341 //
342 // This class controls the debug info for all functions which currently have
343 // active breakpoints in them. This debug info is held in the heap root object
344 // debug_info which is a FixedArray. Each entry in this list is of class
345 // DebugInfo.
346 class Debug {
347  public:
348   // Debug event triggers.
349   void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
350
351   void OnThrow(Handle<Object> exception, bool uncaught);
352   void OnPromiseReject(Handle<JSObject> promise, Handle<Object> value);
353   void OnCompileError(Handle<Script> script);
354   void OnBeforeCompile(Handle<Script> script);
355   void OnAfterCompile(Handle<Script> script);
356   void OnPromiseEvent(Handle<JSObject> data);
357   void OnAsyncTaskEvent(Handle<JSObject> data);
358
359   // API facing.
360   void SetEventListener(Handle<Object> callback, Handle<Object> data);
361   void SetMessageHandler(v8::Debug::MessageHandler handler);
362   void EnqueueCommandMessage(Vector<const uint16_t> command,
363                              v8::Debug::ClientData* client_data = NULL);
364   // Enqueue a debugger command to the command queue for event listeners.
365   void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL);
366   MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun,
367                                            Handle<Object> data);
368   Handle<Context> GetDebugContext();
369   void HandleDebugBreak();
370   void ProcessDebugMessages(bool debug_command_only);
371
372   // Internal logic
373   bool Load();
374   void Break(Arguments args, JavaScriptFrame*);
375   void SetAfterBreakTarget(JavaScriptFrame* frame);
376
377   // Scripts handling.
378   Handle<FixedArray> GetLoadedScripts();
379
380   // Break point handling.
381   bool SetBreakPoint(Handle<JSFunction> function,
382                      Handle<Object> break_point_object,
383                      int* source_position);
384   bool SetBreakPointForScript(Handle<Script> script,
385                               Handle<Object> break_point_object,
386                               int* source_position,
387                               BreakPositionAlignment alignment);
388   void ClearBreakPoint(Handle<Object> break_point_object);
389   void ClearAllBreakPoints();
390   void FloodWithOneShot(Handle<JSFunction> function,
391                         BreakLocatorType type = ALL_BREAK_LOCATIONS);
392   void FloodBoundFunctionWithOneShot(Handle<JSFunction> function);
393   void FloodDefaultConstructorWithOneShot(Handle<JSFunction> function);
394   void FloodWithOneShotGeneric(Handle<JSFunction> function,
395                                Handle<Object> holder = Handle<Object>());
396   void FloodHandlerWithOneShot();
397   void ChangeBreakOnException(ExceptionBreakType type, bool enable);
398   bool IsBreakOnException(ExceptionBreakType type);
399
400   // Stepping handling.
401   void PrepareStep(StepAction step_action,
402                    int step_count,
403                    StackFrame::Id frame_id);
404   void ClearStepping();
405   void ClearStepOut();
406   bool IsStepping() { return thread_local_.step_count_ > 0; }
407   bool StepNextContinue(BreakLocationIterator* break_location_iterator,
408                         JavaScriptFrame* frame);
409   bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
410   void HandleStepIn(Handle<Object> function_obj, Handle<Object> holder,
411                     Address fp, bool is_constructor);
412   bool StepOutActive() { return thread_local_.step_out_fp_ != 0; }
413
414   // Purge all code objects that have no debug break slots.
415   void PrepareForBreakPoints();
416
417   // Returns whether the operation succeeded. Compilation can only be triggered
418   // if a valid closure is passed as the second argument, otherwise the shared
419   // function needs to be compiled already.
420   bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared,
421                        Handle<JSFunction> function);
422   static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared);
423   static bool HasDebugInfo(Handle<SharedFunctionInfo> shared);
424
425   // This function is used in FunctionNameUsing* tests.
426   Object* FindSharedFunctionInfoInScript(Handle<Script> script, int position);
427
428   // Returns true if the current stub call is patched to call the debugger.
429   static bool IsDebugBreak(Address addr);
430   // Returns true if the current return statement has been patched to be
431   // a debugger breakpoint.
432   static bool IsDebugBreakAtReturn(RelocInfo* rinfo);
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(GlobalObject* 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                              Object** restarter_frame_function_pointer);
448
449   // Passed to MakeWeak.
450   static void HandlePhantomDebugInfo(
451       const PhantomCallbackData<DebugInfoListNode>& data);
452
453   // Threading support.
454   char* ArchiveDebug(char* to);
455   char* RestoreDebug(char* from);
456   static int ArchiveSpacePerThread();
457   void FreeThreadResources() { }
458
459   // Record function from which eval was called.
460   static void RecordEvalCaller(Handle<Script> script);
461
462   bool CheckExecutionState(int id) {
463     return !debug_context().is_null() && break_id() != 0 && break_id() == id;
464   }
465
466   // Flags and states.
467   DebugScope* debugger_entry() {
468     return reinterpret_cast<DebugScope*>(
469         base::NoBarrier_Load(&thread_local_.current_debug_scope_));
470   }
471   inline Handle<Context> debug_context() { return debug_context_; }
472   void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; }
473   bool live_edit_enabled() const {
474     return FLAG_enable_liveedit && live_edit_enabled_ ;
475   }
476
477   inline bool is_active() const { return is_active_; }
478   inline bool is_loaded() const { return !debug_context_.is_null(); }
479   inline bool has_break_points() const { return has_break_points_; }
480   inline bool in_debug_scope() const {
481     return !!base::NoBarrier_Load(&thread_local_.current_debug_scope_);
482   }
483   void set_disable_break(bool v) { break_disabled_ = v; }
484
485   StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; }
486   int break_id() { return thread_local_.break_id_; }
487
488   // Support for embedding into generated code.
489   Address is_active_address() {
490     return reinterpret_cast<Address>(&is_active_);
491   }
492
493   Address after_break_target_address() {
494     return reinterpret_cast<Address>(&after_break_target_);
495   }
496
497   Address restarter_frame_function_pointer_address() {
498     Object*** address = &thread_local_.restarter_frame_function_pointer_;
499     return reinterpret_cast<Address>(address);
500   }
501
502   Address step_in_fp_addr() {
503     return reinterpret_cast<Address>(&thread_local_.step_into_fp_);
504   }
505
506   StepAction last_step_action() { return thread_local_.last_step_action_; }
507
508  private:
509   explicit Debug(Isolate* isolate);
510
511   void UpdateState();
512   void Unload();
513   void SetNextBreakId() {
514     thread_local_.break_id_ = ++thread_local_.break_count_;
515   }
516
517   // Check whether there are commands in the command queue.
518   inline bool has_commands() const { return !command_queue_.IsEmpty(); }
519   inline bool ignore_events() const { return is_suppressed_ || !is_active_; }
520   inline bool break_disabled() const {
521     return break_disabled_ || in_debug_event_listener_;
522   }
523
524   void OnException(Handle<Object> exception, bool uncaught,
525                    Handle<Object> promise);
526
527   // Constructors for debug event objects.
528   MUST_USE_RESULT MaybeHandle<Object> MakeJSObject(
529       const char* constructor_name,
530       int argc,
531       Handle<Object> argv[]);
532   MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState();
533   MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent(
534       Handle<Object> break_points_hit);
535   MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent(
536       Handle<Object> exception,
537       bool uncaught,
538       Handle<Object> promise);
539   MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent(
540       Handle<Script> script, v8::DebugEvent type);
541   MUST_USE_RESULT MaybeHandle<Object> MakePromiseEvent(
542       Handle<JSObject> promise_event);
543   MUST_USE_RESULT MaybeHandle<Object> MakeAsyncTaskEvent(
544       Handle<JSObject> task_event);
545
546   // Mirror cache handling.
547   void ClearMirrorCache();
548
549   MaybeHandle<Object> PromiseHasUserDefinedRejectHandler(
550       Handle<JSObject> promise);
551
552   void CallEventCallback(v8::DebugEvent event,
553                          Handle<Object> exec_state,
554                          Handle<Object> event_data,
555                          v8::Debug::ClientData* client_data);
556   void ProcessCompileEventInDebugScope(v8::DebugEvent event,
557                                        Handle<Script> script);
558   void ProcessDebugEvent(v8::DebugEvent event,
559                          Handle<JSObject> event_data,
560                          bool auto_continue);
561   void NotifyMessageHandler(v8::DebugEvent event,
562                             Handle<JSObject> exec_state,
563                             Handle<JSObject> event_data,
564                             bool auto_continue);
565   void InvokeMessageHandler(MessageImpl message);
566
567   static bool CompileDebuggerScript(Isolate* isolate, int index);
568   void ClearOneShot();
569   void ActivateStepIn(StackFrame* frame);
570   void ClearStepIn();
571   void ActivateStepOut(StackFrame* frame);
572   void ClearStepNext();
573   void RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info);
574   void RemoveDebugInfo(DebugInfo** debug_info);
575   void RemoveDebugInfo(DebugInfoListNode* node);
576   void RemoveDebugInfo(DebugInfoListNode* prev, DebugInfoListNode* node);
577   Handle<Object> CheckBreakPoints(Handle<Object> break_point);
578   bool CheckBreakPoint(Handle<Object> break_point_object);
579
580   inline void AssertDebugContext() {
581     DCHECK(isolate_->context() == *debug_context());
582     DCHECK(in_debug_scope());
583   }
584
585   void ThreadInit();
586
587   // Global handles.
588   Handle<Context> debug_context_;
589   Handle<Object> event_listener_;
590   Handle<Object> event_listener_data_;
591
592   v8::Debug::MessageHandler message_handler_;
593
594   static const int kQueueInitialSize = 4;
595   base::Semaphore command_received_;  // Signaled for each command received.
596   LockingCommandMessageQueue command_queue_;
597   LockingCommandMessageQueue event_command_queue_;
598
599   bool is_active_;
600   bool is_suppressed_;
601   bool live_edit_enabled_;
602   bool has_break_points_;
603   bool break_disabled_;
604   bool in_debug_event_listener_;
605   bool break_on_exception_;
606   bool break_on_uncaught_exception_;
607
608   ScriptCache* script_cache_;  // Cache of all scripts in the heap.
609   DebugInfoListNode* debug_info_list_;  // List of active debug info objects.
610
611   // Storage location for jump when exiting debug break calls.
612   // Note that this address is not GC safe.  It should be computed immediately
613   // before returning to the DebugBreakCallHelper.
614   Address after_break_target_;
615
616   // Per-thread data.
617   class ThreadLocal {
618    public:
619     // Top debugger entry.
620     base::AtomicWord current_debug_scope_;
621
622     // Counter for generating next break id.
623     int break_count_;
624
625     // Current break id.
626     int break_id_;
627
628     // Frame id for the frame of the current break.
629     StackFrame::Id break_frame_id_;
630
631     // Step action for last step performed.
632     StepAction last_step_action_;
633
634     // Source statement position from last step next action.
635     int last_statement_position_;
636
637     // Number of steps left to perform before debug event.
638     int step_count_;
639
640     // Frame pointer from last step next or step frame action.
641     Address last_fp_;
642
643     // Number of queued steps left to perform before debug event.
644     int queued_step_count_;
645
646     // Frame pointer for frame from which step in was performed.
647     Address step_into_fp_;
648
649     // Frame pointer for the frame where debugger should be called when current
650     // step out action is completed.
651     Address step_out_fp_;
652
653     // Stores the way how LiveEdit has patched the stack. It is used when
654     // debugger returns control back to user script.
655     LiveEdit::FrameDropMode frame_drop_mode_;
656
657     // When restarter frame is on stack, stores the address
658     // of the pointer to function being restarted. Otherwise (most of the time)
659     // stores NULL. This pointer is used with 'step in' implementation.
660     Object** restarter_frame_function_pointer_;
661   };
662
663   // Storage location for registers when handling debug break calls
664   ThreadLocal thread_local_;
665
666   Isolate* isolate_;
667
668   friend class Isolate;
669   friend class DebugScope;
670   friend class DisableBreak;
671   friend class LiveEdit;
672   friend class SuppressDebug;
673
674   friend Handle<FixedArray> GetDebuggedFunctions();  // In test-debug.cc
675   friend void CheckDebuggerUnloaded(bool check_functions);  // In test-debug.cc
676
677   DISALLOW_COPY_AND_ASSIGN(Debug);
678 };
679
680
681 DECLARE_RUNTIME_FUNCTION(Debug_Break);
682
683
684 // This scope is used to load and enter the debug context and create a new
685 // break state.  Leaving the scope will restore the previous state.
686 // On failure to load, FailedToEnter returns true.
687 class DebugScope BASE_EMBEDDED {
688  public:
689   explicit DebugScope(Debug* debug);
690   ~DebugScope();
691
692   // Check whether loading was successful.
693   inline bool failed() { return failed_; }
694
695   // Get the active context from before entering the debugger.
696   inline Handle<Context> GetContext() { return save_.context(); }
697
698  private:
699   Isolate* isolate() { return debug_->isolate_; }
700
701   Debug* debug_;
702   DebugScope* prev_;               // Previous scope if entered recursively.
703   StackFrame::Id break_frame_id_;  // Previous break frame id.
704   int break_id_;                   // Previous break id.
705   bool failed_;                    // Did the debug context fail to load?
706   SaveContext save_;               // Saves previous context.
707   PostponeInterruptsScope no_termination_exceptons_;
708 };
709
710
711 // Stack allocated class for disabling break.
712 class DisableBreak BASE_EMBEDDED {
713  public:
714   explicit DisableBreak(Debug* debug, bool disable_break)
715       : debug_(debug),
716         previous_break_disabled_(debug->break_disabled_),
717         previous_in_debug_event_listener_(debug->in_debug_event_listener_) {
718     debug_->break_disabled_ = disable_break;
719     debug_->in_debug_event_listener_ = disable_break;
720   }
721   ~DisableBreak() {
722     debug_->break_disabled_ = previous_break_disabled_;
723     debug_->in_debug_event_listener_ = previous_in_debug_event_listener_;
724   }
725
726  private:
727   Debug* debug_;
728   bool previous_break_disabled_;
729   bool previous_in_debug_event_listener_;
730   DISALLOW_COPY_AND_ASSIGN(DisableBreak);
731 };
732
733
734 class SuppressDebug BASE_EMBEDDED {
735  public:
736   explicit SuppressDebug(Debug* debug)
737       : debug_(debug), old_state_(debug->is_suppressed_) {
738     debug_->is_suppressed_ = true;
739   }
740   ~SuppressDebug() { debug_->is_suppressed_ = old_state_; }
741
742  private:
743   Debug* debug_;
744   bool old_state_;
745   DISALLOW_COPY_AND_ASSIGN(SuppressDebug);
746 };
747
748
749 // Code generator routines.
750 class DebugCodegen : public AllStatic {
751  public:
752   static void GenerateSlot(MacroAssembler* masm);
753   static void GenerateCallICStubDebugBreak(MacroAssembler* masm);
754   static void GenerateLoadICDebugBreak(MacroAssembler* masm);
755   static void GenerateStoreICDebugBreak(MacroAssembler* masm);
756   static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm);
757   static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm);
758   static void GenerateCompareNilICDebugBreak(MacroAssembler* masm);
759   static void GenerateReturnDebugBreak(MacroAssembler* masm);
760   static void GenerateCallFunctionStubDebugBreak(MacroAssembler* masm);
761   static void GenerateCallConstructStubDebugBreak(MacroAssembler* masm);
762   static void GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm);
763   static void GenerateSlotDebugBreak(MacroAssembler* masm);
764   static void GeneratePlainReturnLiveEdit(MacroAssembler* masm);
765
766   // FrameDropper is a code replacement for a JavaScript frame with possibly
767   // several frames above.
768   // There is no calling conventions here, because it never actually gets
769   // called, it only gets returned to.
770   static void GenerateFrameDropperLiveEdit(MacroAssembler* masm);
771 };
772
773
774 } }  // namespace v8::internal
775
776 #endif  // V8_DEBUG_H_