Commit e26a58e4 authored by yangguo's avatar yangguo Committed by Commit bot

[debugger api] remove legacy JSON debug protocol.

R=jgruber@chromium.org
BUG=v8:5530

Review-Url: https://codereview.chromium.org/2642253005
Cr-Commit-Position: refs/heads/master@{#42543}
parent 37cdb18b
...@@ -23,68 +23,6 @@ enum DebugEvent { ...@@ -23,68 +23,6 @@ enum DebugEvent {
class V8_EXPORT Debug { class V8_EXPORT Debug {
public: public:
/**
* A client object passed to the v8 debugger whose ownership will be taken by
* it. v8 is always responsible for deleting the object.
*/
class ClientData {
public:
virtual ~ClientData() {}
};
/**
* A message object passed to the debug message handler.
*/
class Message {
public:
/**
* Check type of message.
*/
virtual bool IsEvent() const = 0;
virtual bool IsResponse() const = 0;
virtual DebugEvent GetEvent() const = 0;
/**
* Indicate whether this is a response to a continue command which will
* start the VM running after this is processed.
*/
virtual bool WillStartRunning() const = 0;
/**
* Access to execution state and event data. Don't store these cross
* callbacks as their content becomes invalid. These objects are from the
* debugger event that started the debug message loop.
*/
virtual Local<Object> GetExecutionState() const = 0;
virtual Local<Object> GetEventData() const = 0;
/**
* Get the debugger protocol JSON.
*/
virtual Local<String> GetJSON() const = 0;
/**
* Get the context active when the debug event happened. Note this is not
* the current active context as the JavaScript part of the debugger is
* running in its own context which is entered at this point.
*/
virtual Local<Context> GetEventContext() const = 0;
/**
* Client data passed with the corresponding request if any. This is the
* client_data data value passed into Debug::SendCommand along with the
* request that led to the message or NULL if the message is an event. The
* debugger takes ownership of the data and will delete it even if there is
* no message handler.
*/
virtual ClientData* GetClientData() const = 0;
virtual Isolate* GetIsolate() const = 0;
virtual ~Message() {}
};
/** /**
* An event details object passed to the debug event listener. * An event details object passed to the debug event listener.
*/ */
...@@ -115,13 +53,6 @@ class V8_EXPORT Debug { ...@@ -115,13 +53,6 @@ class V8_EXPORT Debug {
*/ */
virtual Local<Value> GetCallbackData() const = 0; virtual Local<Value> GetCallbackData() const = 0;
/**
* Client data passed to DebugBreakForCommand function. The
* debugger takes ownership of the data and will delete it even if
* there is no message handler.
*/
virtual ClientData* GetClientData() const = 0;
virtual Isolate* GetIsolate() const = 0; virtual Isolate* GetIsolate() const = 0;
virtual ~EventDetails() {} virtual ~EventDetails() {}
...@@ -132,26 +63,11 @@ class V8_EXPORT Debug { ...@@ -132,26 +63,11 @@ class V8_EXPORT Debug {
* *
* \param event_details object providing information about the debug event * \param event_details object providing information about the debug event
* *
* A EventCallback2 does not take possession of the event data, * A EventCallback does not take possession of the event data,
* and must not rely on the data persisting after the handler returns. * and must not rely on the data persisting after the handler returns.
*/ */
typedef void (*EventCallback)(const EventDetails& event_details); typedef void (*EventCallback)(const EventDetails& event_details);
/**
* Debug message callback function.
*
* \param message the debug message handler message object
*
* A MessageHandler does not take possession of the message data,
* and must not rely on the data persisting after the handler returns.
*/
typedef void (*MessageHandler)(const Message& message);
/**
* Callback function for the host to ensure debug messages are processed.
*/
typedef void (*DebugMessageDispatchHandler)();
static bool SetDebugEventListener(Isolate* isolate, EventCallback that, static bool SetDebugEventListener(Isolate* isolate, EventCallback that,
Local<Value> data = Local<Value>()); Local<Value> data = Local<Value>());
...@@ -167,16 +83,6 @@ class V8_EXPORT Debug { ...@@ -167,16 +83,6 @@ class V8_EXPORT Debug {
V8_DEPRECATED("No longer supported", V8_DEPRECATED("No longer supported",
static bool CheckDebugBreak(Isolate* isolate)); static bool CheckDebugBreak(Isolate* isolate));
// Message based interface. The message protocol is JSON.
V8_DEPRECATED("No longer supported",
static void SetMessageHandler(Isolate* isolate,
MessageHandler handler));
V8_DEPRECATED("No longer supported",
static void SendCommand(Isolate* isolate,
const uint16_t* command, int length,
ClientData* client_data = NULL));
/** /**
* Run a JavaScript function in the debugger. * Run a JavaScript function in the debugger.
* \param fun the function to call * \param fun the function to call
...@@ -207,40 +113,6 @@ class V8_EXPORT Debug { ...@@ -207,40 +113,6 @@ class V8_EXPORT Debug {
static MaybeLocal<Value> GetMirror(Local<Context> context, static MaybeLocal<Value> GetMirror(Local<Context> context,
v8::Local<v8::Value> obj)); v8::Local<v8::Value> obj));
/**
* Makes V8 process all pending debug messages.
*
* From V8 point of view all debug messages come asynchronously (e.g. from
* remote debugger) but they all must be handled synchronously: V8 cannot
* do 2 things at one time so normal script execution must be interrupted
* for a while.
*
* Generally when message arrives V8 may be in one of 3 states:
* 1. V8 is running script; V8 will automatically interrupt and process all
* pending messages;
* 2. V8 is suspended on debug breakpoint; in this state V8 is dedicated
* to reading and processing debug messages;
* 3. V8 is not running at all or has called some long-working C++ function;
* by default it means that processing of all debug messages will be deferred
* until V8 gets control again; however, embedding application may improve
* this by manually calling this method.
*
* Technically this method in many senses is equivalent to executing empty
* script:
* 1. It does nothing except for processing all pending debug messages.
* 2. It should be invoked with the same precautions and from the same context
* as V8 script would be invoked from, because:
* a. with "evaluate" command it can do whatever normal script can do,
* including all native calls;
* b. no other thread should call V8 while this method is running
* (v8::Locker may be used here).
*
* "Evaluate" debug command behavior currently is not specified in scope
* of this method.
*/
V8_DEPRECATED("No longer supported",
static void ProcessDebugMessages(Isolate* isolate));
/** /**
* Debugger is running in its own context which is entered while debugger * Debugger is running in its own context which is entered while debugger
* messages are being dispatched. This is an explicit getter for this * messages are being dispatched. This is an explicit getter for this
......
...@@ -8896,24 +8896,6 @@ bool Debug::CheckDebugBreak(Isolate* isolate) { ...@@ -8896,24 +8896,6 @@ bool Debug::CheckDebugBreak(Isolate* isolate) {
} }
void Debug::SetMessageHandler(Isolate* isolate,
v8::Debug::MessageHandler handler) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8(i_isolate);
i_isolate->debug()->SetMessageHandler(handler);
}
void Debug::SendCommand(Isolate* isolate,
const uint16_t* command,
int length,
ClientData* client_data) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
internal_isolate->debug()->EnqueueCommandMessage(
i::Vector<const uint16_t>(command, length), client_data);
}
MaybeLocal<Value> Debug::Call(Local<Context> context, MaybeLocal<Value> Debug::Call(Local<Context> context,
v8::Local<v8::Function> fun, v8::Local<v8::Function> fun,
v8::Local<v8::Value> data) { v8::Local<v8::Value> data) {
...@@ -8953,10 +8935,6 @@ MaybeLocal<Value> Debug::GetMirror(Local<Context> context, ...@@ -8953,10 +8935,6 @@ MaybeLocal<Value> Debug::GetMirror(Local<Context> context,
RETURN_ESCAPED(result); RETURN_ESCAPED(result);
} }
void Debug::ProcessDebugMessages(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)->debug()->ProcessDebugMessages(true);
}
Local<Context> Debug::GetDebugContext(Isolate* isolate) { Local<Context> Debug::GetDebugContext(Isolate* isolate) {
return debug::GetDebugContext(isolate); return debug::GetDebugContext(isolate);
......
This diff is collapsed.
...@@ -244,62 +244,16 @@ class DebugInfoListNode { ...@@ -244,62 +244,16 @@ class DebugInfoListNode {
DebugInfoListNode* next_; 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<JSObject> exec_state,
Handle<JSObject> event_data);
// Create a message object for the response to a debug command.
static MessageImpl NewResponse(DebugEvent event, bool running,
Handle<JSObject> exec_state,
Handle<JSObject> event_data,
Handle<String> 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<v8::Object> GetExecutionState() const;
virtual v8::Local<v8::Object> GetEventData() const;
virtual v8::Local<v8::String> GetJSON() const;
virtual v8::Local<v8::Context> GetEventContext() const;
virtual v8::Debug::ClientData* GetClientData() const;
virtual v8::Isolate* GetIsolate() const;
private:
MessageImpl(bool is_event, DebugEvent event, bool running,
Handle<JSObject> exec_state, Handle<JSObject> event_data,
Handle<String> 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<JSObject> exec_state_; // Current execution state.
Handle<JSObject> event_data_; // Data associated with the event.
Handle<String> 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. // Details of the debug event delivered to the debug event listener.
class EventDetailsImpl : public v8::Debug::EventDetails { class EventDetailsImpl : public v8::Debug::EventDetails {
public: public:
EventDetailsImpl(DebugEvent event, EventDetailsImpl(DebugEvent event, Handle<JSObject> exec_state,
Handle<JSObject> exec_state, Handle<JSObject> event_data, Handle<Object> callback_data);
Handle<JSObject> event_data,
Handle<Object> callback_data,
v8::Debug::ClientData* client_data);
virtual DebugEvent GetEvent() const; virtual DebugEvent GetEvent() const;
virtual v8::Local<v8::Object> GetExecutionState() const; virtual v8::Local<v8::Object> GetExecutionState() const;
virtual v8::Local<v8::Object> GetEventData() const; virtual v8::Local<v8::Object> GetEventData() const;
virtual v8::Local<v8::Context> GetEventContext() const; virtual v8::Local<v8::Context> GetEventContext() const;
virtual v8::Local<v8::Value> GetCallbackData() const; virtual v8::Local<v8::Value> GetCallbackData() const;
virtual v8::Debug::ClientData* GetClientData() const;
virtual v8::Isolate* GetIsolate() const; virtual v8::Isolate* GetIsolate() const;
private: private:
...@@ -308,70 +262,8 @@ class EventDetailsImpl : public v8::Debug::EventDetails { ...@@ -308,70 +262,8 @@ class EventDetailsImpl : public v8::Debug::EventDetails {
Handle<JSObject> event_data_; // Data associated with the event. Handle<JSObject> event_data_; // Data associated with the event.
Handle<Object> callback_data_; // User data passed with the callback Handle<Object> callback_data_; // User data passed with the callback
// when it was registered. // 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<uint16_t>& command,
v8::Debug::ClientData* data);
CommandMessage();
// Deletes user data and disposes of the text.
void Dispose();
Vector<uint16_t> text() const { return text_; }
v8::Debug::ClientData* client_data() const { return client_data_; }
private:
CommandMessage(const Vector<uint16_t>& text, v8::Debug::ClientData* data);
Vector<uint16_t> 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 { class DebugFeatureTracker {
public: public:
...@@ -405,7 +297,7 @@ class DebugFeatureTracker { ...@@ -405,7 +297,7 @@ class DebugFeatureTracker {
class Debug { class Debug {
public: public:
// Debug event triggers. // Debug event triggers.
void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); void OnDebugBreak(Handle<Object> break_points_hit);
void OnThrow(Handle<Object> exception); void OnThrow(Handle<Object> exception);
void OnPromiseReject(Handle<Object> promise, Handle<Object> value); void OnPromiseReject(Handle<Object> promise, Handle<Object> value);
...@@ -415,14 +307,10 @@ class Debug { ...@@ -415,14 +307,10 @@ class Debug {
// API facing. // API facing.
void SetEventListener(Handle<Object> callback, Handle<Object> data); void SetEventListener(Handle<Object> callback, Handle<Object> data);
void SetMessageHandler(v8::Debug::MessageHandler handler);
void EnqueueCommandMessage(Vector<const uint16_t> command,
v8::Debug::ClientData* client_data = NULL);
MUST_USE_RESULT MaybeHandle<Object> Call(Handle<Object> fun, MUST_USE_RESULT MaybeHandle<Object> Call(Handle<Object> fun,
Handle<Object> data); Handle<Object> data);
Handle<Context> GetDebugContext(); Handle<Context> GetDebugContext();
void HandleDebugBreak(); void HandleDebugBreak();
void ProcessDebugMessages(bool debug_command_only);
// Internal logic // Internal logic
bool Load(); bool Load();
...@@ -579,8 +467,6 @@ class Debug { ...@@ -579,8 +467,6 @@ class Debug {
thread_local_.break_id_ = ++thread_local_.break_count_; thread_local_.break_id_ = ++thread_local_.break_count_;
} }
// Check whether there are commands in the command queue.
inline bool has_commands() const { return !command_queue_.IsEmpty(); }
inline bool ignore_events() const { inline bool ignore_events() const {
return is_suppressed_ || !is_active_ || isolate_->needs_side_effect_check(); return is_suppressed_ || !is_active_ || isolate_->needs_side_effect_check();
} }
...@@ -604,8 +490,7 @@ class Debug { ...@@ -604,8 +490,7 @@ class Debug {
// is presented. Other clients can install JavaScript event listener // is presented. Other clients can install JavaScript event listener
// (e.g. some of NodeJS module). // (e.g. some of NodeJS module).
bool non_inspector_listener_exists() const { bool non_inspector_listener_exists() const {
return message_handler_ != nullptr || return !event_listener_.is_null() && !event_listener_->IsForeign();
(!event_listener_.is_null() && !event_listener_->IsForeign());
} }
void OnException(Handle<Object> exception, Handle<Object> promise); void OnException(Handle<Object> exception, Handle<Object> promise);
...@@ -626,16 +511,8 @@ class Debug { ...@@ -626,16 +511,8 @@ class Debug {
// Mirror cache handling. // Mirror cache handling.
void ClearMirrorCache(); void ClearMirrorCache();
void CallEventCallback(v8::DebugEvent event,
Handle<Object> exec_state,
Handle<Object> event_data,
v8::Debug::ClientData* client_data);
void ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script); void ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script);
void ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data, void ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data);
bool auto_continue);
void NotifyMessageHandler(v8::DebugEvent event, Handle<JSObject> exec_state,
Handle<JSObject> event_data, bool auto_continue);
void InvokeMessageHandler(MessageImpl message);
// Find the closest source position for a break point for a given position. // Find the closest source position for a break point for a given position.
int FindBreakablePosition(Handle<DebugInfo> debug_info, int source_position, int FindBreakablePosition(Handle<DebugInfo> debug_info, int source_position,
...@@ -676,14 +553,8 @@ class Debug { ...@@ -676,14 +553,8 @@ class Debug {
Handle<Object> event_listener_; Handle<Object> event_listener_;
Handle<Object> event_listener_data_; Handle<Object> event_listener_data_;
v8::Debug::MessageHandler message_handler_;
debug::DebugEventListener* debug_event_listener_ = nullptr; debug::DebugEventListener* debug_event_listener_ = nullptr;
static const int kQueueInitialSize = 4;
base::Semaphore command_received_; // Signaled for each command received.
LockingCommandMessageQueue command_queue_;
// Debugger is active, i.e. there is a debug event listener attached. // Debugger is active, i.e. there is a debug event listener attached.
bool is_active_; bool is_active_;
// Debugger needs to be notified on every new function call. // Debugger needs to be notified on every new function call.
......
This diff is collapsed.
This diff is collapsed.
...@@ -469,7 +469,7 @@ Object* StackGuard::HandleInterrupts() { ...@@ -469,7 +469,7 @@ Object* StackGuard::HandleInterrupts() {
isolate_->heap()->HandleGCRequest(); isolate_->heap()->HandleGCRequest();
} }
if (CheckDebugBreak() || CheckDebugCommand()) { if (CheckDebugBreak()) {
isolate_->debug()->HandleDebugBreak(); isolate_->debug()->HandleDebugBreak();
} }
......
...@@ -86,12 +86,11 @@ class StackGuard final { ...@@ -86,12 +86,11 @@ class StackGuard final {
#define INTERRUPT_LIST(V) \ #define INTERRUPT_LIST(V) \
V(DEBUGBREAK, DebugBreak, 0) \ V(DEBUGBREAK, DebugBreak, 0) \
V(DEBUGCOMMAND, DebugCommand, 1) \ V(TERMINATE_EXECUTION, TerminateExecution, 1) \
V(TERMINATE_EXECUTION, TerminateExecution, 2) \ V(GC_REQUEST, GC, 2) \
V(GC_REQUEST, GC, 3) \ V(INSTALL_CODE, InstallCode, 3) \
V(INSTALL_CODE, InstallCode, 4) \ V(API_INTERRUPT, ApiInterrupt, 4) \
V(API_INTERRUPT, ApiInterrupt, 5) \ V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites, 5)
V(DEOPT_MARKED_ALLOCATION_SITES, DeoptMarkedAllocationSites, 6)
#define V(NAME, Name, id) \ #define V(NAME, Name, id) \
inline bool Check##Name() { return CheckInterrupt(NAME); } \ inline bool Check##Name() { return CheckInterrupt(NAME); } \
......
...@@ -1249,28 +1249,6 @@ void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { ...@@ -1249,28 +1249,6 @@ void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
} }
void Logger::DebugTag(const char* call_site_tag) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
msg.Append("debug-tag,%s", call_site_tag);
msg.WriteToLogFile();
}
void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) {
if (!log_->IsEnabled() || !FLAG_log) return;
StringBuilder s(parameter.length() + 1);
for (int i = 0; i < parameter.length(); ++i) {
s.AddCharacter(static_cast<char>(parameter[i]));
}
char* parameter_string = s.Finalize();
Log::MessageBuilder msg(log_);
msg.Append("debug-queue-event,%s,%15.3f,%s", event_type,
base::OS::TimeCurrentMillis(), parameter_string);
DeleteArray(parameter_string);
msg.WriteToLogFile();
}
void Logger::RuntimeCallTimerEvent() { void Logger::RuntimeCallTimerEvent() {
RuntimeCallStats* stats = isolate_->counters()->runtime_call_stats(); RuntimeCallStats* stats = isolate_->counters()->runtime_call_stats();
RuntimeCallTimer* timer = stats->current_timer(); RuntimeCallTimer* timer = stats->current_timer();
......
...@@ -136,12 +136,6 @@ class Logger : public CodeEventListener { ...@@ -136,12 +136,6 @@ class Logger : public CodeEventListener {
// object. // object.
void SuspectReadEvent(Name* name, Object* obj); void SuspectReadEvent(Name* name, Object* obj);
// Emits an event when a message is put on or read from a debugging queue.
// DebugTag lets us put a call-site specific label on the event.
void DebugTag(const char* call_site_tag);
void DebugEvent(const char* event_type, Vector<uint16_t> parameter);
// ==== Events logged by --log-api. ==== // ==== Events logged by --log-api. ====
void ApiSecurityCheck(); void ApiSecurityCheck();
void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name); void ApiNamedPropertyAccess(const char* tag, JSObject* holder, Object* name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment