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/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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 if (msgbuf_ != NULL) { | 291 if (msgbuf_ != NULL) { |
292 delete msgbuf_; | 292 delete msgbuf_; |
293 msgbuf_ = NULL; | 293 msgbuf_ = NULL; |
294 } | 294 } |
295 // TODO(hausner): Need to tell the VM debugger object to remove all | 295 // TODO(hausner): Need to tell the VM debugger object to remove all |
296 // breakpoints. | 296 // breakpoints. |
297 } | 297 } |
298 | 298 |
299 | 299 |
| 300 // The vm service relies on certain debugger functionality. |
| 301 void DebuggerConnectionHandler::InitForVmService() { |
| 302 MonitorLocker ml(handler_lock_); |
| 303 DbgMsgQueueList::Initialize(); |
| 304 } |
| 305 |
| 306 |
300 int DebuggerConnectionHandler::StartHandler(const char* address, | 307 int DebuggerConnectionHandler::StartHandler(const char* address, |
301 int port_number) { | 308 int port_number) { |
302 ASSERT(handler_lock_ != NULL); | 309 ASSERT(handler_lock_ != NULL); |
303 MonitorLocker ml(handler_lock_); | 310 MonitorLocker ml(handler_lock_); |
304 if (listener_fd_ != -1) { | 311 if (IsListening()) { |
305 // The debugger connection handler was already started. | 312 // The debugger connection handler was already started. |
306 return Socket::GetPort(listener_fd_); | 313 return Socket::GetPort(listener_fd_); |
307 } | 314 } |
308 | 315 |
309 // First setup breakpoint, exception and delayed breakpoint handlers. | 316 // First setup breakpoint, exception and delayed breakpoint handlers. |
310 DbgMsgQueueList::Initialize(); | 317 DbgMsgQueueList::Initialize(); |
311 | 318 |
312 // Initialize the socket implementation. | 319 // Initialize the socket implementation. |
313 if (!Socket::Initialize()) { | 320 if (!Socket::Initialize()) { |
314 FATAL("Failed initializing socket implementation."); | 321 FATAL("Failed initializing socket implementation."); |
(...skipping 11 matching lines...) Expand all Loading... |
326 delete addresses; | 333 delete addresses; |
327 port_number = Socket::GetPort(listener_fd_); | 334 port_number = Socket::GetPort(listener_fd_); |
328 DebuggerConnectionImpl::StartHandler(port_number); | 335 DebuggerConnectionImpl::StartHandler(port_number); |
329 return port_number; | 336 return port_number; |
330 } | 337 } |
331 | 338 |
332 | 339 |
333 void DebuggerConnectionHandler::WaitForConnection() { | 340 void DebuggerConnectionHandler::WaitForConnection() { |
334 ASSERT(handler_lock_ != NULL); | 341 ASSERT(handler_lock_ != NULL); |
335 MonitorLocker ml(handler_lock_); | 342 MonitorLocker ml(handler_lock_); |
| 343 if (!IsListening()) { |
| 344 // If we are only running the vm service, don't wait for |
| 345 // connections. |
| 346 return; |
| 347 } |
336 while (!IsConnected()) { | 348 while (!IsConnected()) { |
337 dart::Monitor::WaitResult res = ml.Wait(); | 349 dart::Monitor::WaitResult res = ml.Wait(); |
338 ASSERT(res == dart::Monitor::kNotified); | 350 ASSERT(res == dart::Monitor::kNotified); |
339 } | 351 } |
340 } | 352 } |
341 | 353 |
342 | 354 |
343 void DebuggerConnectionHandler::SendMsg(int debug_fd, dart::TextBuffer* msg) { | 355 void DebuggerConnectionHandler::SendMsg(int debug_fd, dart::TextBuffer* msg) { |
344 ASSERT(handler_lock_ != NULL); | 356 ASSERT(handler_lock_ != NULL); |
345 MonitorLocker ml(handler_lock_); | 357 MonitorLocker ml(handler_lock_); |
346 SendMsgHelper(debug_fd, msg); | 358 SendMsgHelper(debug_fd, msg); |
347 } | 359 } |
348 | 360 |
349 | 361 |
350 void DebuggerConnectionHandler::BroadcastMsg(dart::TextBuffer* msg) { | 362 void DebuggerConnectionHandler::BroadcastMsg(dart::TextBuffer* msg) { |
351 ASSERT(handler_lock_ != NULL); | 363 ASSERT(handler_lock_ != NULL); |
352 MonitorLocker ml(handler_lock_); | 364 MonitorLocker ml(handler_lock_); |
| 365 if (!IsListening()) { |
| 366 // If we are only running the vm service, don't try to broadcast |
| 367 // to debugger clients. |
| 368 return; |
| 369 } |
353 // TODO(asiva): Once we support connection to multiple debuggers | 370 // TODO(asiva): Once we support connection to multiple debuggers |
354 // we need to send the message to all of them. | 371 // we need to send the message to all of them. |
355 ASSERT(singleton_handler != NULL); | 372 ASSERT(singleton_handler != NULL); |
356 SendMsgHelper(singleton_handler->debug_fd(), msg); | 373 SendMsgHelper(singleton_handler->debug_fd(), msg); |
357 } | 374 } |
358 | 375 |
359 | 376 |
360 void DebuggerConnectionHandler::SendMsgHelper(int debug_fd, | 377 void DebuggerConnectionHandler::SendMsgHelper(int debug_fd, |
361 dart::TextBuffer* msg) { | 378 dart::TextBuffer* msg) { |
362 ASSERT(debug_fd >= 0); | 379 ASSERT(debug_fd >= 0); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 499 |
483 | 500 |
484 bool DebuggerConnectionHandler::IsConnected() { | 501 bool DebuggerConnectionHandler::IsConnected() { |
485 // TODO(asiva): Support multiple debugger connections. | 502 // TODO(asiva): Support multiple debugger connections. |
486 // Return true if a connection has been established. | 503 // Return true if a connection has been established. |
487 return singleton_handler != NULL; | 504 return singleton_handler != NULL; |
488 } | 505 } |
489 | 506 |
490 } // namespace bin | 507 } // namespace bin |
491 } // namespace dart | 508 } // namespace dart |
OLD | NEW |