| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 struct JSONDebuggerCommand { | 174 struct JSONDebuggerCommand { |
| 175 const char* cmd_string; | 175 const char* cmd_string; |
| 176 CommandHandler handler_function; | 176 CommandHandler handler_function; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 | 179 |
| 180 void DebuggerConnectionHandler::HandleMessages() { | 180 void DebuggerConnectionHandler::HandleMessages() { |
| 181 static JSONDebuggerCommand generic_debugger_commands[] = { | 181 static JSONDebuggerCommand generic_debugger_commands[] = { |
| 182 { "interrupt", HandleInterruptCmd }, | 182 { "interrupt", HandleInterruptCmd }, |
| 183 { "isolates", HandleIsolatesListCmd }, | 183 { "getIsolateIds", HandleIsolatesListCmd }, |
| 184 { NULL, NULL } | 184 { NULL, NULL } |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 for (;;) { | 187 for (;;) { |
| 188 // Read a message. | 188 // Read a message. |
| 189 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) { | 189 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) { |
| 190 msgbuf_->ReadData(); | 190 msgbuf_->ReadData(); |
| 191 } | 191 } |
| 192 if (!msgbuf_->Alive()) { | 192 if (!msgbuf_->Alive()) { |
| 193 return; | 193 return; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 dart::TextBuffer msg(64); | 397 dart::TextBuffer msg(64); |
| 398 msg.Printf("{ \"id\": %d }", msg_id); | 398 msg.Printf("{ \"id\": %d }", msg_id); |
| 399 in_msg->SendReply(&msg); | 399 in_msg->SendReply(&msg); |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 void DebuggerConnectionHandler::HandleIsolatesListCmd(DbgMessage* in_msg) { | 403 void DebuggerConnectionHandler::HandleIsolatesListCmd(DbgMessage* in_msg) { |
| 404 MessageParser msg_parser(in_msg->buffer(), in_msg->buffer_len()); | 404 MessageParser msg_parser(in_msg->buffer(), in_msg->buffer_len()); |
| 405 int msg_id = msg_parser.MessageId(); | 405 int msg_id = msg_parser.MessageId(); |
| 406 ASSERT(msg_id >= 0); | 406 ASSERT(msg_id >= 0); |
| 407 in_msg->SendErrorReply(msg_id, "isolate list command unimplemented"); | 407 dart::TextBuffer msg(64); |
| 408 msg.Printf("{ \"id\": %d, \"result\": { \"isolateIds\": [", msg_id); |
| 409 DbgMsgQueueList::ListIsolateIds(&msg); |
| 410 msg.Printf("]}}"); |
| 411 in_msg->SendReply(&msg); |
| 408 } | 412 } |
| 409 | 413 |
| 410 | 414 |
| 411 void DebuggerConnectionHandler::AddNewDebuggerConnection(int debug_fd) { | 415 void DebuggerConnectionHandler::AddNewDebuggerConnection(int debug_fd) { |
| 412 // TODO(asiva): Support multiple debugger connections, for now we just | 416 // TODO(asiva): Support multiple debugger connections, for now we just |
| 413 // create one handler, store it in a static variable and use it. | 417 // create one handler, store it in a static variable and use it. |
| 414 ASSERT(singleton_handler == NULL); | 418 ASSERT(singleton_handler == NULL); |
| 415 singleton_handler = new DebuggerConnectionHandler(debug_fd); | 419 singleton_handler = new DebuggerConnectionHandler(debug_fd); |
| 416 } | 420 } |
| 417 | 421 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 431 ASSERT(singleton_handler != NULL); | 435 ASSERT(singleton_handler != NULL); |
| 432 return singleton_handler; | 436 return singleton_handler; |
| 433 } | 437 } |
| 434 | 438 |
| 435 | 439 |
| 436 bool DebuggerConnectionHandler::IsConnected() { | 440 bool DebuggerConnectionHandler::IsConnected() { |
| 437 // TODO(asiva): Support multiple debugger connections. | 441 // TODO(asiva): Support multiple debugger connections. |
| 438 // Return true if a connection has been established. | 442 // Return true if a connection has been established. |
| 439 return singleton_handler != NULL; | 443 return singleton_handler != NULL; |
| 440 } | 444 } |
| OLD | NEW |