| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/service.h" | 5 #include "vm/service.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/coverage.h" | 10 #include "vm/coverage.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 struct RootMessageHandlerEntry { | 477 struct RootMessageHandlerEntry { |
| 478 const char* command; | 478 const char* command; |
| 479 RootMessageHandler handler; | 479 RootMessageHandler handler; |
| 480 }; | 480 }; |
| 481 | 481 |
| 482 static RootMessageHandler FindRootMessageHandler(const char* command); | 482 static RootMessageHandler FindRootMessageHandler(const char* command); |
| 483 | 483 |
| 484 | 484 |
| 485 static void PrintArgumentsAndOptions(const JSONObject& obj, JSONStream* js) { | 485 static void PrintArgumentsAndOptions(const JSONObject& obj, JSONStream* js) { |
| 486 JSONObject jsobj(&obj, "message"); | 486 JSONObject jsobj(&obj, "request"); |
| 487 { | 487 { |
| 488 JSONArray jsarr(&jsobj, "arguments"); | 488 JSONArray jsarr(&jsobj, "arguments"); |
| 489 for (intptr_t i = 0; i < js->num_arguments(); i++) { | 489 for (intptr_t i = 0; i < js->num_arguments(); i++) { |
| 490 jsarr.AddValue(js->GetArgument(i)); | 490 jsarr.AddValue(js->GetArgument(i)); |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 { | 493 { |
| 494 JSONArray jsarr(&jsobj, "option_keys"); | 494 JSONArray jsarr(&jsobj, "option_keys"); |
| 495 for (intptr_t i = 0; i < js->num_options(); i++) { | 495 for (intptr_t i = 0; i < js->num_options(); i++) { |
| 496 jsarr.AddValue(js->GetOptionKey(i)); | 496 jsarr.AddValue(js->GetOptionKey(i)); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 { | 499 { |
| 500 JSONArray jsarr(&jsobj, "option_values"); | 500 JSONArray jsarr(&jsobj, "option_values"); |
| 501 for (intptr_t i = 0; i < js->num_options(); i++) { | 501 for (intptr_t i = 0; i < js->num_options(); i++) { |
| 502 jsarr.AddValue(js->GetOptionValue(i)); | 502 jsarr.AddValue(js->GetOptionValue(i)); |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 | 507 |
| 508 static void PrintError(JSONStream* js, const char* format, ...) { | 508 static void PrintError(JSONStream* js, |
| 509 const char* format, ...) { |
| 509 Isolate* isolate = Isolate::Current(); | 510 Isolate* isolate = Isolate::Current(); |
| 510 | 511 |
| 511 va_list args; | 512 va_list args; |
| 512 va_start(args, format); | 513 va_start(args, format); |
| 513 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 514 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 514 va_end(args); | 515 va_end(args); |
| 515 | 516 |
| 516 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 517 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 517 va_list args2; | 518 va_list args2; |
| 518 va_start(args2, format); | 519 va_start(args2, format); |
| 519 OS::VSNPrint(buffer, (len + 1), format, args2); | 520 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 520 va_end(args2); | 521 va_end(args2); |
| 521 | 522 |
| 522 JSONObject jsobj(js); | 523 JSONObject jsobj(js); |
| 523 jsobj.AddProperty("type", "Error"); | 524 jsobj.AddProperty("type", "Error"); |
| 524 jsobj.AddProperty("text", buffer); | 525 jsobj.AddProperty("id", ""); |
| 526 jsobj.AddProperty("message", buffer); |
| 525 PrintArgumentsAndOptions(jsobj, js); | 527 PrintArgumentsAndOptions(jsobj, js); |
| 526 } | 528 } |
| 527 | 529 |
| 530 |
| 531 static void PrintErrorWithKind(JSONStream* js, |
| 532 const char* kind, |
| 533 const char* format, ...) { |
| 534 Isolate* isolate = Isolate::Current(); |
| 535 |
| 536 va_list args; |
| 537 va_start(args, format); |
| 538 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 539 va_end(args); |
| 540 |
| 541 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 542 va_list args2; |
| 543 va_start(args2, format); |
| 544 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 545 va_end(args2); |
| 546 |
| 547 JSONObject jsobj(js); |
| 548 jsobj.AddProperty("type", "Error"); |
| 549 jsobj.AddProperty("id", ""); |
| 550 jsobj.AddProperty("kind", kind); |
| 551 jsobj.AddProperty("message", buffer); |
| 552 PrintArgumentsAndOptions(jsobj, js); |
| 553 } |
| 554 |
| 528 | 555 |
| 529 void Service::HandleIsolateMessage(Isolate* isolate, const Instance& msg) { | 556 void Service::HandleIsolateMessage(Isolate* isolate, const Instance& msg) { |
| 530 ASSERT(isolate != NULL); | 557 ASSERT(isolate != NULL); |
| 531 ASSERT(!msg.IsNull()); | 558 ASSERT(!msg.IsNull()); |
| 532 ASSERT(msg.IsGrowableObjectArray()); | 559 ASSERT(msg.IsGrowableObjectArray()); |
| 533 | 560 |
| 534 { | 561 { |
| 535 StackZone zone(isolate); | 562 StackZone zone(isolate); |
| 536 HANDLESCOPE(isolate); | 563 HANDLESCOPE(isolate); |
| 537 | 564 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 | 624 |
| 598 | 625 |
| 599 static bool HandleStackTrace(Isolate* isolate, JSONStream* js) { | 626 static bool HandleStackTrace(Isolate* isolate, JSONStream* js) { |
| 600 if (js->num_arguments() > 1) { | 627 if (js->num_arguments() > 1) { |
| 601 PrintError(js, "Command too long"); | 628 PrintError(js, "Command too long"); |
| 602 return true; | 629 return true; |
| 603 } | 630 } |
| 604 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 631 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
| 605 JSONObject jsobj(js); | 632 JSONObject jsobj(js); |
| 606 jsobj.AddProperty("type", "StackTrace"); | 633 jsobj.AddProperty("type", "StackTrace"); |
| 634 jsobj.AddProperty("id", "stacktrace"); |
| 607 JSONArray jsarr(&jsobj, "members"); | 635 JSONArray jsarr(&jsobj, "members"); |
| 608 intptr_t num_frames = stack->Length(); | 636 intptr_t num_frames = stack->Length(); |
| 609 for (intptr_t i = 0; i < num_frames; i++) { | 637 for (intptr_t i = 0; i < num_frames; i++) { |
| 610 ActivationFrame* frame = stack->FrameAt(i); | 638 ActivationFrame* frame = stack->FrameAt(i); |
| 611 JSONObject jsobj(&jsarr); | 639 JSONObject jsobj(&jsarr); |
| 612 frame->PrintToJSONObject(&jsobj); | 640 frame->PrintToJSONObject(&jsobj); |
| 613 // TODO(turnidge): Implement depth differently -- differentiate | 641 // TODO(turnidge): Implement depth differently -- differentiate |
| 614 // inlined frames. | 642 // inlined frames. |
| 615 jsobj.AddProperty("depth", i); | 643 jsobj.AddProperty("depth", i); |
| 616 } | 644 } |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 for (intptr_t i = 0; i < num_scripts; i++) { | 1033 for (intptr_t i = 0; i < num_scripts; i++) { |
| 1006 script ^= loaded_scripts.At(i); | 1034 script ^= loaded_scripts.At(i); |
| 1007 ASSERT(!script.IsNull()); | 1035 ASSERT(!script.IsNull()); |
| 1008 url ^= script.url(); | 1036 url ^= script.url(); |
| 1009 if (url.Equals(requested_url)) { | 1037 if (url.Equals(requested_url)) { |
| 1010 script.PrintToJSONStream(js, false); | 1038 script.PrintToJSONStream(js, false); |
| 1011 return true; | 1039 return true; |
| 1012 } | 1040 } |
| 1013 } | 1041 } |
| 1014 } | 1042 } |
| 1015 PrintError(js, "Cannot find script %s\n", requested_url.ToCString()); | 1043 PrintErrorWithKind(js, "NotFoundError", "Cannot find script %s", |
| 1044 requested_url.ToCString()); |
| 1016 return true; | 1045 return true; |
| 1017 } | 1046 } |
| 1018 | 1047 |
| 1019 | 1048 |
| 1020 static bool HandleScripts(Isolate* isolate, JSONStream* js) { | 1049 static bool HandleScripts(Isolate* isolate, JSONStream* js) { |
| 1021 if (js->num_arguments() == 1) { | 1050 if (js->num_arguments() == 1) { |
| 1022 // Enumerate all scripts. | 1051 // Enumerate all scripts. |
| 1023 return HandleScriptsEnumerate(isolate, js); | 1052 return HandleScriptsEnumerate(isolate, js); |
| 1024 } else if (js->num_arguments() == 2) { | 1053 } else if (js->num_arguments() == 2) { |
| 1025 // Fetch specific script. | 1054 // Fetch specific script. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 while (current != NULL) { | 1425 while (current != NULL) { |
| 1397 if (strcmp(name, current->name()) == 0) { | 1426 if (strcmp(name, current->name()) == 0) { |
| 1398 return current; | 1427 return current; |
| 1399 } | 1428 } |
| 1400 current = current->next(); | 1429 current = current->next(); |
| 1401 } | 1430 } |
| 1402 return NULL; | 1431 return NULL; |
| 1403 } | 1432 } |
| 1404 | 1433 |
| 1405 } // namespace dart | 1434 } // namespace dart |
| OLD | NEW |