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/dartutils.h" | 6 #include "bin/dartutils.h" |
7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
8 #include "bin/thread.h" | 8 #include "bin/thread.h" |
9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
10 | 10 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 | 196 |
197 static bool IsValidJSON(const char* msg) { | 197 static bool IsValidJSON(const char* msg) { |
198 dart::JSONReader r(msg); | 198 dart::JSONReader r(msg); |
199 return r.EndOfObject() != NULL; | 199 return r.EndOfObject() != NULL; |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 void DebuggerConnectionHandler::SendMsg(dart::TextBuffer* msg) { | 203 void DebuggerConnectionHandler::SendMsg(dart::TextBuffer* msg) { |
204 ASSERT(debugger_fd_ >= 0); | 204 ASSERT(debugger_fd_ >= 0); |
205 Socket::Write(debugger_fd_, msg->buf(), msg->length()); | 205 ASSERT(IsValidJSON(msg->buf())); |
| 206 // Sending messages in short pieces can be used to stress test the |
| 207 // debugger front-end's message handling code. |
| 208 const bool send_in_pieces = false; |
| 209 if (send_in_pieces) { |
| 210 intptr_t remaining = msg->length(); |
| 211 intptr_t sent = 0; |
| 212 const intptr_t max_piece_len = 122; // Pretty arbitrary, not a power of 2. |
| 213 dart::Monitor sleep; |
| 214 while (remaining > 0) { |
| 215 intptr_t piece_len = remaining; |
| 216 if (piece_len > max_piece_len) { |
| 217 piece_len = max_piece_len; |
| 218 } |
| 219 intptr_t written = |
| 220 Socket::Write(debugger_fd_, msg->buf() + sent, piece_len); |
| 221 ASSERT(written == piece_len); |
| 222 sent += written; |
| 223 remaining -= written; |
| 224 // Wait briefly so the OS does not coalesce message fragments. |
| 225 { |
| 226 MonitorLocker ml(&sleep); |
| 227 ml.Wait(10); |
| 228 } |
| 229 } |
| 230 return; |
| 231 } |
| 232 intptr_t bytes_written = |
| 233 Socket::Write(debugger_fd_, msg->buf(), msg->length()); |
| 234 ASSERT(msg->length() == bytes_written); |
206 // TODO(hausner): Error checking. Probably just shut down the debugger | 235 // TODO(hausner): Error checking. Probably just shut down the debugger |
207 // session if we there is an error while writing. | 236 // session if we there is an error while writing. |
208 } | 237 } |
209 | 238 |
210 | 239 |
211 void DebuggerConnectionHandler::QueueMsg(dart::TextBuffer* msg) { | 240 void DebuggerConnectionHandler::QueueMsg(dart::TextBuffer* msg) { |
212 queued_messages_.Printf("%s", msg->buf()); | 241 queued_messages_.Printf("%s", msg->buf()); |
213 } | 242 } |
214 | 243 |
215 | 244 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 } | 747 } |
719 } | 748 } |
720 | 749 |
721 | 750 |
722 void DebuggerConnectionHandler::SendBreakpointEvent(Dart_Breakpoint bpt, | 751 void DebuggerConnectionHandler::SendBreakpointEvent(Dart_Breakpoint bpt, |
723 Dart_StackTrace trace) { | 752 Dart_StackTrace trace) { |
724 dart::TextBuffer msg(128); | 753 dart::TextBuffer msg(128); |
725 msg.Printf("{ \"event\": \"paused\", \"params\": { "); | 754 msg.Printf("{ \"event\": \"paused\", \"params\": { "); |
726 FormatCallFrames(&msg, trace); | 755 FormatCallFrames(&msg, trace); |
727 msg.Printf("}}"); | 756 msg.Printf("}}"); |
728 Socket::Write(debugger_fd_, msg.buf(), msg.length()); | 757 SendMsg(&msg); |
729 ASSERT(IsValidJSON(msg.buf())); | |
730 } | 758 } |
731 | 759 |
732 | 760 |
733 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt, | 761 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt, |
734 Dart_StackTrace trace) { | 762 Dart_StackTrace trace) { |
735 { | 763 { |
736 MonitorLocker ml(&is_connected_); | 764 MonitorLocker ml(&is_connected_); |
737 while (!IsConnected()) { | 765 while (!IsConnected()) { |
738 printf("Waiting for debugger connection...\n"); | 766 printf("Waiting for debugger connection...\n"); |
739 dart::Monitor::WaitResult res = ml.Wait(dart::Monitor::kNoTimeout); | 767 dart::Monitor::WaitResult res = ml.Wait(dart::Monitor::kNoTimeout); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 handler_started_ = true; | 828 handler_started_ = true; |
801 DebuggerConnectionImpl::StartHandler(port_number); | 829 DebuggerConnectionImpl::StartHandler(port_number); |
802 Dart_SetBreakpointHandler(BreakpointHandler); | 830 Dart_SetBreakpointHandler(BreakpointHandler); |
803 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); | 831 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); |
804 } | 832 } |
805 | 833 |
806 | 834 |
807 DebuggerConnectionHandler::~DebuggerConnectionHandler() { | 835 DebuggerConnectionHandler::~DebuggerConnectionHandler() { |
808 CloseDbgConnection(); | 836 CloseDbgConnection(); |
809 } | 837 } |
OLD | NEW |