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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 class MessageBuffer { | 48 class MessageBuffer { |
49 public: | 49 public: |
50 explicit MessageBuffer(int fd); | 50 explicit MessageBuffer(int fd); |
51 ~MessageBuffer(); | 51 ~MessageBuffer(); |
52 void ReadData(); | 52 void ReadData(); |
53 bool IsValidMessage() const; | 53 bool IsValidMessage() const; |
54 void PopMessage(); | 54 void PopMessage(); |
55 int MessageId() const; | 55 int MessageId() const; |
56 const char* Params() const; | 56 const char* Params() const; |
57 intptr_t GetIntParam(const char* name) const; | 57 intptr_t GetIntParam(const char* name) const; |
srdjan
2012/06/02 00:03:08
Could you add add a comment that the caller must f
hausner
2012/06/02 00:06:53
I can. Done.
| |
58 char* GetStringParam(const char* name) const; | |
58 char* buf() const { return buf_; } | 59 char* buf() const { return buf_; } |
59 bool Alive() const { return connection_is_alive_; } | 60 bool Alive() const { return connection_is_alive_; } |
60 | 61 |
61 private: | 62 private: |
62 static const int kInitialBufferSize = 256; | 63 static const int kInitialBufferSize = 256; |
63 char* buf_; | 64 char* buf_; |
64 int buf_length_; | 65 int buf_length_; |
65 int fd_; | 66 int fd_; |
66 int data_length_; | 67 int data_length_; |
67 bool connection_is_alive_; | 68 bool connection_is_alive_; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 127 |
127 intptr_t MessageBuffer::GetIntParam(const char* name) const { | 128 intptr_t MessageBuffer::GetIntParam(const char* name) const { |
128 const char* params = Params(); | 129 const char* params = Params(); |
129 ASSERT(params != NULL); | 130 ASSERT(params != NULL); |
130 dart::JSONReader r(params); | 131 dart::JSONReader r(params); |
131 r.Seek(name); | 132 r.Seek(name); |
132 ASSERT(r.Type() == dart::JSONReader::kInteger); | 133 ASSERT(r.Type() == dart::JSONReader::kInteger); |
133 return strtol(r.ValueChars(), NULL, 10); | 134 return strtol(r.ValueChars(), NULL, 10); |
134 } | 135 } |
135 | 136 |
137 char* MessageBuffer::GetStringParam(const char* name) const { | |
138 const char* params = Params(); | |
139 ASSERT(params != NULL); | |
140 dart::JSONReader pr(params); | |
141 pr.Seek(name); | |
142 if (pr.Type() != dart::JSONReader::kString) { | |
143 return NULL; | |
144 } | |
145 intptr_t buflen = pr.ValueLen() + 1; | |
146 char* param_chars = reinterpret_cast<char*>(malloc(buflen)); | |
147 pr.GetValueChars(param_chars, buflen); | |
148 // TODO(hausner): Decode escape sequences. | |
149 return param_chars; | |
150 } | |
136 | 151 |
137 void MessageBuffer::ReadData() { | 152 void MessageBuffer::ReadData() { |
138 ASSERT(data_length_ >= 0); | 153 ASSERT(data_length_ >= 0); |
139 ASSERT(data_length_ < buf_length_); | 154 ASSERT(data_length_ < buf_length_); |
140 int max_read = buf_length_ - data_length_ - 1; | 155 int max_read = buf_length_ - data_length_ - 1; |
141 if (max_read == 0) { | 156 if (max_read == 0) { |
142 // TODO(hausner): | 157 // TODO(hausner): |
143 // Buffer is full. What should we do if there is no valid message | 158 // Buffer is full. What should we do if there is no valid message |
144 // in the buffer? This might be possible if the client sends a message | 159 // in the buffer? This might be possible if the client sends a message |
145 // that's larger than the buffer, of if the client sends malformed | 160 // that's larger than the buffer, of if the client sends malformed |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 Dart_Handle res = Dart_StringToCString(str, &chars); | 234 Dart_Handle res = Dart_StringToCString(str, &chars); |
220 ASSERT(!Dart_IsError(res)); | 235 ASSERT(!Dart_IsError(res)); |
221 return chars; | 236 return chars; |
222 } | 237 } |
223 | 238 |
224 | 239 |
225 static int GetIntValue(Dart_Handle int_handle) { | 240 static int GetIntValue(Dart_Handle int_handle) { |
226 int64_t int64_val = -1; | 241 int64_t int64_val = -1; |
227 ASSERT(Dart_IsInteger(int_handle)); | 242 ASSERT(Dart_IsInteger(int_handle)); |
228 Dart_Handle res = Dart_IntegerToInt64(int_handle, &int64_val); | 243 Dart_Handle res = Dart_IntegerToInt64(int_handle, &int64_val); |
229 ASSERT(!Dart_IsError(res)); | 244 ASSERT_NOT_ERROR(res); |
230 // TODO(hausner): Range check. | 245 // TODO(hausner): Range check. |
231 return int64_val; | 246 return int64_val; |
232 } | 247 } |
233 | 248 |
234 | 249 |
235 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { | 250 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { |
236 int msg_id = msgbuf_->MessageId(); | 251 int msg_id = msgbuf_->MessageId(); |
237 dart::TextBuffer msg(64); | 252 dart::TextBuffer msg(64); |
238 msg.Printf("{ \"id\": %d }", msg_id); | 253 msg.Printf("{ \"id\": %d }", msg_id); |
239 SendMsg(&msg); | 254 SendMsg(&msg); |
(...skipping 15 matching lines...) Expand all Loading... | |
255 } | 270 } |
256 | 271 |
257 | 272 |
258 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) { | 273 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) { |
259 Dart_Handle res = Dart_SetStepOver(); | 274 Dart_Handle res = Dart_SetStepOver(); |
260 ASSERT_NOT_ERROR(res); | 275 ASSERT_NOT_ERROR(res); |
261 HandleResumeCmd(json_msg); | 276 HandleResumeCmd(json_msg); |
262 } | 277 } |
263 | 278 |
264 | 279 |
280 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) { | |
281 ASSERT(Dart_IsString8(str)); | |
282 intptr_t str_len = 0; | |
283 Dart_Handle res = Dart_StringLength(str, &str_len); | |
284 ASSERT_NOT_ERROR(res); | |
285 uint8_t* codepoints = reinterpret_cast<uint8_t*>(malloc(str_len)); | |
286 ASSERT(codepoints != NULL); | |
287 intptr_t actual_len = str_len; | |
288 res = Dart_StringGet8(str, codepoints, &actual_len); | |
289 ASSERT(str_len == actual_len); | |
290 buf->Printf("\""); | |
291 buf->PrintJsonString8(codepoints, str_len); | |
292 buf->Printf("\""); | |
293 free(codepoints); | |
294 } | |
295 | |
296 | |
297 static void FormatErrorMsg(dart::TextBuffer* buf, Dart_Handle err) { | |
298 // TODO(hausner): Turn message into Dart string and | |
299 // properly encode the message. | |
300 ASSERT(Dart_IsError(err)); | |
301 const char* msg = Dart_GetError(err); | |
302 buf->Printf("\"%s\"", msg); | |
303 } | |
304 | |
305 | |
265 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) { | 306 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) { |
266 int msg_id = msgbuf_->MessageId(); | 307 int msg_id = msgbuf_->MessageId(); |
267 dart::TextBuffer msg(64); | 308 dart::TextBuffer msg(64); |
268 intptr_t lib_id = msgbuf_->GetIntParam("libraryId"); | 309 intptr_t lib_id = msgbuf_->GetIntParam("libraryId"); |
269 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); | 310 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); |
270 ASSERT_NOT_ERROR(lib_url); | 311 ASSERT_NOT_ERROR(lib_url); |
271 Dart_Handle urls = Dart_GetScriptURLs(lib_url); | 312 Dart_Handle urls = Dart_GetScriptURLs(lib_url); |
272 if (Dart_IsError(urls)) { | 313 if (Dart_IsError(urls)) { |
273 SendError(msg_id, Dart_GetError(urls)); | 314 SendError(msg_id, Dart_GetError(urls)); |
274 return; | 315 return; |
275 } | 316 } |
276 ASSERT(Dart_IsList(urls)); | 317 ASSERT(Dart_IsList(urls)); |
277 intptr_t num_urls = 0; | 318 intptr_t num_urls = 0; |
278 Dart_ListLength(urls, &num_urls); | 319 Dart_ListLength(urls, &num_urls); |
279 msg.Printf("{ \"id\": %d, ", msg_id); | 320 msg.Printf("{ \"id\": %d, ", msg_id); |
280 msg.Printf("\"result\": { \"urls\": ["); | 321 msg.Printf("\"result\": { \"urls\": ["); |
281 for (int i = 0; i < num_urls; i++) { | 322 for (int i = 0; i < num_urls; i++) { |
282 Dart_Handle script_url = Dart_ListGetAt(urls, i); | 323 Dart_Handle script_url = Dart_ListGetAt(urls, i); |
283 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", GetStringChars(script_url)); | 324 if (i > 0) { |
325 msg.Printf(","); | |
326 } | |
327 FormatEncodedString(&msg, script_url); | |
284 } | 328 } |
285 msg.Printf("] }}"); | 329 msg.Printf("]}}"); |
330 SendMsg(&msg); | |
331 } | |
332 | |
333 | |
334 void DebuggerConnectionHandler::HandleGetSourceCmd(const char* json_msg) { | |
335 int msg_id = msgbuf_->MessageId(); | |
336 dart::TextBuffer msg(64); | |
337 intptr_t lib_id = msgbuf_->GetIntParam("libraryId"); | |
338 char* url_chars = msgbuf_->GetStringParam("url"); | |
339 ASSERT(url_chars != NULL); | |
340 Dart_Handle url = Dart_NewString(url_chars); | |
341 ASSERT_NOT_ERROR(url); | |
342 free(url_chars); | |
343 url_chars = NULL; | |
344 Dart_Handle source = Dart_ScriptGetSource(lib_id, url); | |
345 if (Dart_IsError(source)) { | |
346 SendError(msg_id, Dart_GetError(source)); | |
347 return; | |
348 } | |
349 msg.Printf("{ \"id\": %d, ", msg_id); | |
350 msg.Printf("\"result\": { \"text\": "); | |
351 FormatEncodedString(&msg, source); | |
352 msg.Printf("}}"); | |
286 SendMsg(&msg); | 353 SendMsg(&msg); |
287 } | 354 } |
288 | 355 |
289 | 356 |
290 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) { | 357 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) { |
291 int msg_id = msgbuf_->MessageId(); | 358 int msg_id = msgbuf_->MessageId(); |
292 dart::TextBuffer msg(64); | 359 dart::TextBuffer msg(64); |
293 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id); | 360 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id); |
294 Dart_Handle lib_ids = Dart_GetLibraryIds(); | 361 Dart_Handle lib_ids = Dart_GetLibraryIds(); |
295 ASSERT_NOT_ERROR(lib_ids); | 362 ASSERT_NOT_ERROR(lib_ids); |
296 intptr_t num_libs; | 363 intptr_t num_libs; |
297 Dart_Handle res = Dart_ListLength(lib_ids, &num_libs); | 364 Dart_Handle res = Dart_ListLength(lib_ids, &num_libs); |
298 ASSERT_NOT_ERROR(res); | 365 ASSERT_NOT_ERROR(res); |
299 for (int i = 0; i < num_libs; i++) { | 366 for (int i = 0; i < num_libs; i++) { |
300 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i); | 367 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i); |
301 ASSERT(Dart_IsInteger(lib_id_handle)); | 368 ASSERT(Dart_IsInteger(lib_id_handle)); |
302 int lib_id = GetIntValue(lib_id_handle); | 369 int lib_id = GetIntValue(lib_id_handle); |
303 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); | 370 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); |
304 ASSERT_NOT_ERROR(lib_url); | 371 ASSERT_NOT_ERROR(lib_url); |
305 ASSERT(!Dart_IsNull(lib_url)); | |
306 ASSERT(Dart_IsString(lib_url)); | 372 ASSERT(Dart_IsString(lib_url)); |
307 char const* chars = NULL; | 373 msg.Printf("%s{\"id\":%d,\"url\":", (i == 0) ? "" : ", ", lib_id); |
308 Dart_StringToCString(lib_url, &chars); | 374 FormatEncodedString(&msg, lib_url); |
309 msg.Printf("%s{\"id\":%d,\"url\":\"%s\"}", | 375 msg.Printf("}"); |
310 (i == 0) ? "" : ", ", lib_id, chars); | |
311 } | 376 } |
312 msg.Printf("]}}"); | 377 msg.Printf("]}}"); |
313 SendMsg(&msg); | 378 SendMsg(&msg); |
314 } | 379 } |
315 | 380 |
316 | 381 |
317 static void FormatField(dart::TextBuffer* buf, | 382 static void FormatField(dart::TextBuffer* buf, |
318 Dart_Handle object_name, | 383 Dart_Handle object_name, |
319 Dart_Handle object) { | 384 Dart_Handle object) { |
320 ASSERT(Dart_IsString(object_name)); | 385 ASSERT(Dart_IsString(object_name)); |
321 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); | 386 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); |
322 intptr_t obj_id = Dart_CacheObject(object); | 387 intptr_t obj_id = Dart_CacheObject(object); |
323 ASSERT(obj_id >= 0); | 388 ASSERT(obj_id >= 0); |
324 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); | 389 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); |
325 const char* kind = "object"; | 390 const char* kind = "object"; |
326 if (Dart_IsInteger(object)) { | 391 if (Dart_IsInteger(object)) { |
327 kind = "integer"; | 392 kind = "integer"; |
328 } else if (Dart_IsString(object)) { | 393 } else if (Dart_IsString(object)) { |
329 kind = "string"; | 394 kind = "string"; |
330 } else if (Dart_IsBoolean(object)) { | 395 } else if (Dart_IsBoolean(object)) { |
331 kind = "boolean"; | 396 kind = "boolean"; |
332 } | 397 } |
333 buf->Printf("\"kind\":\"%s\",", kind); | 398 buf->Printf("\"kind\":\"%s\",", kind); |
334 Dart_Handle text = Dart_ToString(object); | 399 buf->Printf("\"text\":"); |
335 buf->Printf("\"text\":\"%s\"}}", GetStringChars(text)); | 400 Dart_Handle text; |
401 if (Dart_IsNull(object)) { | |
402 text = Dart_Null(); | |
403 } else { | |
404 text = Dart_ToString(object); | |
405 } | |
406 if (Dart_IsNull(text)) { | |
407 buf->Printf("null"); | |
408 } else if (Dart_IsError(text)) { | |
409 FormatErrorMsg(buf, text); | |
410 } else { | |
411 FormatEncodedString(buf, text); | |
412 } | |
413 buf->Printf("}}"); | |
336 } | 414 } |
337 | 415 |
338 | 416 |
339 static void FormatFieldList(dart::TextBuffer* buf, | 417 static void FormatFieldList(dart::TextBuffer* buf, |
340 Dart_Handle obj_list) { | 418 Dart_Handle obj_list) { |
341 ASSERT(Dart_IsList(obj_list)); | 419 ASSERT(Dart_IsList(obj_list)); |
342 intptr_t list_length = 0; | 420 intptr_t list_length = 0; |
343 Dart_Handle res = Dart_ListLength(obj_list, &list_length); | 421 Dart_Handle res = Dart_ListLength(obj_list, &list_length); |
344 ASSERT_NOT_ERROR(res); | 422 ASSERT_NOT_ERROR(res); |
345 ASSERT(list_length % 2 == 0); | 423 ASSERT(list_length % 2 == 0); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 FormatFieldList(buf, static_fields); | 455 FormatFieldList(buf, static_fields); |
378 buf->Printf("}"); | 456 buf->Printf("}"); |
379 return NULL; | 457 return NULL; |
380 } | 458 } |
381 | 459 |
382 | 460 |
383 static const char* FormatLibraryProps(dart::TextBuffer* buf, | 461 static const char* FormatLibraryProps(dart::TextBuffer* buf, |
384 intptr_t lib_id) { | 462 intptr_t lib_id) { |
385 Dart_Handle url = Dart_GetLibraryURL(lib_id); | 463 Dart_Handle url = Dart_GetLibraryURL(lib_id); |
386 RETURN_IF_ERROR(url); | 464 RETURN_IF_ERROR(url); |
387 buf->Printf("{\"url\":\"%s\",", GetStringChars(url)); | 465 buf->Printf("{\"url\":"); |
466 FormatEncodedString(buf, url); | |
388 | 467 |
389 // Imports and prefixes. | 468 // Imports and prefixes. |
390 Dart_Handle import_list = Dart_GetLibraryImports(lib_id); | 469 Dart_Handle import_list = Dart_GetLibraryImports(lib_id); |
391 RETURN_IF_ERROR(import_list); | 470 RETURN_IF_ERROR(import_list); |
392 ASSERT(Dart_IsList(import_list)); | 471 ASSERT(Dart_IsList(import_list)); |
393 intptr_t list_length = 0; | 472 intptr_t list_length = 0; |
394 Dart_Handle res = Dart_ListLength(import_list, &list_length); | 473 Dart_Handle res = Dart_ListLength(import_list, &list_length); |
395 RETURN_IF_ERROR(res); | 474 RETURN_IF_ERROR(res); |
396 buf->Printf("\"imports\":["); | 475 buf->Printf(",\"imports\":["); |
397 for (int i = 0; i + 1 < list_length; i += 2) { | 476 for (int i = 0; i + 1 < list_length; i += 2) { |
398 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1); | 477 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1); |
399 ASSERT_NOT_ERROR(lib_id); | 478 ASSERT_NOT_ERROR(lib_id); |
400 buf->Printf("%s{\"libraryId\":%d,", | 479 buf->Printf("%s{\"libraryId\":%d,", |
401 (i > 0) ? ",": "", | 480 (i > 0) ? ",": "", |
402 GetIntValue(lib_id)); | 481 GetIntValue(lib_id)); |
403 | 482 |
404 Dart_Handle name = Dart_ListGetAt(import_list, i); | 483 Dart_Handle name = Dart_ListGetAt(import_list, i); |
405 ASSERT_NOT_ERROR(name); | 484 ASSERT_NOT_ERROR(name); |
406 buf->Printf("\"prefix\":\"%s\"}", | 485 buf->Printf("\"prefix\":\"%s\"}", |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 msg->Printf("\"callFrames\" : [ "); | 522 msg->Printf("\"callFrames\" : [ "); |
444 for (int i = 0; i < trace_len; i++) { | 523 for (int i = 0; i < trace_len; i++) { |
445 Dart_ActivationFrame frame; | 524 Dart_ActivationFrame frame; |
446 res = Dart_GetActivationFrame(trace, i, &frame); | 525 res = Dart_GetActivationFrame(trace, i, &frame); |
447 ASSERT_NOT_ERROR(res); | 526 ASSERT_NOT_ERROR(res); |
448 Dart_Handle func_name; | 527 Dart_Handle func_name; |
449 Dart_Handle script_url; | 528 Dart_Handle script_url; |
450 intptr_t line_number = 0; | 529 intptr_t line_number = 0; |
451 res = Dart_ActivationFrameInfo( | 530 res = Dart_ActivationFrameInfo( |
452 frame, &func_name, &script_url, &line_number); | 531 frame, &func_name, &script_url, &line_number); |
532 | |
453 ASSERT_NOT_ERROR(res); | 533 ASSERT_NOT_ERROR(res); |
454 ASSERT(Dart_IsString(func_name)); | 534 ASSERT(Dart_IsString(func_name)); |
455 const char* func_name_chars; | 535 msg->Printf("%s{\"functionName\":", (i > 0) ? "," : ""); |
456 Dart_StringToCString(func_name, &func_name_chars); | 536 FormatEncodedString(msg, func_name); |
457 msg->Printf("%s { \"functionName\": \"%s\" , ", | 537 |
458 i > 0 ? "," : "", | |
459 func_name_chars); | |
460 ASSERT(Dart_IsString(script_url)); | 538 ASSERT(Dart_IsString(script_url)); |
461 const char* script_url_chars; | 539 msg->Printf(",\"location\": { \"url\":"); |
462 Dart_StringToCString(script_url, &script_url_chars); | 540 FormatEncodedString(msg, script_url); |
463 msg->Printf("\"location\": { \"url\": \"%s\", \"lineNumber\":%d},", | 541 msg->Printf(",\"lineNumber\":%d},", line_number); |
464 script_url_chars, line_number); | 542 |
465 Dart_Handle locals = Dart_GetLocalVariables(frame); | 543 Dart_Handle locals = Dart_GetLocalVariables(frame); |
466 ASSERT_NOT_ERROR(locals); | 544 ASSERT_NOT_ERROR(locals); |
467 msg->Printf("\"locals\":"); | 545 msg->Printf("\"locals\":"); |
468 FormatFieldList(msg, locals); | 546 FormatFieldList(msg, locals); |
469 msg->Printf("}"); | 547 msg->Printf("}"); |
470 } | 548 } |
471 msg->Printf("]"); | 549 msg->Printf("]"); |
472 } | 550 } |
473 | 551 |
474 | 552 |
475 void DebuggerConnectionHandler::HandleGetStackTraceCmd(const char* json_msg) { | 553 void DebuggerConnectionHandler::HandleGetStackTraceCmd(const char* json_msg) { |
476 int msg_id = msgbuf_->MessageId(); | 554 int msg_id = msgbuf_->MessageId(); |
477 Dart_StackTrace trace; | 555 Dart_StackTrace trace; |
478 Dart_Handle res = Dart_GetStackTrace(&trace); | 556 Dart_Handle res = Dart_GetStackTrace(&trace); |
479 ASSERT_NOT_ERROR(res); | 557 ASSERT_NOT_ERROR(res); |
480 dart::TextBuffer msg(128); | 558 dart::TextBuffer msg(128); |
481 msg.Printf("{ \"id\": %d, \"result\": {", msg_id); | 559 msg.Printf("{ \"id\": %d, \"result\": {", msg_id); |
482 FormatCallFrames(&msg, trace); | 560 FormatCallFrames(&msg, trace); |
483 msg.Printf("}}"); | 561 msg.Printf("}}"); |
484 SendMsg(&msg); | 562 SendMsg(&msg); |
485 } | 563 } |
486 | 564 |
487 | 565 |
488 void DebuggerConnectionHandler::HandleSetBpCmd(const char* json_msg) { | 566 void DebuggerConnectionHandler::HandleSetBpCmd(const char* json_msg) { |
489 int msg_id = msgbuf_->MessageId(); | 567 int msg_id = msgbuf_->MessageId(); |
490 const char* params = msgbuf_->Params(); | 568 char* url_chars = msgbuf_->GetStringParam("url"); |
491 ASSERT(params != NULL); | 569 ASSERT(url_chars != NULL); |
492 dart::JSONReader pr(params); | |
493 pr.Seek("url"); | |
494 ASSERT(pr.Type() == dart::JSONReader::kString); | |
495 char url_chars[128]; | |
496 pr.GetValueChars(url_chars, sizeof(url_chars)); | |
497 Dart_Handle url = Dart_NewString(url_chars); | 570 Dart_Handle url = Dart_NewString(url_chars); |
498 ASSERT_NOT_ERROR(url); | 571 ASSERT_NOT_ERROR(url); |
499 pr.Seek("line"); | 572 free(url_chars); |
500 ASSERT(pr.Type() == dart::JSONReader::kInteger); | 573 url_chars = NULL; |
501 intptr_t line_number = atoi(pr.ValueChars()); | 574 intptr_t line_number = msgbuf_->GetIntParam("line"); |
502 Dart_Handle bp_id = Dart_SetBreakpoint(url, line_number); | 575 Dart_Handle bp_id = Dart_SetBreakpoint(url, line_number); |
503 if (Dart_IsError(bp_id)) { | 576 if (Dart_IsError(bp_id)) { |
504 SendError(msg_id, Dart_GetError(bp_id)); | 577 SendError(msg_id, Dart_GetError(bp_id)); |
505 return; | 578 return; |
506 } | 579 } |
507 ASSERT(Dart_IsInteger(bp_id)); | 580 ASSERT(Dart_IsInteger(bp_id)); |
508 uint64_t bp_id_value; | 581 uint64_t bp_id_value; |
509 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value); | 582 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value); |
510 ASSERT_NOT_ERROR(res); | 583 ASSERT_NOT_ERROR(res); |
511 dart::TextBuffer msg(64); | 584 dart::TextBuffer msg(64); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 | 660 |
588 | 661 |
589 void DebuggerConnectionHandler::HandleMessages() { | 662 void DebuggerConnectionHandler::HandleMessages() { |
590 static JSONDebuggerCommand debugger_commands[] = { | 663 static JSONDebuggerCommand debugger_commands[] = { |
591 { "resume", HandleResumeCmd }, | 664 { "resume", HandleResumeCmd }, |
592 { "getLibraries", HandleGetLibrariesCmd }, | 665 { "getLibraries", HandleGetLibrariesCmd }, |
593 { "getClassProperties", HandleGetClassPropsCmd }, | 666 { "getClassProperties", HandleGetClassPropsCmd }, |
594 { "getLibraryProperties", HandleGetLibPropsCmd }, | 667 { "getLibraryProperties", HandleGetLibPropsCmd }, |
595 { "getObjectProperties", HandleGetObjPropsCmd }, | 668 { "getObjectProperties", HandleGetObjPropsCmd }, |
596 { "getScriptURLs", HandleGetScriptURLsCmd }, | 669 { "getScriptURLs", HandleGetScriptURLsCmd }, |
670 { "getScriptSource", HandleGetSourceCmd }, | |
597 { "getStackTrace", HandleGetStackTraceCmd }, | 671 { "getStackTrace", HandleGetStackTraceCmd }, |
598 { "setBreakpoint", HandleSetBpCmd }, | 672 { "setBreakpoint", HandleSetBpCmd }, |
599 { "removeBreakpoint", HandleRemBpCmd }, | 673 { "removeBreakpoint", HandleRemBpCmd }, |
600 { "stepInto", HandleStepIntoCmd }, | 674 { "stepInto", HandleStepIntoCmd }, |
601 { "stepOut", HandleStepOutCmd }, | 675 { "stepOut", HandleStepOutCmd }, |
602 { "stepOver", HandleStepOverCmd }, | 676 { "stepOver", HandleStepOverCmd }, |
603 { NULL, NULL } | 677 { NULL, NULL } |
604 }; | 678 }; |
605 | 679 |
606 for (;;) { | 680 for (;;) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 Dart_ExitScope(); | 749 Dart_ExitScope(); |
676 } | 750 } |
677 | 751 |
678 | 752 |
679 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id, | 753 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id, |
680 Dart_Handle url, | 754 Dart_Handle url, |
681 intptr_t line_number) { | 755 intptr_t line_number) { |
682 Dart_EnterScope(); | 756 Dart_EnterScope(); |
683 dart::TextBuffer msg(128); | 757 dart::TextBuffer msg(128); |
684 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {"); | 758 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {"); |
685 msg.Printf("\"breakpointId\": %d, ", bp_id); | 759 msg.Printf("\"breakpointId\": %d, \"url\":", bp_id); |
686 char const* url_chars; | 760 FormatEncodedString(&msg, url); |
687 Dart_StringToCString(url, &url_chars); | 761 msg.Printf(",\"line\": %d }}", line_number); |
688 msg.Printf("\"url\": \"%s\", ", url_chars); | |
689 msg.Printf("\"line\": %d }}", line_number); | |
690 QueueMsg(&msg); | 762 QueueMsg(&msg); |
691 Dart_ExitScope(); | 763 Dart_ExitScope(); |
692 } | 764 } |
693 | 765 |
694 | 766 |
695 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) { | 767 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) { |
696 debugger_fd_ = debugger_fd; | 768 debugger_fd_ = debugger_fd; |
697 ASSERT(msgbuf_ == NULL); | 769 ASSERT(msgbuf_ == NULL); |
698 msgbuf_ = new MessageBuffer(debugger_fd_); | 770 msgbuf_ = new MessageBuffer(debugger_fd_); |
699 { | 771 { |
(...skipping 27 matching lines...) Expand all Loading... | |
727 handler_started_ = true; | 799 handler_started_ = true; |
728 DebuggerConnectionImpl::StartHandler(port_number); | 800 DebuggerConnectionImpl::StartHandler(port_number); |
729 Dart_SetBreakpointHandler(BreakpointHandler); | 801 Dart_SetBreakpointHandler(BreakpointHandler); |
730 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); | 802 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); |
731 } | 803 } |
732 | 804 |
733 | 805 |
734 DebuggerConnectionHandler::~DebuggerConnectionHandler() { | 806 DebuggerConnectionHandler::~DebuggerConnectionHandler() { |
735 CloseDbgConnection(); | 807 CloseDbgConnection(); |
736 } | 808 } |
OLD | NEW |