Commit f8319c3c authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Re-submit http://codereview.chromium.org/99122 after fixing compilation issues.

TBR=yurys@chromium.org
Review URL: http://codereview.chromium.org/100155

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1813 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 974734be
......@@ -91,6 +91,57 @@ class EXPORT Debug {
};
/**
* 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 Handle<Object> GetExecutionState() const = 0;
virtual Handle<Object> GetEventData() const = 0;
/**
* Get the debugger protocol JSON.
*/
virtual Handle<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 it's own context which is entered at this point.
*/
virtual Handle<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 ~Message() {}
};
/**
* Debug event callback function.
*
......@@ -101,26 +152,22 @@ class EXPORT Debug {
* \param data value passed by the user to SetDebugEventListener
*/
typedef void (*EventCallback)(DebugEvent event,
Handle<Object> exec_state,
Handle<Object> event_data,
Handle<Value> data);
Handle<Object> exec_state,
Handle<Object> event_data,
Handle<Value> data);
/**
* Debug message callback function.
*
* \param message the debug message
* \param message the debug message handler message object
* \param length length of the message
* \param data the data value passed when registering the message handler
* \param client_data the data value passed into Debug::SendCommand along
* with the request that led to the message or NULL if the message is an
* asynchronous event. The debugger takes ownership of the data and will
* delete it before dying even if there is no message handler.
* A MessageHandler does not take posession of the message string,
* and must not rely on the data persisting after the handler returns.
*/
typedef void (*MessageHandler)(const uint16_t* message, int length,
ClientData* client_data);
typedef void (*MessageHandler)(const Message& message);
/**
* Debug host dispatch callback function.
......
......@@ -34,9 +34,8 @@ namespace v8 { namespace internal {
// Public V8 debugger API message handler function. This function just delegates
// to the debugger agent through it's data parameter.
void DebuggerAgentMessageHandler(const uint16_t* message, int length,
v8::Debug::ClientData* client_data) {
DebuggerAgent::instance_->DebuggerMessage(message, length);
void DebuggerAgentMessageHandler(const v8::Debug::Message& message) {
DebuggerAgent::instance_->DebuggerMessage(message);
}
// static
......@@ -125,13 +124,14 @@ void DebuggerAgent::CloseSession() {
}
void DebuggerAgent::DebuggerMessage(const uint16_t* message, int length) {
void DebuggerAgent::DebuggerMessage(const v8::Debug::Message& message) {
ScopedLock with(session_access_);
// Forward the message handling to the session.
if (session_ != NULL) {
session_->DebuggerMessage(Vector<uint16_t>(const_cast<uint16_t*>(message),
length));
v8::String::Value val(message.GetJSON());
session_->DebuggerMessage(Vector<uint16_t>(const_cast<uint16_t*>(*val),
val.length()));
}
}
......
......@@ -60,7 +60,7 @@ class DebuggerAgent: public Thread {
private:
void Run();
void CreateSession(Socket* socket);
void DebuggerMessage(const uint16_t* message, int length);
void DebuggerMessage(const v8::Debug::Message& message);
void CloseSession();
void OnSessionClosed(DebuggerAgentSession* session);
......@@ -75,8 +75,7 @@ class DebuggerAgent: public Thread {
static DebuggerAgent* instance_;
friend class DebuggerAgentSession;
friend void DebuggerAgentMessageHandler(const uint16_t* message, int length,
v8::Debug::ClientData* client_data);
friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message);
DISALLOW_COPY_AND_ASSIGN(DebuggerAgent);
};
......
This diff is collapsed.
......@@ -401,6 +401,54 @@ class Debug {
};
// 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::Handle<v8::Object> GetExecutionState() const;
virtual v8::Handle<v8::Object> GetEventData() const;
virtual v8::Handle<v8::String> GetJSON() const;
virtual v8::Handle<v8::Context> GetEventContext() const;
virtual v8::Debug::ClientData* GetClientData() 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.
};
// 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
......@@ -491,11 +539,11 @@ class Debugger {
Handle<JSFunction> fun);
static void OnNewFunction(Handle<JSFunction> fun);
static void ProcessDebugEvent(v8::DebugEvent event,
Handle<Object> event_data,
Handle<JSObject> event_data,
bool auto_continue);
static void NotifyMessageHandler(v8::DebugEvent event,
Handle<Object> exec_state,
Handle<Object> event_data,
Handle<JSObject> exec_state,
Handle<JSObject> event_data,
bool auto_continue);
static void SetEventListener(Handle<Object> callback, Handle<Object> data);
static void SetMessageHandler(v8::Debug::MessageHandler handler);
......@@ -503,11 +551,7 @@ class Debugger {
int period);
// Invoke the message handler function.
static void InvokeMessageHandler(v8::Handle<v8::String> output,
v8::Debug::ClientData* data);
// Send the JSON message for a debug event.
static bool InvokeMessageHandlerWithEvent(Handle<Object> event_data);
static void InvokeMessageHandler(MessageImpl message);
// Add a debugger command to the command queue.
static void ProcessCommand(Vector<const uint16_t> command,
......
......@@ -3427,10 +3427,10 @@ class MessageQueueDebuggerThread : public v8::internal::Thread {
void Run();
};
static void MessageHandler(const uint16_t* message, int length,
v8::Debug::ClientData* client_data) {
static void MessageHandler(const v8::Debug::Message& message) {
static char print_buffer[1000];
Utf16ToAscii(message, length, print_buffer);
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
if (IsBreakEventMessage(print_buffer)) {
// Lets test script wait until break occurs to send commands.
// Signals when a break is reported.
......@@ -3612,10 +3612,8 @@ TEST(MessageQueueExpandAndDestroy) {
static int handled_client_data_instances_count = 0;
static void MessageHandlerCountingClientData(
const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
if (client_data) {
const v8::Debug::Message& message) {
if (message.GetClientData() != NULL) {
handled_client_data_instances_count++;
}
}
......@@ -3691,10 +3689,10 @@ static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) {
}
static void ThreadedMessageHandler(const uint16_t* message, int length,
v8::Debug::ClientData* client_data) {
static void ThreadedMessageHandler(const v8::Debug::Message& message) {
static char print_buffer[1000];
Utf16ToAscii(message, length, print_buffer);
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
if (IsBreakEventMessage(print_buffer)) {
threaded_debugging_barriers.barrier_2.Wait();
}
......@@ -3788,11 +3786,10 @@ class BreakpointsDebuggerThread : public v8::internal::Thread {
Barriers* breakpoints_barriers;
static void BreakpointsMessageHandler(const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
static void BreakpointsMessageHandler(const v8::Debug::Message& message) {
static char print_buffer[1000];
Utf16ToAscii(message, length, print_buffer);
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
printf("%s\n", print_buffer);
fflush(stdout);
......@@ -3935,9 +3932,7 @@ TEST(SetDebugEventListenerOnUninitializedVM) {
}
static void DummyMessageHandler(const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
static void DummyMessageHandler(const v8::Debug::Message& message) {
}
......@@ -4162,9 +4157,7 @@ TEST(DebuggerUnload) {
// Debugger message handler which counts the number of times it is called.
static int message_handler_hit_count = 0;
static void MessageHandlerHitCount(const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
static void MessageHandlerHitCount(const v8::Debug::Message& message) {
message_handler_hit_count++;
const int kBufferSize = 1000;
......@@ -4213,9 +4206,7 @@ TEST(DebuggerClearMessageHandler) {
// Debugger message handler which clears the message handler while active.
static void MessageHandlerClearingMessageHandler(
const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
const v8::Debug::Message& message) {
message_handler_hit_count++;
// Clear debug message handler.
......@@ -4262,11 +4253,10 @@ class HostDispatchDebuggerThread : public v8::internal::Thread {
Barriers* host_dispatch_barriers;
static void HostDispatchMessageHandler(const uint16_t* message,
int length,
v8::Debug::ClientData* client_data) {
static void HostDispatchMessageHandler(const v8::Debug::Message& message) {
static char print_buffer[1000];
Utf16ToAscii(message, length, print_buffer);
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
printf("%s\n", print_buffer);
fflush(stdout);
}
......
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