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 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "vm/stack_frame.h" | 32 #include "vm/stack_frame.h" |
33 #include "vm/symbols.h" | 33 #include "vm/symbols.h" |
34 #include "vm/unicode.h" | 34 #include "vm/unicode.h" |
35 #include "vm/version.h" | 35 #include "vm/version.h" |
36 | 36 |
37 namespace dart { | 37 namespace dart { |
38 | 38 |
39 DECLARE_FLAG(bool, trace_service); | 39 DECLARE_FLAG(bool, trace_service); |
40 DECLARE_FLAG(bool, trace_service_pause_events); | 40 DECLARE_FLAG(bool, trace_service_pause_events); |
41 | 41 |
| 42 ServiceIdZone::ServiceIdZone() { |
| 43 } |
| 44 |
| 45 |
| 46 ServiceIdZone::~ServiceIdZone() { |
| 47 } |
| 48 |
| 49 |
| 50 RingServiceIdZone::RingServiceIdZone( |
| 51 ObjectIdRing* ring, ObjectIdRing::IdPolicy policy) |
| 52 : ring_(ring), |
| 53 policy_(policy) { |
| 54 ASSERT(ring_ != NULL); |
| 55 } |
| 56 |
| 57 |
| 58 RingServiceIdZone::~RingServiceIdZone() { |
| 59 } |
| 60 |
| 61 |
| 62 char* RingServiceIdZone::GetServiceId(const Object& obj) { |
| 63 Thread* thread = Thread::Current(); |
| 64 Zone* zone = thread->zone(); |
| 65 ASSERT(zone != NULL); |
| 66 const intptr_t id = ring_->GetIdForObject(obj.raw(), policy_); |
| 67 return zone->PrintToString("objects/%" Pd "", id); |
| 68 } |
| 69 |
| 70 |
42 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. | 71 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. |
43 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 72 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
44 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 73 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
45 struct ServiceMethodDescriptor; | 74 struct ServiceMethodDescriptor; |
46 ServiceMethodDescriptor* FindMethod(const char* method_name); | 75 ServiceMethodDescriptor* FindMethod(const char* method_name); |
47 | 76 |
48 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 77 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
49 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 78 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
50 return reinterpret_cast<uint8_t*>(new_ptr); | 79 return reinterpret_cast<uint8_t*>(new_ptr); |
51 } | 80 } |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 ASSERT(param_keys.Length() == param_values.Length()); | 472 ASSERT(param_keys.Length() == param_values.Length()); |
444 | 473 |
445 if (!reply_port.IsSendPort()) { | 474 if (!reply_port.IsSendPort()) { |
446 FATAL("SendPort expected."); | 475 FATAL("SendPort expected."); |
447 } | 476 } |
448 | 477 |
449 JSONStream js; | 478 JSONStream js; |
450 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), | 479 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), |
451 seq, method_name, param_keys, param_values); | 480 seq, method_name, param_keys, param_values); |
452 | 481 |
| 482 // RPC came in with a custom service id zone. |
| 483 const char* id_zone_param = js.LookupParam("_idZone"); |
| 484 |
| 485 if (id_zone_param != NULL) { |
| 486 // Override id zone. |
| 487 if (strcmp("default", id_zone_param) == 0) { |
| 488 // Ring with eager id allocation. This is the default ring and default |
| 489 // policy. |
| 490 // Nothing to do. |
| 491 } else if (strcmp("default.reuse", id_zone_param) == 0) { |
| 492 // Change the default ring's policy. |
| 493 RingServiceIdZone* zone = |
| 494 reinterpret_cast<RingServiceIdZone*>(js.id_zone()); |
| 495 zone->set_policy(ObjectIdRing::kReuseId); |
| 496 } else { |
| 497 // TODO(johnmccutchan): Support creating, deleting, and selecting |
| 498 // custom service id zones. |
| 499 // For now, always return an error. |
| 500 PrintInvalidParamError(&js, "_idZone"); |
| 501 js.PostReply(); |
| 502 return; |
| 503 } |
| 504 } |
453 const char* c_method_name = method_name.ToCString(); | 505 const char* c_method_name = method_name.ToCString(); |
454 | 506 |
455 ServiceMethodDescriptor* method = FindMethod(c_method_name); | 507 ServiceMethodDescriptor* method = FindMethod(c_method_name); |
456 if (method != NULL) { | 508 if (method != NULL) { |
457 if (!ValidateParameters(method->parameters, &js)) { | 509 if (!ValidateParameters(method->parameters, &js)) { |
458 js.PostReply(); | 510 js.PostReply(); |
459 return; | 511 return; |
460 } | 512 } |
461 if (method->entry(isolate, &js)) { | 513 if (method->entry(isolate, &js)) { |
462 js.PostReply(); | 514 js.PostReply(); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 764 |
713 | 765 |
714 static bool GetIsolate(Isolate* isolate, JSONStream* js) { | 766 static bool GetIsolate(Isolate* isolate, JSONStream* js) { |
715 isolate->PrintJSON(js, false); | 767 isolate->PrintJSON(js, false); |
716 return true; | 768 return true; |
717 } | 769 } |
718 | 770 |
719 | 771 |
720 static const MethodParameter* get_stack_params[] = { | 772 static const MethodParameter* get_stack_params[] = { |
721 ISOLATE_PARAMETER, | 773 ISOLATE_PARAMETER, |
722 new BoolParameter("full", false), | 774 new BoolParameter("_full", false), |
723 NULL, | 775 NULL, |
724 }; | 776 }; |
725 | 777 |
726 | 778 |
727 static bool GetStack(Isolate* isolate, JSONStream* js) { | 779 static bool GetStack(Isolate* isolate, JSONStream* js) { |
728 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 780 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
729 // Do we want the complete script object and complete local variable objects? | 781 // Do we want the complete script object and complete local variable objects? |
730 // This is true for dump requests. | 782 // This is true for dump requests. |
731 const bool full = BoolParameter::Parse(js->LookupParam("full"), false); | 783 const bool full = BoolParameter::Parse(js->LookupParam("_full"), false); |
732 JSONObject jsobj(js); | 784 JSONObject jsobj(js); |
733 jsobj.AddProperty("type", "Stack"); | 785 jsobj.AddProperty("type", "Stack"); |
734 { | 786 { |
735 JSONArray jsarr(&jsobj, "frames"); | 787 JSONArray jsarr(&jsobj, "frames"); |
736 | 788 |
737 intptr_t num_frames = stack->Length(); | 789 intptr_t num_frames = stack->Length(); |
738 for (intptr_t i = 0; i < num_frames; i++) { | 790 for (intptr_t i = 0; i < num_frames; i++) { |
739 ActivationFrame* frame = stack->FrameAt(i); | 791 ActivationFrame* frame = stack->FrameAt(i); |
740 JSONObject jsobj(&jsarr); | 792 JSONObject jsobj(&jsarr); |
741 frame->PrintToJSONObject(&jsobj, full); | 793 frame->PrintToJSONObject(&jsobj, full); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 event.AddProperty("text", text); | 829 event.AddProperty("text", text); |
778 } | 830 } |
779 } | 831 } |
780 } | 832 } |
781 const String& message = String::Handle(String::New(js.ToCString())); | 833 const String& message = String::Handle(String::New(js.ToCString())); |
782 uint8_t data[] = {0, 128, 255}; | 834 uint8_t data[] = {0, 128, 255}; |
783 SendEvent(message, data, sizeof(data)); | 835 SendEvent(message, data, sizeof(data)); |
784 } | 836 } |
785 | 837 |
786 | 838 |
787 static bool _TriggerEchoEvent(Isolate* isolate, JSONStream* js) { | 839 static bool TriggerEchoEvent(Isolate* isolate, JSONStream* js) { |
788 Service::SendEchoEvent(isolate, js->LookupParam("text")); | 840 Service::SendEchoEvent(isolate, js->LookupParam("text")); |
789 JSONObject jsobj(js); | 841 JSONObject jsobj(js); |
790 return HandleCommonEcho(&jsobj, js); | 842 return HandleCommonEcho(&jsobj, js); |
791 } | 843 } |
792 | 844 |
793 | 845 |
794 static bool _Echo(Isolate* isolate, JSONStream* js) { | 846 static bool DumpIdZone(Isolate* isolate, JSONStream* js) { |
| 847 // TODO(johnmccutchan): Respect _idZone parameter passed to RPC. For now, |
| 848 // always send the ObjectIdRing. |
| 849 // |
| 850 ObjectIdRing* ring = isolate->object_id_ring(); |
| 851 ASSERT(ring != NULL); |
| 852 // When printing the ObjectIdRing, force object id reuse policy. |
| 853 RingServiceIdZone reuse_zone(ring, ObjectIdRing::kReuseId); |
| 854 js->set_id_zone(&reuse_zone); |
| 855 ring->PrintJSON(js); |
| 856 return true; |
| 857 } |
| 858 |
| 859 |
| 860 static bool Echo(Isolate* isolate, JSONStream* js) { |
795 JSONObject jsobj(js); | 861 JSONObject jsobj(js); |
796 return HandleCommonEcho(&jsobj, js); | 862 return HandleCommonEcho(&jsobj, js); |
797 } | 863 } |
798 | 864 |
799 | 865 |
800 static bool ContainsNonInstance(const Object& obj) { | 866 static bool ContainsNonInstance(const Object& obj) { |
801 if (obj.IsArray()) { | 867 if (obj.IsArray()) { |
802 const Array& array = Array::Cast(obj); | 868 const Array& array = Array::Cast(obj); |
803 Object& element = Object::Handle(); | 869 Object& element = Object::Handle(); |
804 for (intptr_t i = 0; i < array.Length(); ++i) { | 870 for (intptr_t i = 0; i < array.Length(); ++i) { |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2311 } | 2377 } |
2312 if (object.IsNull()) { | 2378 if (object.IsNull()) { |
2313 PrintSentinel(js, "objects/free", "<free>"); | 2379 PrintSentinel(js, "objects/free", "<free>"); |
2314 } else { | 2380 } else { |
2315 object.PrintJSON(js, ref); | 2381 object.PrintJSON(js, ref); |
2316 } | 2382 } |
2317 return true; | 2383 return true; |
2318 } | 2384 } |
2319 | 2385 |
2320 | 2386 |
2321 static bool _RespondWithMalformedJson(Isolate* isolate, | 2387 static bool RespondWithMalformedJson(Isolate* isolate, |
2322 JSONStream* js) { | 2388 JSONStream* js) { |
2323 JSONObject jsobj(js); | 2389 JSONObject jsobj(js); |
2324 jsobj.AddProperty("a", "a"); | 2390 jsobj.AddProperty("a", "a"); |
2325 JSONObject jsobj1(js); | 2391 JSONObject jsobj1(js); |
2326 jsobj1.AddProperty("a", "a"); | 2392 jsobj1.AddProperty("a", "a"); |
2327 JSONObject jsobj2(js); | 2393 JSONObject jsobj2(js); |
2328 jsobj2.AddProperty("a", "a"); | 2394 jsobj2.AddProperty("a", "a"); |
2329 JSONObject jsobj3(js); | 2395 JSONObject jsobj3(js); |
2330 jsobj3.AddProperty("a", "a"); | 2396 jsobj3.AddProperty("a", "a"); |
2331 return true; | 2397 return true; |
2332 } | 2398 } |
2333 | 2399 |
2334 | 2400 |
2335 static bool _RespondWithMalformedObject(Isolate* isolate, | 2401 static bool RespondWithMalformedObject(Isolate* isolate, |
2336 JSONStream* js) { | 2402 JSONStream* js) { |
2337 JSONObject jsobj(js); | 2403 JSONObject jsobj(js); |
2338 jsobj.AddProperty("bart", "simpson"); | 2404 jsobj.AddProperty("bart", "simpson"); |
2339 return true; | 2405 return true; |
2340 } | 2406 } |
2341 | 2407 |
2342 | 2408 |
2343 static const MethodParameter* get_object_params[] = { | 2409 static const MethodParameter* get_object_params[] = { |
2344 ISOLATE_PARAMETER, | 2410 ISOLATE_PARAMETER, |
2345 NULL, | 2411 NULL, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2540 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); | 2606 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); |
2541 Service::HandleEvent(&event); | 2607 Service::HandleEvent(&event); |
2542 } | 2608 } |
2543 JSONObject jsobj(js); | 2609 JSONObject jsobj(js); |
2544 jsobj.AddProperty("type", "Success"); | 2610 jsobj.AddProperty("type", "Success"); |
2545 return true; | 2611 return true; |
2546 } | 2612 } |
2547 | 2613 |
2548 | 2614 |
2549 static ServiceMethodDescriptor service_methods_[] = { | 2615 static ServiceMethodDescriptor service_methods_[] = { |
2550 { "_echo", _Echo, | 2616 { "_dumpIdZone", DumpIdZone, NULL }, |
| 2617 { "_echo", Echo, |
2551 NULL }, | 2618 NULL }, |
2552 { "_respondWithMalformedJson", _RespondWithMalformedJson, | 2619 { "_respondWithMalformedJson", RespondWithMalformedJson, |
2553 NULL }, | 2620 NULL }, |
2554 { "_respondWithMalformedObject", _RespondWithMalformedObject, | 2621 { "_respondWithMalformedObject", RespondWithMalformedObject, |
2555 NULL }, | 2622 NULL }, |
2556 { "_triggerEchoEvent", _TriggerEchoEvent, | 2623 { "_triggerEchoEvent", TriggerEchoEvent, |
2557 NULL }, | 2624 NULL }, |
2558 { "addBreakpoint", AddBreakpoint, | 2625 { "addBreakpoint", AddBreakpoint, |
2559 add_breakpoint_params }, | 2626 add_breakpoint_params }, |
2560 { "addBreakpointAtEntry", AddBreakpointAtEntry, | 2627 { "addBreakpointAtEntry", AddBreakpointAtEntry, |
2561 add_breakpoint_at_entry_params }, | 2628 add_breakpoint_at_entry_params }, |
2562 { "clearCpuProfile", ClearCpuProfile, | 2629 { "clearCpuProfile", ClearCpuProfile, |
2563 clear_cpu_profile_params }, | 2630 clear_cpu_profile_params }, |
2564 { "eval", Eval, | 2631 { "eval", Eval, |
2565 eval_params }, | 2632 eval_params }, |
2566 { "evalFrame", EvalFrame, | 2633 { "evalFrame", EvalFrame, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2631 ServiceMethodDescriptor& method = service_methods_[i]; | 2698 ServiceMethodDescriptor& method = service_methods_[i]; |
2632 if (strcmp(method_name, method.name) == 0) { | 2699 if (strcmp(method_name, method.name) == 0) { |
2633 return &method; | 2700 return &method; |
2634 } | 2701 } |
2635 } | 2702 } |
2636 return NULL; | 2703 return NULL; |
2637 } | 2704 } |
2638 | 2705 |
2639 | 2706 |
2640 } // namespace dart | 2707 } // namespace dart |
OLD | NEW |