📄 debug.h.svn-base
字号:
public: // Step action for last step performed. StepAction last_step_action_; // Source statement position from last step next action. int last_statement_position_; // Number of steps left to perform before debug event. int step_count_; // Frame pointer from last step next action. Address last_fp_; // Frame pointer for frame from which step in was performed. Address step_into_fp_; // Storage location for jump when exiting debug break calls. Address after_break_target_; }; // Storage location for registers when handling debug break calls static JSCallerSavedBuffer registers_; static ThreadLocal thread_local_; static void ThreadInit(); // Code object for debug break return entry code. static Code* debug_break_return_entry_; // Code to call for handling debug break on return. static Code* debug_break_return_; DISALLOW_COPY_AND_ASSIGN(Debug);};class DebugMessageThread;class Debugger { public: static void DebugRequest(const uint16_t* json_request, int length); static Handle<Object> MakeJSObject(Vector<const char> constructor_name, int argc, Object*** argv, bool* caught_exception); static Handle<Object> MakeExecutionState(bool* caught_exception); static Handle<Object> MakeBreakEvent(Handle<Object> exec_state, Handle<Object> break_points_hit, bool* caught_exception); static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state, Handle<Object> exception, bool uncaught, bool* caught_exception); static Handle<Object> MakeNewFunctionEvent(Handle<Object> func, bool* caught_exception); static Handle<Object> MakeCompileEvent(Handle<Script> script, Handle<Object> script_function, bool* caught_exception); static Handle<String> ProcessRequest(Handle<Object> exec_state, Handle<Object> request, bool stopped); static void OnDebugBreak(Handle<Object> break_points_hit); static void OnException(Handle<Object> exception, bool uncaught); static void OnBeforeCompile(Handle<Script> script); static void OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun); static void OnNewFunction(Handle<JSFunction> fun); static void ProcessDebugEvent(v8::DebugEvent event, Handle<Object> event_data); static void SetMessageHandler(v8::DebugMessageHandler handler, void* data); static void SendMessage(Vector<uint16_t> message); static void ProcessCommand(Vector<const uint16_t> command); static void UpdateActiveDebugger(); inline static bool EventActive(v8::DebugEvent event) { // Currently argument event is not used. return !Debugger::compiling_natives_ && Debugger::debugger_active_; } static void set_debugger_active(bool debugger_active) { Debugger::debugger_active_ = debugger_active; } static bool debugger_active() { return Debugger::debugger_active_; } static void set_compiling_natives(bool compiling_natives) { Debugger::compiling_natives_ = compiling_natives; } static bool compiling_natives() { return Debugger::compiling_natives_; } static void set_loading_debugger(bool v) { is_loading_debugger_ = v; } static bool is_loading_debugger() { return Debugger::is_loading_debugger_; } private: static bool debugger_active_; // Are there any active debugger? static bool compiling_natives_; // Are we compiling natives? static bool is_loading_debugger_; // Are we loading the debugger? static DebugMessageThread* message_thread_; static v8::DebugMessageHandler debug_message_handler_; static void* debug_message_handler_data_;};// A Queue of Vector<uint16_t> objects. A thread-safe version is// LockingMessageQueue, based on this class.class MessageQueue BASE_EMBEDDED { public: explicit MessageQueue(int size); ~MessageQueue(); bool IsEmpty() const { return start_ == end_; } Vector<uint16_t> Get(); void Put(const Vector<uint16_t>& message); void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). private: // Doubles the size of the message queue, and copies the messages. void Expand(); Vector<uint16_t>* messages_; int start_; int end_; int size_; // The size of the queue buffer. Queue can hold size-1 messages.};// LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t>// messages. The message data is not managed by LockingMessageQueue.// Pointers to the data are passed in and out. Implemented by adding a// Mutex to MessageQueue. Includes logging of all puts and gets.class LockingMessageQueue BASE_EMBEDDED { public: explicit LockingMessageQueue(int size); ~LockingMessageQueue(); bool IsEmpty() const; Vector<uint16_t> Get(); void Put(const Vector<uint16_t>& message); void Clear(); private: MessageQueue queue_; Mutex* lock_; DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue);};/* This class is the data for a running thread that serializes * event messages and command processing for the debugger. * All uncommented methods are called only from this message thread. */class DebugMessageThread: public Thread { public: DebugMessageThread(); // Called from API thread. virtual ~DebugMessageThread(); // Never called. // Called by V8 thread. Reports events from V8 VM. // Also handles command processing in stopped state of V8, // when host_running_ is false. void DebugEvent(v8::DebugEvent, Handle<Object> exec_state, Handle<Object> event_data); // Puts event on the output queue. Called by V8. // This is where V8 hands off // processing of the event to the DebugMessageThread thread, // which forwards it to the debug_message_handler set by the API. void SendMessage(Vector<uint16_t> event_json); // Formats an event into JSON, and calls SendMessage. void SetEventJSONFromEvent(Handle<Object> event_data); // Puts a command coming from the public API on the queue. Called // by the API client thread. This is where the API client hands off // processing of the command to the DebugMessageThread thread. void ProcessCommand(Vector<uint16_t> command); void OnDebuggerInactive(); // Main function of DebugMessageThread thread. void Run(); bool host_running_; // Is the debugging host running or stopped? Semaphore* command_received_; // Non-zero when command queue is non-empty. Semaphore* message_received_; // Exactly equal to message queue length. private: bool TwoByteEqualsAscii(Vector<uint16_t> two_byte, const char* ascii); static const int kQueueInitialSize = 4; LockingMessageQueue command_queue_; LockingMessageQueue message_queue_; DISALLOW_COPY_AND_ASSIGN(DebugMessageThread);};// Helper class to support saving/restoring the top break frame id.class SaveBreakFrame { public: SaveBreakFrame() : set_(!it_.done()) { if (set_) { // Store the previous break is and frame id. break_id_ = Top::break_id(); break_frame_id_ = Top::break_frame_id(); // Create the new break info. Top::new_break(it_.frame()->id()); } } ~SaveBreakFrame() { if (set_) { // restore to the previous break state. Top::set_break(break_frame_id_, break_id_); } } private: JavaScriptFrameIterator it_; const bool set_; // Was the break actually set? StackFrame::Id break_frame_id_; // Previous break frame id. int break_id_; // Previous break id.};class EnterDebuggerContext BASE_EMBEDDED { public: // Enter the debugger by storing the previous top context and setting the // current top context to the debugger context. EnterDebuggerContext() { // NOTE the member variable save which saves the previous context before // this change. Top::set_context(*Debug::debug_context()); Top::set_security_context(*Debug::debug_context()); } private: SaveContext save;};// Stack allocated class for disabling break.class DisableBreak BASE_EMBEDDED { public: // Enter the debugger by storing the previous top context and setting the // current top context to the debugger context. explicit DisableBreak(bool disable_break) { prev_disable_break_ = Debug::disable_break(); Debug::set_disable_break(disable_break); } ~DisableBreak() { Debug::set_disable_break(prev_disable_break_); } private: // The previous state of the disable break used to restore the value when this // object is destructed. bool prev_disable_break_;};// Debug_Address encapsulates the Address pointers used in generating debug// code.class Debug_Address { public: Debug_Address(Debug::AddressId id, int reg = 0) : id_(id), reg_(reg) { ASSERT(reg == 0 || id == Debug::k_register_address); } static Debug_Address AfterBreakTarget() { return Debug_Address(Debug::k_after_break_target_address); } static Debug_Address DebugBreakReturn() { return Debug_Address(Debug::k_debug_break_return_address); } static Debug_Address Register(int reg) { return Debug_Address(Debug::k_register_address, reg); } Address address() const { switch (id_) { case Debug::k_after_break_target_address: return reinterpret_cast<Address>(Debug::after_break_target_address()); case Debug::k_debug_break_return_address: return reinterpret_cast<Address>(Debug::debug_break_return_address()); case Debug::k_register_address: return reinterpret_cast<Address>(Debug::register_address(reg_)); default: UNREACHABLE(); return NULL; } } private: Debug::AddressId id_; int reg_;};} } // namespace v8::internal#endif // V8_V8_DEBUG_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -