| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // Doubles the size of the message queue, and copies the messages. | 552 // Doubles the size of the message queue, and copies the messages. |
| 553 void Expand(); | 553 void Expand(); |
| 554 | 554 |
| 555 CommandMessage* messages_; | 555 CommandMessage* messages_; |
| 556 int start_; | 556 int start_; |
| 557 int end_; | 557 int end_; |
| 558 int size_; // The size of the queue buffer. Queue can hold size-1 messages. | 558 int size_; // The size of the queue buffer. Queue can hold size-1 messages. |
| 559 }; | 559 }; |
| 560 | 560 |
| 561 | 561 |
| 562 class MessageDispatchHelperThread; |
| 563 |
| 564 |
| 562 // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage | 565 // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage |
| 563 // messages. The message data is not managed by LockingCommandMessageQueue. | 566 // messages. The message data is not managed by LockingCommandMessageQueue. |
| 564 // Pointers to the data are passed in and out. Implemented by adding a | 567 // Pointers to the data are passed in and out. Implemented by adding a |
| 565 // Mutex to CommandMessageQueue. Includes logging of all puts and gets. | 568 // Mutex to CommandMessageQueue. Includes logging of all puts and gets. |
| 566 class LockingCommandMessageQueue BASE_EMBEDDED { | 569 class LockingCommandMessageQueue BASE_EMBEDDED { |
| 567 public: | 570 public: |
| 568 explicit LockingCommandMessageQueue(int size); | 571 explicit LockingCommandMessageQueue(int size); |
| 569 ~LockingCommandMessageQueue(); | 572 ~LockingCommandMessageQueue(); |
| 570 bool IsEmpty() const; | 573 bool IsEmpty() const; |
| 571 CommandMessage Get(); | 574 CommandMessage Get(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 bool auto_continue); | 615 bool auto_continue); |
| 613 static void NotifyMessageHandler(v8::DebugEvent event, | 616 static void NotifyMessageHandler(v8::DebugEvent event, |
| 614 Handle<JSObject> exec_state, | 617 Handle<JSObject> exec_state, |
| 615 Handle<JSObject> event_data, | 618 Handle<JSObject> event_data, |
| 616 bool auto_continue); | 619 bool auto_continue); |
| 617 static void SetEventListener(Handle<Object> callback, Handle<Object> data); | 620 static void SetEventListener(Handle<Object> callback, Handle<Object> data); |
| 618 static void SetMessageHandler(v8::Debug::MessageHandler2 handler); | 621 static void SetMessageHandler(v8::Debug::MessageHandler2 handler); |
| 619 static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 622 static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
| 620 int period); | 623 int period); |
| 621 static void SetDebugMessageDispatchHandler( | 624 static void SetDebugMessageDispatchHandler( |
| 622 v8::Debug::DebugMessageDispatchHandler handler); | 625 v8::Debug::DebugMessageDispatchHandler handler, |
| 626 bool provide_locker); |
| 623 | 627 |
| 624 // Invoke the message handler function. | 628 // Invoke the message handler function. |
| 625 static void InvokeMessageHandler(MessageImpl message); | 629 static void InvokeMessageHandler(MessageImpl message); |
| 626 | 630 |
| 627 // Add a debugger command to the command queue. | 631 // Add a debugger command to the command queue. |
| 628 static void ProcessCommand(Vector<const uint16_t> command, | 632 static void ProcessCommand(Vector<const uint16_t> command, |
| 629 v8::Debug::ClientData* client_data = NULL); | 633 v8::Debug::ClientData* client_data = NULL); |
| 630 | 634 |
| 631 // Check whether there are commands in the command queue. | 635 // Check whether there are commands in the command queue. |
| 632 static bool HasCommands(); | 636 static bool HasCommands(); |
| 633 | 637 |
| 634 static Handle<Object> Call(Handle<JSFunction> fun, | 638 static Handle<Object> Call(Handle<JSFunction> fun, |
| 635 Handle<Object> data, | 639 Handle<Object> data, |
| 636 bool* pending_exception); | 640 bool* pending_exception); |
| 637 | 641 |
| 638 // Start the debugger agent listening on the provided port. | 642 // Start the debugger agent listening on the provided port. |
| 639 static bool StartAgent(const char* name, int port, | 643 static bool StartAgent(const char* name, int port, |
| 640 bool wait_for_connection = false); | 644 bool wait_for_connection = false); |
| 641 | 645 |
| 642 // Stop the debugger agent. | 646 // Stop the debugger agent. |
| 643 static void StopAgent(); | 647 static void StopAgent(); |
| 644 | 648 |
| 645 // Blocks until the agent has started listening for connections | 649 // Blocks until the agent has started listening for connections |
| 646 static void WaitForAgent(); | 650 static void WaitForAgent(); |
| 647 | 651 |
| 652 static void CallMessageDispatchHandler(); |
| 653 |
| 648 // Unload the debugger if possible. Only called when no debugger is currently | 654 // Unload the debugger if possible. Only called when no debugger is currently |
| 649 // active. | 655 // active. |
| 650 static void UnloadDebugger(); | 656 static void UnloadDebugger(); |
| 651 | 657 |
| 652 inline static bool EventActive(v8::DebugEvent event) { | 658 inline static bool EventActive(v8::DebugEvent event) { |
| 653 ScopedLock with(debugger_access_); | 659 ScopedLock with(debugger_access_); |
| 654 | 660 |
| 655 // Check whether the message handler was been cleared. | 661 // Check whether the message handler was been cleared. |
| 656 if (debugger_unload_pending_) { | 662 if (debugger_unload_pending_) { |
| 657 if (Debug::debugger_entry() == NULL) { | 663 if (Debug::debugger_entry() == NULL) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 676 | 682 |
| 677 static Mutex* debugger_access_; // Mutex guarding debugger variables. | 683 static Mutex* debugger_access_; // Mutex guarding debugger variables. |
| 678 static Handle<Object> event_listener_; // Global handle to listener. | 684 static Handle<Object> event_listener_; // Global handle to listener. |
| 679 static Handle<Object> event_listener_data_; | 685 static Handle<Object> event_listener_data_; |
| 680 static bool compiling_natives_; // Are we compiling natives? | 686 static bool compiling_natives_; // Are we compiling natives? |
| 681 static bool is_loading_debugger_; // Are we loading the debugger? | 687 static bool is_loading_debugger_; // Are we loading the debugger? |
| 682 static bool never_unload_debugger_; // Can we unload the debugger? | 688 static bool never_unload_debugger_; // Can we unload the debugger? |
| 683 static v8::Debug::MessageHandler2 message_handler_; | 689 static v8::Debug::MessageHandler2 message_handler_; |
| 684 static bool debugger_unload_pending_; // Was message handler cleared? | 690 static bool debugger_unload_pending_; // Was message handler cleared? |
| 685 static v8::Debug::HostDispatchHandler host_dispatch_handler_; | 691 static v8::Debug::HostDispatchHandler host_dispatch_handler_; |
| 692 static Mutex* dispatch_handler_access_; // Mutex guarding dispatch handler. |
| 686 static v8::Debug::DebugMessageDispatchHandler debug_message_dispatch_handler_; | 693 static v8::Debug::DebugMessageDispatchHandler debug_message_dispatch_handler_; |
| 694 static MessageDispatchHelperThread* message_dispatch_helper_thread_; |
| 687 static int host_dispatch_micros_; | 695 static int host_dispatch_micros_; |
| 688 | 696 |
| 689 static DebuggerAgent* agent_; | 697 static DebuggerAgent* agent_; |
| 690 | 698 |
| 691 static const int kQueueInitialSize = 4; | 699 static const int kQueueInitialSize = 4; |
| 692 static LockingCommandMessageQueue command_queue_; | 700 static LockingCommandMessageQueue command_queue_; |
| 693 static Semaphore* command_received_; // Signaled for each command received. | 701 static Semaphore* command_received_; // Signaled for each command received. |
| 694 | 702 |
| 695 friend class EnterDebugger; | 703 friend class EnterDebugger; |
| 696 }; | 704 }; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 default: | 861 default: |
| 854 UNREACHABLE(); | 862 UNREACHABLE(); |
| 855 return NULL; | 863 return NULL; |
| 856 } | 864 } |
| 857 } | 865 } |
| 858 private: | 866 private: |
| 859 Debug::AddressId id_; | 867 Debug::AddressId id_; |
| 860 int reg_; | 868 int reg_; |
| 861 }; | 869 }; |
| 862 | 870 |
| 871 // The optional thread that Debug Agent may use to temporary call V8 to process |
| 872 // pending debug requests if debuggee is not running V8 at the moment. |
| 873 // Techincally it does not call V8 itself, rather it asks embedding program |
| 874 // to do this via v8::Debug::HostDispatchHandler |
| 875 class MessageDispatchHelperThread: public Thread { |
| 876 public: |
| 877 MessageDispatchHelperThread(); |
| 878 ~MessageDispatchHelperThread(); |
| 879 |
| 880 void Schedule(); |
| 881 |
| 882 private: |
| 883 void Run(); |
| 884 |
| 885 Semaphore* const sem_; |
| 886 Mutex* const mutex_; |
| 887 bool already_signalled_; |
| 888 |
| 889 DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread); |
| 890 }; |
| 891 |
| 863 | 892 |
| 864 } } // namespace v8::internal | 893 } } // namespace v8::internal |
| 865 | 894 |
| 866 #endif // ENABLE_DEBUGGER_SUPPORT | 895 #endif // ENABLE_DEBUGGER_SUPPORT |
| 867 | 896 |
| 868 #endif // V8_DEBUG_H_ | 897 #endif // V8_DEBUG_H_ |
| OLD | NEW |