OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/dbg_connection.h" | 5 #include "bin/dbg_connection.h" |
6 #include "bin/dbg_message.h" | 6 #include "bin/dbg_message.h" |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/lockers.h" | 8 #include "bin/lockers.h" |
9 #include "bin/log.h" | 9 #include "bin/log.h" |
10 #include "bin/socket.h" | 10 #include "bin/socket.h" |
11 #include "bin/thread.h" | 11 #include "bin/thread.h" |
12 #include "bin/utils.h" | 12 #include "bin/utils.h" |
13 | 13 |
14 #include "platform/globals.h" | 14 #include "platform/globals.h" |
15 #include "platform/json.h" | 15 #include "platform/json.h" |
16 #include "platform/utils.h" | 16 #include "platform/utils.h" |
17 | 17 |
18 #include "include/dart_api.h" | 18 #include "include/dart_api.h" |
19 | 19 |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 namespace bin { | 22 namespace bin { |
23 | 23 |
24 extern bool trace_debug_protocol; | 24 extern bool trace_debug_protocol; |
25 | 25 |
26 intptr_t DebuggerConnectionHandler::listener_fd_ = -1; | 26 intptr_t DebuggerConnectionHandler::listener_fd_ = -1; |
27 dart::Monitor* DebuggerConnectionHandler::handler_lock_ = new dart::Monitor(); | 27 Monitor* DebuggerConnectionHandler::handler_lock_ = new Monitor(); |
28 | 28 |
29 // TODO(asiva): Remove this once we have support for multiple debugger | 29 // TODO(asiva): Remove this once we have support for multiple debugger |
30 // connections. For now we just store the single debugger connection | 30 // connections. For now we just store the single debugger connection |
31 // handler in a static variable. | 31 // handler in a static variable. |
32 static DebuggerConnectionHandler* singleton_handler = NULL; | 32 static DebuggerConnectionHandler* singleton_handler = NULL; |
33 | 33 |
34 // The maximum message length to print when --trace_debug_protocol is | 34 // The maximum message length to print when --trace_debug_protocol is |
35 // specified. | 35 // specified. |
36 static const int kMaxPrintMessageLen = 1024; | 36 static const int kMaxPrintMessageLen = 1024; |
37 | 37 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 339 |
340 void DebuggerConnectionHandler::WaitForConnection() { | 340 void DebuggerConnectionHandler::WaitForConnection() { |
341 ASSERT(handler_lock_ != NULL); | 341 ASSERT(handler_lock_ != NULL); |
342 MonitorLocker ml(handler_lock_); | 342 MonitorLocker ml(handler_lock_); |
343 if (!IsListening()) { | 343 if (!IsListening()) { |
344 // If we are only running the vm service, don't wait for | 344 // If we are only running the vm service, don't wait for |
345 // connections. | 345 // connections. |
346 return; | 346 return; |
347 } | 347 } |
348 while (!IsConnected()) { | 348 while (!IsConnected()) { |
349 dart::Monitor::WaitResult res = ml.Wait(); | 349 Monitor::WaitResult res = ml.Wait(); |
350 ASSERT(res == dart::Monitor::kNotified); | 350 ASSERT(res == Monitor::kNotified); |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 void DebuggerConnectionHandler::SendMsg(intptr_t debug_fd, | 355 void DebuggerConnectionHandler::SendMsg(intptr_t debug_fd, |
356 dart::TextBuffer* msg) { | 356 dart::TextBuffer* msg) { |
357 ASSERT(handler_lock_ != NULL); | 357 ASSERT(handler_lock_ != NULL); |
358 MonitorLocker ml(handler_lock_); | 358 MonitorLocker ml(handler_lock_); |
359 SendMsgHelper(debug_fd, msg); | 359 SendMsgHelper(debug_fd, msg); |
360 } | 360 } |
(...skipping 27 matching lines...) Expand all Loading... |
388 ((msg->length() > print_len) ? "..." : "")); | 388 ((msg->length() > print_len) ? "..." : "")); |
389 } | 389 } |
390 | 390 |
391 // Sending messages in short pieces can be used to stress test the | 391 // Sending messages in short pieces can be used to stress test the |
392 // debugger front-end's message handling code. | 392 // debugger front-end's message handling code. |
393 const bool send_in_pieces = false; | 393 const bool send_in_pieces = false; |
394 if (send_in_pieces) { | 394 if (send_in_pieces) { |
395 intptr_t remaining = msg->length(); | 395 intptr_t remaining = msg->length(); |
396 intptr_t sent = 0; | 396 intptr_t sent = 0; |
397 const intptr_t max_piece_len = 122; // Pretty arbitrary, not a power of 2. | 397 const intptr_t max_piece_len = 122; // Pretty arbitrary, not a power of 2. |
398 dart::Monitor sleep; | 398 Monitor sleep; |
399 while (remaining > 0) { | 399 while (remaining > 0) { |
400 intptr_t piece_len = remaining; | 400 intptr_t piece_len = remaining; |
401 if (piece_len > max_piece_len) { | 401 if (piece_len > max_piece_len) { |
402 piece_len = max_piece_len; | 402 piece_len = max_piece_len; |
403 } | 403 } |
404 intptr_t written = | 404 intptr_t written = |
405 DebuggerConnectionImpl::Send(debug_fd, msg->buf() + sent, piece_len); | 405 DebuggerConnectionImpl::Send(debug_fd, msg->buf() + sent, piece_len); |
406 ASSERT(written == piece_len); | 406 ASSERT(written == piece_len); |
407 sent += written; | 407 sent += written; |
408 remaining -= written; | 408 remaining -= written; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 | 501 |
502 bool DebuggerConnectionHandler::IsConnected() { | 502 bool DebuggerConnectionHandler::IsConnected() { |
503 // TODO(asiva): Support multiple debugger connections. | 503 // TODO(asiva): Support multiple debugger connections. |
504 // Return true if a connection has been established. | 504 // Return true if a connection has been established. |
505 return singleton_handler != NULL; | 505 return singleton_handler != NULL; |
506 } | 506 } |
507 | 507 |
508 } // namespace bin | 508 } // namespace bin |
509 } // namespace dart | 509 } // namespace dart |
OLD | NEW |