HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Oreo
|
8.0.0_r4
下载
查看原文件
收藏
根目录
external
v8
src
debug
debug.h
// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_DEBUG_DEBUG_H_ #define V8_DEBUG_DEBUG_H_ #include "src/allocation.h" #include "src/arguments.h" #include "src/assembler.h" #include "src/base/atomicops.h" #include "src/base/hashmap.h" #include "src/base/platform/platform.h" #include "src/debug/debug-interface.h" #include "src/execution.h" #include "src/factory.h" #include "src/flags.h" #include "src/frames.h" #include "src/globals.h" #include "src/runtime/runtime.h" #include "src/source-position-table.h" #include "src/string-stream.h" #include "src/v8threads.h" #include "include/v8-debug.h" namespace v8 { namespace internal { // Forward declarations. class DebugScope; // Step actions. NOTE: These values are in macros.py as well. enum StepAction : int8_t { StepNone = -1, // Stepping not prepared. StepOut = 0, // Step out of the current function. StepNext = 1, // Step to the next statement in the current function. StepIn = 2, // Step into new functions invoked or the next statement // in the current function. StepFrame = 3, // Step into a new frame or return to previous frame. LastStepAction = StepFrame }; // Type of exception break. NOTE: These values are in macros.py as well. enum ExceptionBreakType { BreakException = 0, BreakUncaughtException = 1 }; // Type of exception break. enum BreakLocatorType { ALL_BREAK_LOCATIONS, CALLS_AND_RETURNS }; // The different types of breakpoint position alignments. // Must match Debug.BreakPositionAlignment in debug.js enum BreakPositionAlignment { STATEMENT_ALIGNED = 0, BREAK_POSITION_ALIGNED = 1 }; enum DebugBreakType { NOT_DEBUG_BREAK, DEBUGGER_STATEMENT, DEBUG_BREAK_SLOT, DEBUG_BREAK_SLOT_AT_CALL, DEBUG_BREAK_SLOT_AT_RETURN, DEBUG_BREAK_SLOT_AT_TAIL_CALL, }; class BreakLocation { public: static BreakLocation FromFrame(Handle
debug_info, JavaScriptFrame* frame); static void AllAtCurrentStatement(Handle
debug_info, JavaScriptFrame* frame, List
* result_out); inline bool IsReturn() const { return type_ == DEBUG_BREAK_SLOT_AT_RETURN; } inline bool IsCall() const { return type_ == DEBUG_BREAK_SLOT_AT_CALL; } inline bool IsTailCall() const { return type_ == DEBUG_BREAK_SLOT_AT_TAIL_CALL; } inline bool IsDebugBreakSlot() const { return type_ >= DEBUG_BREAK_SLOT; } inline bool IsDebuggerStatement() const { return type_ == DEBUGGER_STATEMENT; } bool HasBreakPoint(Handle
debug_info) const; inline int position() const { return position_; } private: BreakLocation(Handle
abstract_code, DebugBreakType type, int code_offset, int position) : abstract_code_(abstract_code), code_offset_(code_offset), type_(type), position_(position) { DCHECK_NE(NOT_DEBUG_BREAK, type_); } static int BreakIndexFromCodeOffset(Handle
debug_info, Handle
abstract_code, int offset); void SetDebugBreak(); void ClearDebugBreak(); Handle
abstract_code_; int code_offset_; DebugBreakType type_; int position_; friend class CodeBreakIterator; friend class BytecodeArrayBreakIterator; }; class BreakIterator { public: static std::unique_ptr
GetIterator( Handle
debug_info, Handle
abstract_code, BreakLocatorType type = ALL_BREAK_LOCATIONS); virtual ~BreakIterator() {} virtual BreakLocation GetBreakLocation() = 0; virtual bool Done() const = 0; virtual void Next() = 0; void SkipTo(int count) { while (count-- > 0) Next(); } virtual int code_offset() = 0; int break_index() const { return break_index_; } inline int position() const { return position_; } inline int statement_position() const { return statement_position_; } virtual bool IsDebugBreak() = 0; virtual void ClearDebugBreak() = 0; virtual void SetDebugBreak() = 0; protected: explicit BreakIterator(Handle
debug_info, BreakLocatorType break_locator_type); int BreakIndexFromPosition(int position, BreakPositionAlignment alignment); Isolate* isolate() { return debug_info_->GetIsolate(); } Handle
debug_info_; int break_index_; int position_; int statement_position_; BreakLocatorType break_locator_type_; private: DisallowHeapAllocation no_gc_; DISALLOW_COPY_AND_ASSIGN(BreakIterator); }; class CodeBreakIterator : public BreakIterator { public: CodeBreakIterator(Handle
debug_info, BreakLocatorType type); ~CodeBreakIterator() override {} BreakLocation GetBreakLocation() override; bool Done() const override { return reloc_iterator_.done(); } void Next() override; bool IsDebugBreak() override; void ClearDebugBreak() override; void SetDebugBreak() override; void SkipToPosition(int position, BreakPositionAlignment alignment); int code_offset() override { return static_cast
(rinfo()->pc() - debug_info_->DebugCode()->instruction_start()); } private: int GetModeMask(BreakLocatorType type); DebugBreakType GetDebugBreakType(); RelocInfo::Mode rmode() { return reloc_iterator_.rinfo()->rmode(); } RelocInfo* rinfo() { return reloc_iterator_.rinfo(); } RelocIterator reloc_iterator_; SourcePositionTableIterator source_position_iterator_; DISALLOW_COPY_AND_ASSIGN(CodeBreakIterator); }; class BytecodeArrayBreakIterator : public BreakIterator { public: BytecodeArrayBreakIterator(Handle
debug_info, BreakLocatorType type); ~BytecodeArrayBreakIterator() override {} BreakLocation GetBreakLocation() override; bool Done() const override { return source_position_iterator_.done(); } void Next() override; bool IsDebugBreak() override; void ClearDebugBreak() override; void SetDebugBreak() override; void SkipToPosition(int position, BreakPositionAlignment alignment); int code_offset() override { return source_position_iterator_.code_offset(); } private: DebugBreakType GetDebugBreakType(); SourcePositionTableIterator source_position_iterator_; DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBreakIterator); }; // Linked list holding debug info objects. The debug info objects are kept as // weak handles to avoid a debug info object to keep a function alive. class DebugInfoListNode { public: explicit DebugInfoListNode(DebugInfo* debug_info); ~DebugInfoListNode(); DebugInfoListNode* next() { return next_; } void set_next(DebugInfoListNode* next) { next_ = next; } Handle
debug_info() { return Handle
(debug_info_); } private: // Global (weak) handle to the debug info object. DebugInfo** debug_info_; // Next pointer for linked list. DebugInfoListNode* next_; }; // Message delivered to the message handler callback. This is either a debugger // event or the response to a command. class MessageImpl: public v8::Debug::Message { public: // Create a message object for a debug event. static MessageImpl NewEvent(DebugEvent event, bool running, Handle
exec_state, Handle
event_data); // Create a message object for the response to a debug command. static MessageImpl NewResponse(DebugEvent event, bool running, Handle
exec_state, Handle
event_data, Handle
response_json, v8::Debug::ClientData* client_data); // Implementation of interface v8::Debug::Message. virtual bool IsEvent() const; virtual bool IsResponse() const; virtual DebugEvent GetEvent() const; virtual bool WillStartRunning() const; virtual v8::Local
GetExecutionState() const; virtual v8::Local
GetEventData() const; virtual v8::Local
GetJSON() const; virtual v8::Local
GetEventContext() const; virtual v8::Debug::ClientData* GetClientData() const; virtual v8::Isolate* GetIsolate() const; private: MessageImpl(bool is_event, DebugEvent event, bool running, Handle
exec_state, Handle
event_data, Handle
response_json, v8::Debug::ClientData* client_data); bool is_event_; // Does this message represent a debug event? DebugEvent event_; // Debug event causing the break. bool running_; // Will the VM start running after this event? Handle
exec_state_; // Current execution state. Handle
event_data_; // Data associated with the event. Handle
response_json_; // Response JSON if message holds a response. v8::Debug::ClientData* client_data_; // Client data passed with the request. }; // Details of the debug event delivered to the debug event listener. class EventDetailsImpl : public v8::DebugInterface::EventDetails { public: EventDetailsImpl(DebugEvent event, Handle
exec_state, Handle
event_data, Handle
callback_data, v8::Debug::ClientData* client_data); virtual DebugEvent GetEvent() const; virtual v8::Local
GetExecutionState() const; virtual v8::Local
GetEventData() const; virtual v8::Local
GetEventContext() const; virtual v8::Local
GetCallbackData() const; virtual v8::Debug::ClientData* GetClientData() const; virtual v8::Isolate* GetIsolate() const; private: DebugEvent event_; // Debug event causing the break. Handle
exec_state_; // Current execution state. Handle
event_data_; // Data associated with the event. Handle
callback_data_; // User data passed with the callback // when it was registered. v8::Debug::ClientData* client_data_; // Data passed to DebugBreakForCommand. }; // Message send by user to v8 debugger or debugger output message. // In addition to command text it may contain a pointer to some user data // which are expected to be passed along with the command reponse to message // handler. class CommandMessage { public: static CommandMessage New(const Vector
& command, v8::Debug::ClientData* data); CommandMessage(); // Deletes user data and disposes of the text. void Dispose(); Vector
text() const { return text_; } v8::Debug::ClientData* client_data() const { return client_data_; } private: CommandMessage(const Vector
& text, v8::Debug::ClientData* data); Vector
text_; v8::Debug::ClientData* client_data_; }; // A Queue of CommandMessage objects. A thread-safe version is // LockingCommandMessageQueue, based on this class. class CommandMessageQueue BASE_EMBEDDED { public: explicit CommandMessageQueue(int size); ~CommandMessageQueue(); bool IsEmpty() const { return start_ == end_; } CommandMessage Get(); void Put(const CommandMessage& 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(); CommandMessage* messages_; int start_; int end_; int size_; // The size of the queue buffer. Queue can hold size-1 messages. }; // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage // messages. The message data is not managed by LockingCommandMessageQueue. // Pointers to the data are passed in and out. Implemented by adding a // Mutex to CommandMessageQueue. Includes logging of all puts and gets. class LockingCommandMessageQueue BASE_EMBEDDED { public: LockingCommandMessageQueue(Logger* logger, int size); bool IsEmpty() const; CommandMessage Get(); void Put(const CommandMessage& message); void Clear(); private: Logger* logger_; CommandMessageQueue queue_; mutable base::Mutex mutex_; DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue); }; class DebugFeatureTracker { public: enum Feature { kActive = 1, kBreakPoint = 2, kStepping = 3, kHeapSnapshot = 4, kAllocationTracking = 5, kProfiler = 6, kLiveEdit = 7, }; explicit DebugFeatureTracker(Isolate* isolate) : isolate_(isolate), bitfield_(0) {} void Track(Feature feature); private: Isolate* isolate_; uint32_t bitfield_; }; // This class contains the debugger support. The main purpose is to handle // setting break points in the code. // // This class controls the debug info for all functions which currently have // active breakpoints in them. This debug info is held in the heap root object // debug_info which is a FixedArray. Each entry in this list is of class // DebugInfo. class Debug { public: // Debug event triggers. void OnDebugBreak(Handle
break_points_hit, bool auto_continue); void OnThrow(Handle
exception); void OnPromiseReject(Handle
promise, Handle
value); void OnCompileError(Handle
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册