Author: [email protected]
Date: Mon Mar 23 15:23:39 2009
New Revision: 1579
Modified:
branches/bleeding_edge/include/v8-debug.h
branches/bleeding_edge/src/api.cc
branches/bleeding_edge/src/d8-debug.cc
branches/bleeding_edge/src/d8.cc
branches/bleeding_edge/src/debug-agent.cc
branches/bleeding_edge/src/debug-agent.h
branches/bleeding_edge/src/debug.cc
branches/bleeding_edge/src/debug.h
branches/bleeding_edge/test/cctest/test-debug.cc
Log:
Extend debugger agent protocol with a connect message.Added a name of the
embedding application when enabeling the debugger agent.Send a connection
message from the debugger agent to the remote debugger when connecting.
This message contains the V8 version, the protcol version (currently 1) and
the name of the embedding application. Currently this information is just
printed raw as received.
Review URL: http://codereview.chromium.org/52012
Modified: branches/bleeding_edge/include/v8-debug.h
==============================================================================
--- branches/bleeding_edge/include/v8-debug.h (original)
+++ branches/bleeding_edge/include/v8-debug.h Mon Mar 23 15:23:39 2009
@@ -162,9 +162,10 @@
/**
* Enable the V8 builtin debug agent. The debugger agent will listen on
the
* supplied TCP/IP port for remote debugger connection.
+ * \param name the name of the embedding application
* \param port the TCP/IP port to listen on
*/
- static bool EnableAgent(int port);
+ static bool EnableAgent(const char* name, int port);
};
Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc (original)
+++ branches/bleeding_edge/src/api.cc Mon Mar 23 15:23:39 2009
@@ -3113,8 +3113,8 @@
}
-bool Debug::EnableAgent(int port) {
- return i::Debugger::StartAgent(port);
+bool Debug::EnableAgent(const char* name, int port) {
+ return i::Debugger::StartAgent(name, port);
}
Modified: branches/bleeding_edge/src/d8-debug.cc
==============================================================================
--- branches/bleeding_edge/src/d8-debug.cc (original)
+++ branches/bleeding_edge/src/d8-debug.cc Mon Mar 23 15:23:39 2009
@@ -305,6 +305,11 @@
void ReceiverThread::Run() {
+ // Receive the connect message (with empty body).
+ i::SmartPointer<char> message =
+ i::DebuggerAgentUtil::ReceiveMessage(remote_debugger_->conn());
+ ASSERT(*message == NULL);
+
while (true) {
// Receive a message.
i::SmartPointer<char> message =
Modified: branches/bleeding_edge/src/d8.cc
==============================================================================
--- branches/bleeding_edge/src/d8.cc (original)
+++ branches/bleeding_edge/src/d8.cc Mon Mar 23 15:23:39 2009
@@ -629,7 +629,7 @@
// Start the debugger agent if requested.
if (i::FLAG_debugger_agent) {
- v8::Debug::EnableAgent(i::FLAG_debugger_port);
+ v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port);
}
// Start the in-process debugger if requested.
Modified: branches/bleeding_edge/src/debug-agent.cc
==============================================================================
--- branches/bleeding_edge/src/debug-agent.cc (original)
+++ branches/bleeding_edge/src/debug-agent.cc Mon Mar 23 15:23:39 2009
@@ -150,6 +150,10 @@
void DebuggerAgentSession::Run() {
+ // Send the hello message.
+ bool ok = DebuggerAgentUtil::SendConnectMessage(client_, *agent_->name_);
+ if (!ok) return;
+
while (true) {
// Read data from the debugger front end.
SmartPointer<char> message =
DebuggerAgentUtil::ReceiveMessage(client_);
@@ -252,6 +256,9 @@
}
content_length = 10 * content_length + (value[i] - '0');
}
+ } else {
+ // For now just print all other headers than Content-Length.
+ PrintF("%s: %s\n", key, value);
}
// Start collecting new header.
@@ -264,6 +271,11 @@
}
}
+ // Return now if no body.
+ if (content_length == 0) {
+ return SmartPointer<char>();
+ }
+
// Read body.
char* buffer = NewArray<char>(content_length + 1);
received = ReceiveAll(conn, buffer, content_length);
@@ -277,6 +289,52 @@
}
+bool DebuggerAgentUtil::SendConnectMessage(const Socket* conn,
+ const char* embedding_host) {
+ static const int kBufferSize = 80;
+ char buffer[kBufferSize]; // Sending buffer.
+ bool ok;
+ int len;
+
+ // Send the header.
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
+ "Type: connect\n");
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
+ "V8-Version: %s\n", v8::V8::GetVersion());
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
+ "Protocol-Version: 1\n");
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+
+ if (embedding_host != NULL) {
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
+ "Embedding-Host: %s\n", embedding_host);
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+ }
+
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
+ "%s: 0\n", kContentLength);
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+
+ // Terminate header with empty line.
+ len = OS::SNPrintF(Vector<char>(buffer, kBufferSize), "\n");
+ ok = conn->Send(buffer, len);
+ if (!ok) return false;
+
+ // No body for connect message.
+
+ return true;
+}
+
+
bool DebuggerAgentUtil::SendMessage(const Socket* conn,
const Vector<uint16_t> message) {
static const int kBufferSize = 80;
@@ -291,7 +349,7 @@
// Send the header.
int len;
len = OS::SNPrintF(Vector<char>(buffer, kBufferSize),
- "Content-Length: %d\n", utf8_len);
+ "%s: %d\n", kContentLength, utf8_len);
conn->Send(buffer, len);
// Terminate header with empty line.
Modified: branches/bleeding_edge/src/debug-agent.h
==============================================================================
--- branches/bleeding_edge/src/debug-agent.h (original)
+++ branches/bleeding_edge/src/debug-agent.h Mon Mar 23 15:23:39 2009
@@ -42,8 +42,9 @@
// handles connection from a remote debugger.
class DebuggerAgent: public Thread {
public:
- explicit DebuggerAgent(int port)
- : port_(port), server_(OS::CreateSocket()), terminate_(false),
+ explicit DebuggerAgent(const char* name, int port)
+ : port_(port), name_(StrDup(name)),
+ server_(OS::CreateSocket()), terminate_(false),
session_access_(OS::CreateMutex()), session_(NULL),
terminate_now_(OS::CreateSemaphore(0)) {}
~DebuggerAgent() { delete server_; }
@@ -57,6 +58,7 @@
void CloseSession();
void OnSessionClosed(DebuggerAgentSession* session);
+ SmartPointer<const char> name_; // Name of the embedding application.
int port_; // Port to use for the agent.
Socket* server_; // Server socket for listen/accept.
bool terminate_; // Termination flag.
@@ -101,6 +103,8 @@
static int kContentLengthSize;
static SmartPointer<char> ReceiveMessage(const Socket* conn);
+ static bool SendConnectMessage(const Socket* conn,
+ const char* embedding_host);
static bool SendMessage(const Socket* conn, const Vector<uint16_t>
message);
static bool SendMessage(const Socket* conn,
const v8::Handle<v8::String> message);
Modified: branches/bleeding_edge/src/debug.cc
==============================================================================
--- branches/bleeding_edge/src/debug.cc (original)
+++ branches/bleeding_edge/src/debug.cc Mon Mar 23 15:23:39 2009
@@ -1828,9 +1828,9 @@
}
-bool Debugger::StartAgent(int port) {
+bool Debugger::StartAgent(const char* name, int port) {
if (Socket::Setup()) {
- agent_ = new DebuggerAgent(port);
+ agent_ = new DebuggerAgent(name, port);
agent_->Start();
return true;
}
Modified: branches/bleeding_edge/src/debug.h
==============================================================================
--- branches/bleeding_edge/src/debug.h (original)
+++ branches/bleeding_edge/src/debug.h Mon Mar 23 15:23:39 2009
@@ -441,7 +441,7 @@
bool* pending_exception);
// Start the debugger agent listening on the provided port.
- static bool StartAgent(int port);
+ static bool StartAgent(const char* name, int port);
// Stop the debugger agent.
static void StopAgent();
Modified: branches/bleeding_edge/test/cctest/test-debug.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-debug.cc (original)
+++ branches/bleeding_edge/test/cctest/test-debug.cc Mon Mar 23 15:23:39
2009
@@ -3840,12 +3840,12 @@
i::Socket::Setup();
// Test starting and stopping the agent without any client connection.
- i::Debugger::StartAgent(kPort);
+ i::Debugger::StartAgent("test", kPort);
i::Debugger::StopAgent();
// Test starting the agent, connecting a client and shutting down the
agent
// with the client connected.
- ok = i::Debugger::StartAgent(kPort);
+ ok = i::Debugger::StartAgent("test", kPort);
CHECK(ok);
i::Socket* client = i::OS::CreateSocket();
ok = client->Connect("localhost", port_str);
@@ -3858,7 +3858,7 @@
i::Socket* server = i::OS::CreateSocket();
server->Bind(kPort);
- i::Debugger::StartAgent(kPort);
+ i::Debugger::StartAgent("test", kPort);
i::Debugger::StopAgent();
delete server;
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---