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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 static bool IsValidJSON(const char* msg) { | 162 static bool IsValidJSON(const char* msg) { |
163 dart::JSONReader r(msg); | 163 dart::JSONReader r(msg); |
164 return r.EndOfObject() != NULL; | 164 return r.EndOfObject() != NULL; |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 void DebuggerConnectionHandler::SendError(int msg_id, | 168 void DebuggerConnectionHandler::SendError(int msg_id, |
169 const char* format, ...) { | 169 const char* err_msg) { |
170 dart::TextBuffer msg(64); | 170 dart::TextBuffer msg(64); |
171 msg.Printf("{\"id\": %d, \"error\": \"", msg_id); | 171 msg.Printf("{\"id\": %d, \"error\": \"Error: %s\"}", msg_id, err_msg); |
172 va_list args; | |
173 va_start(args, format); | |
174 msg.Printf(format, args); | |
175 va_end(args); | |
176 msg.Printf("\"}"); | |
177 Socket::Write(debugger_fd_, msg.buf(), msg.length()); | 172 Socket::Write(debugger_fd_, msg.buf(), msg.length()); |
178 // TODO(hausner): Error checking. Probably just shut down the debugger | 173 // TODO(hausner): Error checking. Probably just shut down the debugger |
179 // session if we there is an error while writing. | 174 // session if we there is an error while writing. |
180 } | 175 } |
181 | 176 |
182 | 177 |
183 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { | 178 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { |
184 int msg_id = msgbuf_->MessageId(); | 179 int msg_id = msgbuf_->MessageId(); |
185 dart::TextBuffer msg(64); | 180 dart::TextBuffer msg(64); |
186 msg.Printf("{ \"id\": %d }", msg_id); | 181 msg.Printf("{ \"id\": %d }", msg_id); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 ASSERT(params != NULL); | 214 ASSERT(params != NULL); |
220 dart::JSONReader pr(params); | 215 dart::JSONReader pr(params); |
221 pr.Seek("library"); | 216 pr.Seek("library"); |
222 ASSERT(pr.Type() == dart::JSONReader::kString); | 217 ASSERT(pr.Type() == dart::JSONReader::kString); |
223 char lib_url_chars[128]; | 218 char lib_url_chars[128]; |
224 pr.GetValueChars(lib_url_chars, sizeof(lib_url_chars)); | 219 pr.GetValueChars(lib_url_chars, sizeof(lib_url_chars)); |
225 Dart_Handle lib_url = Dart_NewString(lib_url_chars); | 220 Dart_Handle lib_url = Dart_NewString(lib_url_chars); |
226 ASSERT_NOT_ERROR(lib_url); | 221 ASSERT_NOT_ERROR(lib_url); |
227 Dart_Handle urls = Dart_GetScriptURLs(lib_url); | 222 Dart_Handle urls = Dart_GetScriptURLs(lib_url); |
228 if (Dart_IsError(urls)) { | 223 if (Dart_IsError(urls)) { |
229 SendError(msg_id, "Error: '%s'.", Dart_GetError(urls)); | 224 SendError(msg_id, Dart_GetError(urls)); |
230 return; | 225 return; |
231 } | 226 } |
232 ASSERT(Dart_IsList(urls)); | 227 ASSERT(Dart_IsList(urls)); |
233 intptr_t num_urls = 0; | 228 intptr_t num_urls = 0; |
234 Dart_ListLength(urls, &num_urls); | 229 Dart_ListLength(urls, &num_urls); |
235 msg.Printf("{ \"id\": %d, ", msg_id); | 230 msg.Printf("{ \"id\": %d, ", msg_id); |
236 msg.Printf("\"result\": { \"urls\": ["); | 231 msg.Printf("\"result\": { \"urls\": ["); |
237 for (int i = 0; i < num_urls; i++) { | 232 for (int i = 0; i < num_urls; i++) { |
238 Dart_Handle script_url = Dart_ListGetAt(urls, i); | 233 Dart_Handle script_url = Dart_ListGetAt(urls, i); |
239 ASSERT(Dart_IsString(script_url)); | 234 ASSERT(Dart_IsString(script_url)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 403 |
409 handler_started_ = true; | 404 handler_started_ = true; |
410 DebuggerConnectionImpl::StartHandler(port_number); | 405 DebuggerConnectionImpl::StartHandler(port_number); |
411 Dart_SetBreakpointHandler(BreakpointHandler); | 406 Dart_SetBreakpointHandler(BreakpointHandler); |
412 } | 407 } |
413 | 408 |
414 | 409 |
415 DebuggerConnectionHandler::~DebuggerConnectionHandler() { | 410 DebuggerConnectionHandler::~DebuggerConnectionHandler() { |
416 CloseDbgConnection(); | 411 CloseDbgConnection(); |
417 } | 412 } |
OLD | NEW |