Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Side by Side Diff: runtime/bin/dbg_connection.cc

Issue 11642019: Implement debugger connection on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Enable debugger test on Windows Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/dbg_connection_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/log.h" 8 #include "bin/log.h"
9 #include "bin/socket.h" 9 #include "bin/socket.h"
10 #include "bin/thread.h" 10 #include "bin/thread.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // TODO(hausner): 101 // TODO(hausner):
102 // Buffer is full. What should we do if there is no valid message 102 // Buffer is full. What should we do if there is no valid message
103 // in the buffer? This might be possible if the client sends a message 103 // in the buffer? This might be possible if the client sends a message
104 // that's larger than the buffer, of if the client sends malformed 104 // that's larger than the buffer, of if the client sends malformed
105 // messages that keep piling up. 105 // messages that keep piling up.
106 ASSERT(IsValidMessage()); 106 ASSERT(IsValidMessage());
107 return; 107 return;
108 } 108 }
109 // TODO(hausner): Handle error conditions returned by Read. We may 109 // TODO(hausner): Handle error conditions returned by Read. We may
110 // want to close the debugger connection if we get any errors. 110 // want to close the debugger connection if we get any errors.
111 int bytes_read = Socket::Read(fd_, buf_ + data_length_, max_read); 111 int bytes_read =
112 DebuggerConnectionImpl::Receive(fd_, buf_ + data_length_, max_read);
112 if (bytes_read == 0) { 113 if (bytes_read == 0) {
113 connection_is_alive_ = false; 114 connection_is_alive_ = false;
114 return; 115 return;
115 } 116 }
116 ASSERT(bytes_read > 0); 117 ASSERT(bytes_read > 0);
117 data_length_ += bytes_read; 118 data_length_ += bytes_read;
118 ASSERT(data_length_ < buf_length_); 119 ASSERT(data_length_ < buf_length_);
119 buf_[data_length_] = '\0'; 120 buf_[data_length_] = '\0';
120 } 121 }
121 122
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void DebuggerConnectionHandler::StartHandler(const char* address, 278 void DebuggerConnectionHandler::StartHandler(const char* address,
278 int port_number) { 279 int port_number) {
279 MonitorLocker ml(&handler_lock_); 280 MonitorLocker ml(&handler_lock_);
280 if (listener_fd_ != -1) { 281 if (listener_fd_ != -1) {
281 return; // The debugger connection handler was already started. 282 return; // The debugger connection handler was already started.
282 } 283 }
283 284
284 // First setup breakpoint, exception and delayed breakpoint handlers. 285 // First setup breakpoint, exception and delayed breakpoint handlers.
285 DbgMsgQueueList::Initialize(); 286 DbgMsgQueueList::Initialize();
286 287
288 // Initialize the socket implementation.
289 if (!Socket::Initialize()) {
290 FATAL("Failed initializing socket implementation.");
291 }
292
287 // Now setup a listener socket and start a thread which will 293 // Now setup a listener socket and start a thread which will
288 // listen, accept connections from debuggers, read and handle/dispatch 294 // listen, accept connections from debuggers, read and handle/dispatch
289 // debugger commands received on these connections. 295 // debugger commands received on these connections.
290 ASSERT(listener_fd_ == -1); 296 ASSERT(listener_fd_ == -1);
291 listener_fd_ = ServerSocket::CreateBindListen(address, port_number, 1); 297 listener_fd_ = ServerSocket::CreateBindListen(address, port_number, 1);
292 DebuggerConnectionImpl::StartHandler(port_number); 298 DebuggerConnectionImpl::StartHandler(port_number);
293 } 299 }
294 300
295 301
296 void DebuggerConnectionHandler::WaitForConnection() { 302 void DebuggerConnectionHandler::WaitForConnection() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 intptr_t remaining = msg->length(); 334 intptr_t remaining = msg->length();
329 intptr_t sent = 0; 335 intptr_t sent = 0;
330 const intptr_t max_piece_len = 122; // Pretty arbitrary, not a power of 2. 336 const intptr_t max_piece_len = 122; // Pretty arbitrary, not a power of 2.
331 dart::Monitor sleep; 337 dart::Monitor sleep;
332 while (remaining > 0) { 338 while (remaining > 0) {
333 intptr_t piece_len = remaining; 339 intptr_t piece_len = remaining;
334 if (piece_len > max_piece_len) { 340 if (piece_len > max_piece_len) {
335 piece_len = max_piece_len; 341 piece_len = max_piece_len;
336 } 342 }
337 intptr_t written = 343 intptr_t written =
338 Socket::Write(debug_fd, msg->buf() + sent, piece_len); 344 DebuggerConnectionImpl::Send(debug_fd, msg->buf() + sent, piece_len);
339 ASSERT(written == piece_len); 345 ASSERT(written == piece_len);
340 sent += written; 346 sent += written;
341 remaining -= written; 347 remaining -= written;
342 // Wait briefly so the OS does not coalesce message fragments. 348 // Wait briefly so the OS does not coalesce message fragments.
343 { 349 {
344 MonitorLocker ml(&sleep); 350 MonitorLocker ml(&sleep);
345 ml.Wait(10); 351 ml.Wait(10);
346 } 352 }
347 } 353 }
348 return; 354 return;
349 } 355 }
350 intptr_t bytes_written = Socket::Write(debug_fd, msg->buf(), msg->length()); 356 intptr_t bytes_written =
357 DebuggerConnectionImpl::Send(debug_fd, msg->buf(), msg->length());
351 ASSERT(msg->length() == bytes_written); 358 ASSERT(msg->length() == bytes_written);
352 // TODO(hausner): Error checking. Probably just shut down the debugger 359 // TODO(hausner): Error checking. Probably just shut down the debugger
353 // session if we there is an error while writing. 360 // session if we there is an error while writing.
354 } 361 }
355 362
356 363
357 void DebuggerConnectionHandler::AcceptDbgConnection(int debug_fd) { 364 void DebuggerConnectionHandler::AcceptDbgConnection(int debug_fd) {
358 AddNewDebuggerConnection(debug_fd); 365 AddNewDebuggerConnection(debug_fd);
359 { 366 {
360 MonitorLocker ml(&handler_lock_); 367 MonitorLocker ml(&handler_lock_);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 ASSERT(singleton_handler != NULL); 431 ASSERT(singleton_handler != NULL);
425 return singleton_handler; 432 return singleton_handler;
426 } 433 }
427 434
428 435
429 bool DebuggerConnectionHandler::IsConnected() { 436 bool DebuggerConnectionHandler::IsConnected() {
430 // TODO(asiva): Support multiple debugger connections. 437 // TODO(asiva): Support multiple debugger connections.
431 // Return true if a connection has been established. 438 // Return true if a connection has been established.
432 return singleton_handler != NULL; 439 return singleton_handler != NULL;
433 } 440 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dbg_connection_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698