| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_DEBUG_H_ | 5 #ifndef V8_DEBUG_H_ |
| 6 #define V8_DEBUG_H_ | 6 #define V8_DEBUG_H_ |
| 7 | 7 |
| 8 #include "allocation.h" | 8 #include "allocation.h" |
| 9 #include "arguments.h" | 9 #include "arguments.h" |
| 10 #include "assembler.h" | 10 #include "assembler.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); | 143 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 | 146 |
| 147 // Cache of all script objects in the heap. When a script is added a weak handle | 147 // Cache of all script objects in the heap. When a script is added a weak handle |
| 148 // to it is created and that weak handle is stored in the cache. The weak handle | 148 // to it is created and that weak handle is stored in the cache. The weak handle |
| 149 // callback takes care of removing the script from the cache. The key used in | 149 // callback takes care of removing the script from the cache. The key used in |
| 150 // the cache is the script id. | 150 // the cache is the script id. |
| 151 class ScriptCache : private HashMap { | 151 class ScriptCache : private HashMap { |
| 152 public: | 152 public: |
| 153 explicit ScriptCache(Isolate* isolate) | 153 explicit ScriptCache(Isolate* isolate); |
| 154 : HashMap(HashMap::PointersMatch), | |
| 155 isolate_(isolate), | |
| 156 collected_scripts_(10) {} | |
| 157 virtual ~ScriptCache() { Clear(); } | 154 virtual ~ScriptCache() { Clear(); } |
| 158 | 155 |
| 159 // Add script to the cache. | 156 // Add script to the cache. |
| 160 void Add(Handle<Script> script); | 157 void Add(Handle<Script> script); |
| 161 | 158 |
| 162 // Return the scripts in the cache. | 159 // Return the scripts in the cache. |
| 163 Handle<FixedArray> GetScripts(); | 160 Handle<FixedArray> GetScripts(); |
| 164 | 161 |
| 165 // Generate debugger events for collected scripts. | 162 // Generate debugger events for collected scripts. |
| 166 void ProcessCollectedScripts(); | 163 void ProcessCollectedScripts(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 277 |
| 281 // Message send by user to v8 debugger or debugger output message. | 278 // Message send by user to v8 debugger or debugger output message. |
| 282 // In addition to command text it may contain a pointer to some user data | 279 // In addition to command text it may contain a pointer to some user data |
| 283 // which are expected to be passed along with the command reponse to message | 280 // which are expected to be passed along with the command reponse to message |
| 284 // handler. | 281 // handler. |
| 285 class CommandMessage { | 282 class CommandMessage { |
| 286 public: | 283 public: |
| 287 static CommandMessage New(const Vector<uint16_t>& command, | 284 static CommandMessage New(const Vector<uint16_t>& command, |
| 288 v8::Debug::ClientData* data); | 285 v8::Debug::ClientData* data); |
| 289 CommandMessage(); | 286 CommandMessage(); |
| 290 ~CommandMessage(); | |
| 291 | 287 |
| 292 // Deletes user data and disposes of the text. | 288 // Deletes user data and disposes of the text. |
| 293 void Dispose(); | 289 void Dispose(); |
| 294 Vector<uint16_t> text() const { return text_; } | 290 Vector<uint16_t> text() const { return text_; } |
| 295 v8::Debug::ClientData* client_data() const { return client_data_; } | 291 v8::Debug::ClientData* client_data() const { return client_data_; } |
| 296 private: | 292 private: |
| 297 CommandMessage(const Vector<uint16_t>& text, | 293 CommandMessage(const Vector<uint16_t>& text, |
| 298 v8::Debug::ClientData* data); | 294 v8::Debug::ClientData* data); |
| 299 | 295 |
| 300 Vector<uint16_t> text_; | 296 Vector<uint16_t> text_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void Put(const CommandMessage& message); | 331 void Put(const CommandMessage& message); |
| 336 void Clear(); | 332 void Clear(); |
| 337 private: | 333 private: |
| 338 Logger* logger_; | 334 Logger* logger_; |
| 339 CommandMessageQueue queue_; | 335 CommandMessageQueue queue_; |
| 340 mutable Mutex mutex_; | 336 mutable Mutex mutex_; |
| 341 DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue); | 337 DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue); |
| 342 }; | 338 }; |
| 343 | 339 |
| 344 | 340 |
| 341 class PromiseOnStack { |
| 342 public: |
| 343 PromiseOnStack(Isolate* isolate, |
| 344 PromiseOnStack* prev, |
| 345 Handle<JSFunction> getter); |
| 346 ~PromiseOnStack(); |
| 347 StackHandler* handler() { return handler_; } |
| 348 Handle<JSFunction> getter() { return getter_; } |
| 349 PromiseOnStack* prev() { return prev_; } |
| 350 private: |
| 351 Isolate* isolate_; |
| 352 StackHandler* handler_; |
| 353 Handle<JSFunction> getter_; |
| 354 PromiseOnStack* prev_; |
| 355 }; |
| 356 |
| 357 |
| 345 // This class contains the debugger support. The main purpose is to handle | 358 // This class contains the debugger support. The main purpose is to handle |
| 346 // setting break points in the code. | 359 // setting break points in the code. |
| 347 // | 360 // |
| 348 // This class controls the debug info for all functions which currently have | 361 // This class controls the debug info for all functions which currently have |
| 349 // active breakpoints in them. This debug info is held in the heap root object | 362 // active breakpoints in them. This debug info is held in the heap root object |
| 350 // debug_info which is a FixedArray. Each entry in this list is of class | 363 // debug_info which is a FixedArray. Each entry in this list is of class |
| 351 // DebugInfo. | 364 // DebugInfo. |
| 352 class Debug { | 365 class Debug { |
| 353 public: | 366 public: |
| 354 enum AfterCompileFlags { | 367 enum AfterCompileFlags { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 367 // API facing. | 380 // API facing. |
| 368 void SetEventListener(Handle<Object> callback, Handle<Object> data); | 381 void SetEventListener(Handle<Object> callback, Handle<Object> data); |
| 369 void SetMessageHandler(v8::Debug::MessageHandler handler); | 382 void SetMessageHandler(v8::Debug::MessageHandler handler); |
| 370 void EnqueueCommandMessage(Vector<const uint16_t> command, | 383 void EnqueueCommandMessage(Vector<const uint16_t> command, |
| 371 v8::Debug::ClientData* client_data = NULL); | 384 v8::Debug::ClientData* client_data = NULL); |
| 372 // Enqueue a debugger command to the command queue for event listeners. | 385 // Enqueue a debugger command to the command queue for event listeners. |
| 373 void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL); | 386 void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL); |
| 374 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun, | 387 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun, |
| 375 Handle<Object> data); | 388 Handle<Object> data); |
| 376 Handle<Context> GetDebugContext(); | 389 Handle<Context> GetDebugContext(); |
| 377 void DebugBreakHelper(); | 390 void HandleDebugBreak(); |
| 378 void ProcessDebugMessages(bool debug_command_only); | 391 void ProcessDebugMessages(bool debug_command_only); |
| 379 | 392 |
| 380 // Flags and states. | 393 // Internal logic |
| 381 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } | |
| 382 bool live_edit_enabled() const { | |
| 383 return FLAG_enable_liveedit && live_edit_enabled_ ; | |
| 384 } | |
| 385 | |
| 386 inline bool is_active() const { return is_active_; } | |
| 387 inline bool is_loaded() const { return !debug_context_.is_null(); } | |
| 388 inline bool has_break_points() const { return has_break_points_; } | |
| 389 inline bool is_entered() const { | |
| 390 return thread_local_.debugger_entry_ != NULL; | |
| 391 } | |
| 392 | |
| 393 void set_disable_break(bool v) { break_disabled_ = v; } | |
| 394 | |
| 395 bool Load(); | 394 bool Load(); |
| 396 | |
| 397 void Break(Arguments args, JavaScriptFrame*); | 395 void Break(Arguments args, JavaScriptFrame*); |
| 398 void SetAfterBreakTarget(JavaScriptFrame* frame); | 396 void SetAfterBreakTarget(JavaScriptFrame* frame); |
| 399 | 397 |
| 398 // Scripts handling. |
| 399 Handle<FixedArray> GetLoadedScripts(); |
| 400 |
| 401 // Break point handling. |
| 400 bool SetBreakPoint(Handle<JSFunction> function, | 402 bool SetBreakPoint(Handle<JSFunction> function, |
| 401 Handle<Object> break_point_object, | 403 Handle<Object> break_point_object, |
| 402 int* source_position); | 404 int* source_position); |
| 403 bool SetBreakPointForScript(Handle<Script> script, | 405 bool SetBreakPointForScript(Handle<Script> script, |
| 404 Handle<Object> break_point_object, | 406 Handle<Object> break_point_object, |
| 405 int* source_position, | 407 int* source_position, |
| 406 BreakPositionAlignment alignment); | 408 BreakPositionAlignment alignment); |
| 407 void ClearBreakPoint(Handle<Object> break_point_object); | 409 void ClearBreakPoint(Handle<Object> break_point_object); |
| 408 void ClearAllBreakPoints(); | 410 void ClearAllBreakPoints(); |
| 409 void FloodWithOneShot(Handle<JSFunction> function); | 411 void FloodWithOneShot(Handle<JSFunction> function); |
| 410 void FloodBoundFunctionWithOneShot(Handle<JSFunction> function); | 412 void FloodBoundFunctionWithOneShot(Handle<JSFunction> function); |
| 411 void FloodHandlerWithOneShot(); | 413 void FloodHandlerWithOneShot(); |
| 412 void ChangeBreakOnException(ExceptionBreakType type, bool enable); | 414 void ChangeBreakOnException(ExceptionBreakType type, bool enable); |
| 413 bool IsBreakOnException(ExceptionBreakType type); | 415 bool IsBreakOnException(ExceptionBreakType type); |
| 414 | 416 |
| 415 void PromiseHandlePrologue(Handle<JSFunction> promise_getter); | 417 // Stepping handling. |
| 416 void PromiseHandleEpilogue(); | |
| 417 // Returns a promise if it does not have a reject handler. | |
| 418 Handle<Object> GetPromiseForUncaughtException(); | |
| 419 | |
| 420 void PrepareStep(StepAction step_action, | 418 void PrepareStep(StepAction step_action, |
| 421 int step_count, | 419 int step_count, |
| 422 StackFrame::Id frame_id); | 420 StackFrame::Id frame_id); |
| 423 void ClearStepping(); | 421 void ClearStepping(); |
| 424 void ClearStepOut(); | 422 void ClearStepOut(); |
| 425 bool IsStepping() { return thread_local_.step_count_ > 0; } | 423 bool IsStepping() { return thread_local_.step_count_ > 0; } |
| 426 bool StepNextContinue(BreakLocationIterator* break_location_iterator, | 424 bool StepNextContinue(BreakLocationIterator* break_location_iterator, |
| 427 JavaScriptFrame* frame); | 425 JavaScriptFrame* frame); |
| 426 bool StepInActive() { return thread_local_.step_into_fp_ != 0; } |
| 427 void HandleStepIn(Handle<JSFunction> function, |
| 428 Handle<Object> holder, |
| 429 Address fp, |
| 430 bool is_constructor); |
| 431 bool StepOutActive() { return thread_local_.step_out_fp_ != 0; } |
| 432 |
| 433 // Purge all code objects that have no debug break slots. |
| 434 void PrepareForBreakPoints(); |
| 428 | 435 |
| 429 // Returns whether the operation succeeded. Compilation can only be triggered | 436 // Returns whether the operation succeeded. Compilation can only be triggered |
| 430 // if a valid closure is passed as the second argument, otherwise the shared | 437 // if a valid closure is passed as the second argument, otherwise the shared |
| 431 // function needs to be compiled already. | 438 // function needs to be compiled already. |
| 432 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared, | 439 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared, |
| 433 Handle<JSFunction> function); | 440 Handle<JSFunction> function); |
| 434 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); | 441 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); |
| 435 static bool HasDebugInfo(Handle<SharedFunctionInfo> shared); | 442 static bool HasDebugInfo(Handle<SharedFunctionInfo> shared); |
| 436 | 443 |
| 437 void PrepareForBreakPoints(); | |
| 438 | |
| 439 // This function is used in FunctionNameUsing* tests. | 444 // This function is used in FunctionNameUsing* tests. |
| 440 Object* FindSharedFunctionInfoInScript(Handle<Script> script, int position); | 445 Object* FindSharedFunctionInfoInScript(Handle<Script> script, int position); |
| 441 | 446 |
| 442 | |
| 443 // Returns true if the current stub call is patched to call the debugger. | 447 // Returns true if the current stub call is patched to call the debugger. |
| 444 static bool IsDebugBreak(Address addr); | 448 static bool IsDebugBreak(Address addr); |
| 445 // Returns true if the current return statement has been patched to be | 449 // Returns true if the current return statement has been patched to be |
| 446 // a debugger breakpoint. | 450 // a debugger breakpoint. |
| 447 static bool IsDebugBreakAtReturn(RelocInfo* rinfo); | 451 static bool IsDebugBreakAtReturn(RelocInfo* rinfo); |
| 448 // Check whether a code stub with the specified major key is a possible break | |
| 449 // point location. | |
| 450 static bool IsSourceBreakStub(Code* code); | |
| 451 static bool IsBreakStub(Code* code); | |
| 452 // Find the builtin to use for invoking the debug break | |
| 453 static Handle<Code> FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode); | |
| 454 | 452 |
| 455 static Handle<Object> GetSourceBreakLocations( | 453 static Handle<Object> GetSourceBreakLocations( |
| 456 Handle<SharedFunctionInfo> shared, | 454 Handle<SharedFunctionInfo> shared, |
| 457 BreakPositionAlignment position_aligment); | 455 BreakPositionAlignment position_aligment); |
| 458 | 456 |
| 459 // Getter for the debug_context. | |
| 460 inline Handle<Context> debug_context() { return debug_context_; } | |
| 461 | |
| 462 // Check whether a global object is the debug global object. | 457 // Check whether a global object is the debug global object. |
| 463 bool IsDebugGlobal(GlobalObject* global); | 458 bool IsDebugGlobal(GlobalObject* global); |
| 464 | 459 |
| 465 // Check whether this frame is just about to return. | 460 // Check whether this frame is just about to return. |
| 466 bool IsBreakAtReturn(JavaScriptFrame* frame); | 461 bool IsBreakAtReturn(JavaScriptFrame* frame); |
| 467 | 462 |
| 468 StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; } | 463 // Promise handling. |
| 469 int break_id() { return thread_local_.break_id_; } | 464 void PromiseHandlePrologue(Handle<JSFunction> promise_getter); |
| 465 void PromiseHandleEpilogue(); |
| 470 | 466 |
| 471 bool StepInActive() { return thread_local_.step_into_fp_ != 0; } | 467 // Support for LiveEdit |
| 472 void HandleStepIn(Handle<JSFunction> function, | |
| 473 Handle<Object> holder, | |
| 474 Address fp, | |
| 475 bool is_constructor); | |
| 476 Address step_in_fp() { return thread_local_.step_into_fp_; } | |
| 477 Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; } | |
| 478 | |
| 479 bool StepOutActive() { return thread_local_.step_out_fp_ != 0; } | |
| 480 Address step_out_fp() { return thread_local_.step_out_fp_; } | |
| 481 | |
| 482 EnterDebugger* debugger_entry() { return thread_local_.debugger_entry_; } | |
| 483 | |
| 484 // Check whether any of the specified interrupts are pending. | |
| 485 bool has_pending_interrupt() { | |
| 486 return thread_local_.has_pending_interrupt_; | |
| 487 } | |
| 488 | |
| 489 // Set specified interrupts as pending. | |
| 490 void set_has_pending_interrupt(bool value) { | |
| 491 thread_local_.has_pending_interrupt_ = value; | |
| 492 } | |
| 493 | |
| 494 // Getters for the current exception break state. | |
| 495 bool break_on_exception() { return break_on_exception_; } | |
| 496 bool break_on_uncaught_exception() { | |
| 497 return break_on_uncaught_exception_; | |
| 498 } | |
| 499 | |
| 500 void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, | 468 void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, |
| 501 LiveEdit::FrameDropMode mode, | 469 LiveEdit::FrameDropMode mode, |
| 502 Object** restarter_frame_function_pointer); | 470 Object** restarter_frame_function_pointer); |
| 503 | 471 |
| 504 // Support for setting the address to jump to when returning from break point. | 472 // Passed to MakeWeak. |
| 473 static void HandleWeakDebugInfo( |
| 474 const v8::WeakCallbackData<v8::Value, void>& data); |
| 475 |
| 476 // Threading support. |
| 477 char* ArchiveDebug(char* to); |
| 478 char* RestoreDebug(char* from); |
| 479 static int ArchiveSpacePerThread(); |
| 480 void FreeThreadResources() { } |
| 481 |
| 482 // Record function from which eval was called. |
| 483 static void RecordEvalCaller(Handle<Script> script); |
| 484 |
| 485 // Garbage collection notifications. |
| 486 void AfterGarbageCollection(); |
| 487 |
| 488 // Flags and states. |
| 489 EnterDebugger* debugger_entry() { return thread_local_.debugger_entry_; } |
| 490 inline Handle<Context> debug_context() { return debug_context_; } |
| 491 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } |
| 492 bool live_edit_enabled() const { |
| 493 return FLAG_enable_liveedit && live_edit_enabled_ ; |
| 494 } |
| 495 |
| 496 inline bool is_active() const { return is_active_; } |
| 497 inline bool is_loaded() const { return !debug_context_.is_null(); } |
| 498 inline bool has_break_points() const { return has_break_points_; } |
| 499 inline bool is_entered() const { |
| 500 return thread_local_.debugger_entry_ != NULL; |
| 501 } |
| 502 void set_disable_break(bool v) { break_disabled_ = v; } |
| 503 |
| 504 StackFrame::Id break_frame_id() { return thread_local_.break_frame_id_; } |
| 505 int break_id() { return thread_local_.break_id_; } |
| 506 |
| 507 // Support for embedding into generated code. |
| 505 Address after_break_target_address() { | 508 Address after_break_target_address() { |
| 506 return reinterpret_cast<Address>(&after_break_target_); | 509 return reinterpret_cast<Address>(&after_break_target_); |
| 507 } | 510 } |
| 508 | 511 |
| 509 Address restarter_frame_function_pointer_address() { | 512 Address restarter_frame_function_pointer_address() { |
| 510 Object*** address = &thread_local_.restarter_frame_function_pointer_; | 513 Object*** address = &thread_local_.restarter_frame_function_pointer_; |
| 511 return reinterpret_cast<Address>(address); | 514 return reinterpret_cast<Address>(address); |
| 512 } | 515 } |
| 513 | 516 |
| 514 static const int kEstimatedNofBreakPointsInFunction = 16; | 517 Address step_in_fp_addr() { |
| 515 | 518 return reinterpret_cast<Address>(&thread_local_.step_into_fp_); |
| 516 // Passed to MakeWeak. | 519 } |
| 517 static void HandleWeakDebugInfo( | |
| 518 const v8::WeakCallbackData<v8::Value, void>& data); | |
| 519 | |
| 520 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc | |
| 521 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc | |
| 522 | |
| 523 // Threading support. | |
| 524 char* ArchiveDebug(char* to); | |
| 525 char* RestoreDebug(char* from); | |
| 526 static int ArchiveSpacePerThread(); | |
| 527 void FreeThreadResources() { } | |
| 528 | |
| 529 // Script cache handling. | |
| 530 void CreateScriptCache(); | |
| 531 void DestroyScriptCache(); | |
| 532 void AddScriptToScriptCache(Handle<Script> script); | |
| 533 Handle<FixedArray> GetLoadedScripts(); | |
| 534 | |
| 535 // Record function from which eval was called. | |
| 536 static void RecordEvalCaller(Handle<Script> script); | |
| 537 | |
| 538 // Garbage collection notifications. | |
| 539 void AfterGarbageCollection(); | |
| 540 | 520 |
| 541 private: | 521 private: |
| 542 explicit Debug(Isolate* isolate); | 522 explicit Debug(Isolate* isolate); |
| 543 | 523 |
| 544 void UpdateState(); | 524 void UpdateState(); |
| 545 void Unload(); | 525 void Unload(); |
| 546 | |
| 547 // Mirror cache handling. | |
| 548 void ClearMirrorCache(); | |
| 549 | |
| 550 void SetNextBreakId() { | 526 void SetNextBreakId() { |
| 551 thread_local_.break_id_ = ++thread_local_.break_count_; | 527 thread_local_.break_id_ = ++thread_local_.break_count_; |
| 552 } | 528 } |
| 553 | 529 |
| 554 // Check whether there are commands in the command queue. | 530 // Check whether there are commands in the command queue. |
| 555 inline bool has_commands() const { return !command_queue_.IsEmpty(); } | 531 inline bool has_commands() const { return !command_queue_.IsEmpty(); } |
| 532 inline bool ignore_events() const { return is_suppressed_ || !is_active_; } |
| 556 | 533 |
| 557 // Constructors for debug event objects. | 534 // Constructors for debug event objects. |
| 558 MUST_USE_RESULT MaybeHandle<Object> MakeJSObject( | 535 MUST_USE_RESULT MaybeHandle<Object> MakeJSObject( |
| 559 const char* constructor_name, | 536 const char* constructor_name, |
| 560 int argc, | 537 int argc, |
| 561 Handle<Object> argv[]); | 538 Handle<Object> argv[]); |
| 562 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState(); | 539 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState(); |
| 563 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent( | 540 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent( |
| 564 Handle<Object> break_points_hit); | 541 Handle<Object> break_points_hit); |
| 565 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent( | 542 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent( |
| 566 Handle<Object> exception, | 543 Handle<Object> exception, |
| 567 bool uncaught, | 544 bool uncaught, |
| 568 Handle<Object> promise); | 545 Handle<Object> promise); |
| 569 MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent( | 546 MUST_USE_RESULT MaybeHandle<Object> MakeCompileEvent( |
| 570 Handle<Script> script, bool before); | 547 Handle<Script> script, bool before); |
| 571 MUST_USE_RESULT MaybeHandle<Object> MakeScriptCollectedEvent(int id); | 548 MUST_USE_RESULT MaybeHandle<Object> MakeScriptCollectedEvent(int id); |
| 572 | 549 |
| 550 // Mirror cache handling. |
| 551 void ClearMirrorCache(); |
| 552 |
| 553 // Returns a promise if it does not have a reject handler. |
| 554 Handle<Object> GetPromiseForUncaughtException(); |
| 573 | 555 |
| 574 void CallEventCallback(v8::DebugEvent event, | 556 void CallEventCallback(v8::DebugEvent event, |
| 575 Handle<Object> exec_state, | 557 Handle<Object> exec_state, |
| 576 Handle<Object> event_data, | 558 Handle<Object> event_data, |
| 577 v8::Debug::ClientData* client_data); | 559 v8::Debug::ClientData* client_data); |
| 578 | |
| 579 void ProcessDebugEvent(v8::DebugEvent event, | 560 void ProcessDebugEvent(v8::DebugEvent event, |
| 580 Handle<JSObject> event_data, | 561 Handle<JSObject> event_data, |
| 581 bool auto_continue); | 562 bool auto_continue); |
| 582 void NotifyMessageHandler(v8::DebugEvent event, | 563 void NotifyMessageHandler(v8::DebugEvent event, |
| 583 Handle<JSObject> exec_state, | 564 Handle<JSObject> exec_state, |
| 584 Handle<JSObject> event_data, | 565 Handle<JSObject> event_data, |
| 585 bool auto_continue); | 566 bool auto_continue); |
| 586 | |
| 587 // Invoke the message handler function. | |
| 588 void InvokeMessageHandler(MessageImpl message); | 567 void InvokeMessageHandler(MessageImpl message); |
| 589 | 568 |
| 590 inline bool EventActive() { | |
| 591 // Check whether the message handler was been cleared. | |
| 592 // TODO(yangguo): handle loading and unloading of the debugger differently. | |
| 593 // Currently argument event is not used. | |
| 594 return !is_suppressed_ && is_active_; | |
| 595 } | |
| 596 | |
| 597 static bool CompileDebuggerScript(Isolate* isolate, int index); | 569 static bool CompileDebuggerScript(Isolate* isolate, int index); |
| 598 void ClearOneShot(); | 570 void ClearOneShot(); |
| 599 void ActivateStepIn(StackFrame* frame); | 571 void ActivateStepIn(StackFrame* frame); |
| 600 void ClearStepIn(); | 572 void ClearStepIn(); |
| 601 void ActivateStepOut(StackFrame* frame); | 573 void ActivateStepOut(StackFrame* frame); |
| 602 void ClearStepNext(); | 574 void ClearStepNext(); |
| 603 // Returns whether the compile succeeded. | 575 // Returns whether the compile succeeded. |
| 604 void RemoveDebugInfo(Handle<DebugInfo> debug_info); | 576 void RemoveDebugInfo(Handle<DebugInfo> debug_info); |
| 605 Handle<Object> CheckBreakPoints(Handle<Object> break_point); | 577 Handle<Object> CheckBreakPoints(Handle<Object> break_point); |
| 606 bool CheckBreakPoint(Handle<Object> break_point_object); | 578 bool CheckBreakPoint(Handle<Object> break_point_object); |
| 607 | 579 |
| 608 void EnsureFunctionHasDebugBreakSlots(Handle<JSFunction> function); | |
| 609 void RecompileAndRelocateSuspendedGenerators( | |
| 610 const List<Handle<JSGeneratorObject> > &suspended_generators); | |
| 611 | |
| 612 void ThreadInit(); | 580 void ThreadInit(); |
| 613 | 581 |
| 614 class PromiseOnStack { | |
| 615 public: | |
| 616 PromiseOnStack(Isolate* isolate, | |
| 617 PromiseOnStack* prev, | |
| 618 Handle<JSFunction> getter); | |
| 619 ~PromiseOnStack(); | |
| 620 StackHandler* handler() { return handler_; } | |
| 621 Handle<JSFunction> getter() { return getter_; } | |
| 622 PromiseOnStack* prev() { return prev_; } | |
| 623 private: | |
| 624 Isolate* isolate_; | |
| 625 StackHandler* handler_; | |
| 626 Handle<JSFunction> getter_; | |
| 627 PromiseOnStack* prev_; | |
| 628 }; | |
| 629 | |
| 630 // Global handles. | 582 // Global handles. |
| 631 Handle<Context> debug_context_; | 583 Handle<Context> debug_context_; |
| 632 Handle<Object> event_listener_; | 584 Handle<Object> event_listener_; |
| 633 Handle<Object> event_listener_data_; | 585 Handle<Object> event_listener_data_; |
| 634 | 586 |
| 635 v8::Debug::MessageHandler message_handler_; | 587 v8::Debug::MessageHandler message_handler_; |
| 636 | 588 |
| 637 static const int kQueueInitialSize = 4; | 589 static const int kQueueInitialSize = 4; |
| 638 Semaphore command_received_; // Signaled for each command received. | 590 Semaphore command_received_; // Signaled for each command received. |
| 639 LockingCommandMessageQueue command_queue_; | 591 LockingCommandMessageQueue command_queue_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 // Number of queued steps left to perform before debug event. | 637 // Number of queued steps left to perform before debug event. |
| 686 int queued_step_count_; | 638 int queued_step_count_; |
| 687 | 639 |
| 688 // Frame pointer for frame from which step in was performed. | 640 // Frame pointer for frame from which step in was performed. |
| 689 Address step_into_fp_; | 641 Address step_into_fp_; |
| 690 | 642 |
| 691 // Frame pointer for the frame where debugger should be called when current | 643 // Frame pointer for the frame where debugger should be called when current |
| 692 // step out action is completed. | 644 // step out action is completed. |
| 693 Address step_out_fp_; | 645 Address step_out_fp_; |
| 694 | 646 |
| 695 // Pending interrupts scheduled while debugging. | |
| 696 bool has_pending_interrupt_; | |
| 697 | |
| 698 // Stores the way how LiveEdit has patched the stack. It is used when | 647 // Stores the way how LiveEdit has patched the stack. It is used when |
| 699 // debugger returns control back to user script. | 648 // debugger returns control back to user script. |
| 700 LiveEdit::FrameDropMode frame_drop_mode_; | 649 LiveEdit::FrameDropMode frame_drop_mode_; |
| 701 | 650 |
| 702 // When restarter frame is on stack, stores the address | 651 // When restarter frame is on stack, stores the address |
| 703 // of the pointer to function being restarted. Otherwise (most of the time) | 652 // of the pointer to function being restarted. Otherwise (most of the time) |
| 704 // stores NULL. This pointer is used with 'step in' implementation. | 653 // stores NULL. This pointer is used with 'step in' implementation. |
| 705 Object** restarter_frame_function_pointer_; | 654 Object** restarter_frame_function_pointer_; |
| 706 | 655 |
| 707 // When a promise is being resolved, we may want to trigger a debug event | 656 // When a promise is being resolved, we may want to trigger a debug event |
| 708 // if we catch a throw. For this purpose we remember the try-catch | 657 // if we catch a throw. For this purpose we remember the try-catch |
| 709 // handler address that would catch the exception. We also hold onto a | 658 // handler address that would catch the exception. We also hold onto a |
| 710 // closure that returns a promise if the exception is considered uncaught. | 659 // closure that returns a promise if the exception is considered uncaught. |
| 711 // Due to the possibility of reentry we use a linked list. | 660 // Due to the possibility of reentry we use a linked list. |
| 712 PromiseOnStack* promise_on_stack_; | 661 PromiseOnStack* promise_on_stack_; |
| 713 }; | 662 }; |
| 714 | 663 |
| 715 // Storage location for registers when handling debug break calls | 664 // Storage location for registers when handling debug break calls |
| 716 ThreadLocal thread_local_; | 665 ThreadLocal thread_local_; |
| 717 | 666 |
| 718 Isolate* isolate_; | 667 Isolate* isolate_; |
| 719 | 668 |
| 720 friend class Isolate; | 669 friend class Isolate; |
| 721 friend class EnterDebugger; | 670 friend class EnterDebugger; |
| 722 friend class FrameDropper; | 671 friend class FrameDropper; |
| 723 friend class DisableBreak; | 672 friend class DisableBreak; |
| 724 friend class SuppressDebug; | 673 friend class SuppressDebug; |
| 725 | 674 |
| 675 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc |
| 676 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc |
| 677 |
| 726 DISALLOW_COPY_AND_ASSIGN(Debug); | 678 DISALLOW_COPY_AND_ASSIGN(Debug); |
| 727 }; | 679 }; |
| 728 | 680 |
| 729 | 681 |
| 730 DECLARE_RUNTIME_FUNCTION(Debug_Break); | 682 DECLARE_RUNTIME_FUNCTION(Debug_Break); |
| 731 | 683 |
| 732 | 684 |
| 733 // This class is used for entering the debugger. Create an instance in the stack | 685 // This class is used for entering the debugger. Create an instance in the stack |
| 734 // to enter the debugger. This will set the current break state, make sure the | 686 // to enter the debugger. This will set the current break state, make sure the |
| 735 // debugger is loaded and switch to the debugger context. If the debugger for | 687 // debugger is loaded and switch to the debugger context. If the debugger for |
| 736 // some reason could not be entered FailedToEnter will return true. | 688 // some reason could not be entered FailedToEnter will return true. |
| 737 class EnterDebugger BASE_EMBEDDED { | 689 class EnterDebugger BASE_EMBEDDED { |
| 738 public: | 690 public: |
| 739 explicit EnterDebugger(Isolate* isolate); | 691 explicit EnterDebugger(Isolate* isolate); |
| 740 ~EnterDebugger(); | 692 ~EnterDebugger(); |
| 741 | 693 |
| 742 // Check whether the debugger could be entered. | 694 // Check whether the debugger could be entered. |
| 743 inline bool FailedToEnter() { return load_failed_; } | 695 inline bool FailedToEnter() { return load_failed_; } |
| 744 | 696 |
| 745 // Check whether there are any JavaScript frames on the stack. | |
| 746 inline bool HasJavaScriptFrames() { return has_js_frames_; } | |
| 747 | |
| 748 // Get the active context from before entering the debugger. | 697 // Get the active context from before entering the debugger. |
| 749 inline Handle<Context> GetContext() { return save_.context(); } | 698 inline Handle<Context> GetContext() { return save_.context(); } |
| 750 | 699 |
| 751 private: | 700 private: |
| 752 Isolate* isolate_; | 701 Isolate* isolate_; |
| 753 EnterDebugger* prev_; // Previous debugger entry if entered recursively. | 702 EnterDebugger* prev_; // Previous debugger entry if entered recursively. |
| 754 bool has_js_frames_; // Were there any JavaScript frames? | |
| 755 StackFrame::Id break_frame_id_; // Previous break frame id. | 703 StackFrame::Id break_frame_id_; // Previous break frame id. |
| 756 int break_id_; // Previous break id. | 704 int break_id_; // Previous break id. |
| 757 bool load_failed_; // Did the debugger fail to load? | 705 bool load_failed_; // Did the debugger fail to load? |
| 758 SaveContext save_; // Saves previous context. | 706 SaveContext save_; // Saves previous context. |
| 759 }; | 707 }; |
| 760 | 708 |
| 761 | 709 |
| 762 // Stack allocated class for disabling break. | 710 // Stack allocated class for disabling break. |
| 763 class DisableBreak BASE_EMBEDDED { | 711 class DisableBreak BASE_EMBEDDED { |
| 764 public: | 712 public: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // several frames above. | 759 // several frames above. |
| 812 // There is no calling conventions here, because it never actually gets | 760 // There is no calling conventions here, because it never actually gets |
| 813 // called, it only gets returned to. | 761 // called, it only gets returned to. |
| 814 static void GenerateFrameDropperLiveEdit(MacroAssembler* masm); | 762 static void GenerateFrameDropperLiveEdit(MacroAssembler* masm); |
| 815 }; | 763 }; |
| 816 | 764 |
| 817 | 765 |
| 818 } } // namespace v8::internal | 766 } } // namespace v8::internal |
| 819 | 767 |
| 820 #endif // V8_DEBUG_H_ | 768 #endif // V8_DEBUG_H_ |
| OLD | NEW |