28 #ifdef ENABLE_DEBUGGER_SUPPORT
41 Isolate* isolate =
reinterpret_cast<Isolate*
>(message.
GetIsolate());
42 DebuggerAgent* agent = isolate->debugger_agent_instance();
44 agent->DebuggerMessage(message);
48 DebuggerAgent::DebuggerAgent(Isolate* isolate,
const char*
name,
int port)
58 ASSERT(isolate_->debugger_agent_instance() ==
NULL);
59 isolate_->set_debugger_agent_instance(
this);
63 DebuggerAgent::~DebuggerAgent() {
64 isolate_->set_debugger_agent_instance(
NULL);
70 void DebuggerAgent::Run() {
72 server_->SetReuseAddress(
true);
76 while (!bound && !terminate_) {
77 bound = server_->Bind(port_);
83 const TimeDelta kTimeout = TimeDelta::FromSeconds(1);
84 PrintF(
"Failed to open socket on port %d, "
85 "waiting %d ms before retrying\n", port_,
86 static_cast<int>(kTimeout.InMilliseconds()));
87 if (!terminate_now_.WaitFor(kTimeout)) {
88 if (terminate_)
return;
95 bool ok = server_->Listen(1);
99 Socket* client = server_->Accept();
103 CreateSession(client);
110 void DebuggerAgent::Shutdown() {
116 terminate_now_.Signal();
125 void DebuggerAgent::WaitUntilListening() {
129 static const char* kCreateSessionMessage =
130 "Remote debugging session already active\r\n";
132 void DebuggerAgent::CreateSession(Socket* client) {
133 LockGuard<RecursiveMutex> session_access_guard(&session_access_);
136 if (session_ !=
NULL) {
137 int len =
StrLength(kCreateSessionMessage);
138 int res = client->Send(kCreateSessionMessage, len);
145 session_ =
new DebuggerAgentSession(
this, client);
146 isolate_->debugger()->SetMessageHandler(DebuggerAgentMessageHandler);
151 void DebuggerAgent::CloseSession() {
152 LockGuard<RecursiveMutex> session_access_guard(&session_access_);
155 if (session_ !=
NULL) {
156 session_->Shutdown();
165 LockGuard<RecursiveMutex> session_access_guard(&session_access_);
168 if (session_ !=
NULL) {
170 session_->DebuggerMessage(Vector<uint16_t>(const_cast<uint16_t*>(*val),
176 DebuggerAgentSession::~DebuggerAgentSession() {
181 void DebuggerAgent::OnSessionClosed(DebuggerAgentSession* session) {
188 LockGuard<RecursiveMutex> session_access_guard(&session_access_);
189 ASSERT(session == session_);
190 if (session == session_) {
191 session_->Shutdown();
198 void DebuggerAgentSession::Run() {
200 bool ok = DebuggerAgentUtil::SendConnectMessage(client_, agent_->name_.get());
205 SmartArrayPointer<char> message =
206 DebuggerAgentUtil::ReceiveMessage(client_);
208 const char* msg = message.get();
209 bool is_closing_session = (msg ==
NULL);
213 msg =
"{\"seq\":1,\"type\":\"request\",\"command\":\"disconnect\"}";
217 const char* disconnectRequestStr =
218 "\"type\":\"request\",\"command\":\"disconnect\"}";
219 const char* result = strstr(msg, disconnectRequestStr);
220 if (result !=
NULL) {
221 is_closing_session =
true;
227 int utf16_length = decoder.Utf16Length();
228 ScopedVector<uint16_t> temp(utf16_length + 1);
229 decoder.WriteUtf16(temp.start(), utf16_length);
235 reinterpret_cast<v8::Isolate*
>(agent_->isolate()));
237 if (is_closing_session) {
239 agent_->OnSessionClosed(
this);
246 void DebuggerAgentSession::DebuggerMessage(Vector<uint16_t> message) {
247 DebuggerAgentUtil::SendMessage(client_, message);
251 void DebuggerAgentSession::Shutdown() {
257 const char*
const DebuggerAgentUtil::kContentLength =
"Content-Length";
260 SmartArrayPointer<char> DebuggerAgentUtil::ReceiveMessage(Socket* conn) {
264 int content_length = 0;
266 const int kHeaderBufferSize = 80;
267 char header_buffer[kHeaderBufferSize];
268 int header_buffer_position = 0;
273 while (!(c ==
'\n' && prev_c ==
'\r')) {
275 received = conn->Receive(&c, 1);
277 PrintF(
"Error %d\n", Socket::GetLastError());
278 return SmartArrayPointer<char>();
282 if (header_buffer_position < kHeaderBufferSize) {
283 header_buffer[header_buffer_position++] = c;
288 if (header_buffer_position == 2) {
293 ASSERT(header_buffer_position > 1);
294 ASSERT(header_buffer_position <= kHeaderBufferSize);
295 header_buffer[header_buffer_position - 2] =
'\0';
298 char* key = header_buffer;
300 for (
int i = 0; header_buffer[i] !=
'\0'; i++) {
301 if (header_buffer[i] ==
':') {
302 header_buffer[i] =
'\0';
303 value = header_buffer + i + 1;
304 while (*value ==
' ') {
312 if (strcmp(key, kContentLength) == 0) {
314 if (value == NULL || strlen(value) > 7) {
315 return SmartArrayPointer<char>();
317 for (
int i = 0; value[i] !=
'\0'; i++) {
319 if (value[i] <
'0' || value[i] >
'9') {
320 return SmartArrayPointer<char>();
322 content_length = 10 * content_length + (value[i] -
'0');
326 PrintF(
"%s: %s\n", key, value != NULL ? value :
"(no value)");
331 if (content_length == 0) {
332 return SmartArrayPointer<char>();
336 char* buffer = NewArray<char>(content_length + 1);
337 received = ReceiveAll(conn, buffer, content_length);
338 if (received < content_length) {
339 PrintF(
"Error %d\n", Socket::GetLastError());
340 return SmartArrayPointer<char>();
342 buffer[content_length] =
'\0';
344 return SmartArrayPointer<char>(buffer);
348 bool DebuggerAgentUtil::SendConnectMessage(Socket* conn,
349 const char* embedding_host) {
350 static const int kBufferSize = 80;
351 char buffer[kBufferSize];
357 "Type: connect\r\n");
358 ok = conn->Send(buffer, len);
359 if (!ok)
return false;
363 ok = conn->Send(buffer, len);
364 if (!ok)
return false;
367 "Protocol-Version: 1\r\n");
368 ok = conn->Send(buffer, len);
369 if (!ok)
return false;
371 if (embedding_host != NULL) {
373 "Embedding-Host: %s\r\n", embedding_host);
374 ok = conn->Send(buffer, len);
375 if (!ok)
return false;
379 "%s: 0\r\n", kContentLength);
380 ok = conn->Send(buffer, len);
381 if (!ok)
return false;
384 len =
OS::SNPrintF(Vector<char>(buffer, kBufferSize),
"\r\n");
385 ok = conn->Send(buffer, len);
386 if (!ok)
return false;
394 bool DebuggerAgentUtil::SendMessage(Socket* conn,
395 const Vector<uint16_t> message) {
396 static const int kBufferSize = 80;
397 char buffer[kBufferSize];
402 for (
int i = 0; i < message.length(); i++) {
405 previous = character;
409 int len =
OS::SNPrintF(Vector<char>(buffer, kBufferSize),
410 "%s: %d\r\n", kContentLength, utf8_len);
411 if (conn->Send(buffer, len) < len) {
416 len =
OS::SNPrintF(Vector<char>(buffer, kBufferSize),
"\r\n");
417 if (conn->Send(buffer, len) < len) {
422 int buffer_position = 0;
424 for (
int i = 0; i < message.length(); i++) {
429 ASSERT(buffer_position <= kBufferSize);
432 if (kBufferSize - buffer_position <
434 i == message.length() - 1) {
436 const int kEncodedSurrogateLength =
438 ASSERT(buffer_position >= kEncodedSurrogateLength);
439 len = buffer_position - kEncodedSurrogateLength;
440 if (conn->Send(buffer, len) < len) {
443 for (
int i = 0; i < kEncodedSurrogateLength; i++) {
444 buffer[i] = buffer[buffer_position + i];
446 buffer_position = kEncodedSurrogateLength;
448 len = buffer_position;
449 if (conn->Send(buffer, len) < len) {
455 previous = character;
462 bool DebuggerAgentUtil::SendMessage(Socket* conn,
464 static const int kBufferSize = 80;
465 char buffer[kBufferSize];
471 int len =
OS::SNPrintF(Vector<char>(buffer, kBufferSize),
472 "Content-Length: %d\r\n", utf8_request.length());
473 if (conn->Send(buffer, len) < len) {
478 len =
OS::SNPrintF(Vector<char>(buffer, kBufferSize),
"\r\n");
479 if (conn->Send(buffer, len) < len) {
484 len = utf8_request.length();
485 if (conn->Send(*utf8_request, len) < len) {
494 int DebuggerAgentUtil::ReceiveAll(Socket* conn,
char* data,
int len) {
495 int total_received = 0;
496 while (total_received < len) {
497 int received = conn->Receive(data + total_received, len - total_received);
499 return total_received;
501 total_received += received;
503 return total_received;
508 #endif // ENABLE_DEBUGGER_SUPPORT
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
void PrintF(const char *format,...)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage message
#define ASSERT(condition)
static const int kMaxExtraUtf8BytesForOneUtf16CodeUnit
static const char * GetVersion()
virtual Isolate * GetIsolate() const =0
static uchar Length(uchar chr, int previous)
static const int kUtf8BytesToCodeASurrogate
virtual Handle< String > GetJSON() const =0
static unsigned Encode(char *out, uchar c, int previous, bool replace_invalid=false)
int StrLength(const char *string)
static int SNPrintF(Vector< char > str, const char *format,...)
static bool IsLeadSurrogate(int code)
char * StrDup(const char *str)
static void SendCommand(const uint16_t *command, int length, ClientData *client_data=NULL, Isolate *isolate=NULL)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
static const int kNoPreviousCharacter