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 "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // These are the set of streams known to the core VM. | 122 // These are the set of streams known to the core VM. |
123 StreamInfo Service::vm_stream("VM"); | 123 StreamInfo Service::vm_stream("VM"); |
124 StreamInfo Service::isolate_stream("Isolate"); | 124 StreamInfo Service::isolate_stream("Isolate"); |
125 StreamInfo Service::debug_stream("Debug"); | 125 StreamInfo Service::debug_stream("Debug"); |
126 StreamInfo Service::gc_stream("GC"); | 126 StreamInfo Service::gc_stream("GC"); |
127 StreamInfo Service::echo_stream("_Echo"); | 127 StreamInfo Service::echo_stream("_Echo"); |
128 StreamInfo Service::graph_stream("_Graph"); | 128 StreamInfo Service::graph_stream("_Graph"); |
129 StreamInfo Service::logging_stream("_Logging"); | 129 StreamInfo Service::logging_stream("_Logging"); |
130 StreamInfo Service::extension_stream("Extension"); | 130 StreamInfo Service::extension_stream("Extension"); |
131 StreamInfo Service::timeline_stream("Timeline"); | 131 StreamInfo Service::timeline_stream("Timeline"); |
132 StreamInfo Service::editor_stream("_Editor"); | |
133 | 132 |
134 static StreamInfo* streams_[] = { | 133 static StreamInfo* streams_[] = { |
135 &Service::vm_stream, &Service::isolate_stream, | 134 &Service::vm_stream, &Service::isolate_stream, |
136 &Service::debug_stream, &Service::gc_stream, | 135 &Service::debug_stream, &Service::gc_stream, |
137 &Service::echo_stream, &Service::graph_stream, | 136 &Service::echo_stream, &Service::graph_stream, |
138 &Service::logging_stream, &Service::extension_stream, | 137 &Service::logging_stream, &Service::extension_stream, |
139 &Service::timeline_stream, &Service::editor_stream}; | 138 &Service::timeline_stream}; |
140 | 139 |
141 | 140 |
142 bool Service::ListenStream(const char* stream_id) { | 141 bool Service::ListenStream(const char* stream_id) { |
143 if (FLAG_trace_service) { | 142 if (FLAG_trace_service) { |
144 OS::Print("vm-service: starting stream '%s'\n", stream_id); | 143 OS::Print("vm-service: starting stream '%s'\n", stream_id); |
145 } | 144 } |
146 intptr_t num_streams = sizeof(streams_) / sizeof(streams_[0]); | 145 intptr_t num_streams = sizeof(streams_) / sizeof(streams_[0]); |
147 for (intptr_t i = 0; i < num_streams; i++) { | 146 for (intptr_t i = 0; i < num_streams; i++) { |
148 if (strcmp(stream_id, streams_[i]->id()) == 0) { | 147 if (strcmp(stream_id, streams_[i]->id()) == 0) { |
149 streams_[i]->set_enabled(true); | 148 streams_[i]->set_enabled(true); |
(...skipping 4058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4208 PrintInvalidParamError(js, "classId"); | 4207 PrintInvalidParamError(js, "classId"); |
4209 return true; | 4208 return true; |
4210 } | 4209 } |
4211 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); | 4210 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); |
4212 ASSERT(!cls.IsNull()); | 4211 ASSERT(!cls.IsNull()); |
4213 cls.SetTraceAllocation(enable); | 4212 cls.SetTraceAllocation(enable); |
4214 PrintSuccess(js); | 4213 PrintSuccess(js); |
4215 return true; | 4214 return true; |
4216 } | 4215 } |
4217 | 4216 |
4218 static const MethodParameter* send_object_to_editor_params[] = { | |
4219 RUNNABLE_ISOLATE_PARAMETER, new StringParameter("editor", true), | |
4220 new StringParameter("objectId", true), NULL, | |
4221 }; | |
4222 | |
4223 static bool SendObjectToEditor(Thread* thread, JSONStream* js) { | |
4224 // Handle heap objects. | |
4225 ObjectIdRing::LookupResult lookup_result; | |
4226 // Refreshing the id to avoid sending an expired ObjectRef | |
4227 const Object& obj = Object::Handle( | |
4228 LookupHeapObject(thread, js->LookupParam("objectId"), &lookup_result)); | |
4229 if (obj.raw() != Object::sentinel().raw()) { | |
4230 // We found a heap object for this id. Return it. | |
4231 if (Service::editor_stream.enabled()) { | |
4232 ServiceEvent event(thread->isolate(), | |
4233 ServiceEvent::kEditorObjectSelected); | |
4234 ServiceEvent::EditorEvent editor_event; | |
4235 editor_event.object = &obj; | |
4236 editor_event.editor = js->LookupParam("editor"); | |
4237 event.set_editor_event(editor_event); | |
4238 Service::HandleEvent(&event); | |
4239 } | |
4240 PrintSuccess(js); | |
4241 return true; | |
4242 } else if (lookup_result == ObjectIdRing::kCollected) { | |
4243 PrintSentinel(js, kCollectedSentinel); | |
4244 return true; | |
4245 } else if (lookup_result == ObjectIdRing::kExpired) { | |
4246 PrintSentinel(js, kExpiredSentinel); | |
4247 return true; | |
4248 } | |
4249 PrintInvalidParamError(js, "objectId"); | |
4250 | |
4251 return true; | |
4252 } | |
4253 | |
4254 | |
4255 // clang-format off | 4217 // clang-format off |
4256 static const ServiceMethodDescriptor service_methods_[] = { | 4218 static const ServiceMethodDescriptor service_methods_[] = { |
4257 { "_dumpIdZone", DumpIdZone, NULL }, | 4219 { "_dumpIdZone", DumpIdZone, NULL }, |
4258 { "_echo", Echo, | 4220 { "_echo", Echo, |
4259 NULL }, | 4221 NULL }, |
4260 { "_respondWithMalformedJson", RespondWithMalformedJson, | 4222 { "_respondWithMalformedJson", RespondWithMalformedJson, |
4261 NULL }, | 4223 NULL }, |
4262 { "_respondWithMalformedObject", RespondWithMalformedObject, | 4224 { "_respondWithMalformedObject", RespondWithMalformedObject, |
4263 NULL }, | 4225 NULL }, |
4264 { "_triggerEchoEvent", TriggerEchoEvent, | 4226 { "_triggerEchoEvent", TriggerEchoEvent, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4362 { "setName", SetName, | 4324 { "setName", SetName, |
4363 set_name_params }, | 4325 set_name_params }, |
4364 { "_setTraceClassAllocation", SetTraceClassAllocation, | 4326 { "_setTraceClassAllocation", SetTraceClassAllocation, |
4365 set_trace_class_allocation_params }, | 4327 set_trace_class_allocation_params }, |
4366 { "setVMName", SetVMName, | 4328 { "setVMName", SetVMName, |
4367 set_vm_name_params }, | 4329 set_vm_name_params }, |
4368 { "_setVMTimelineFlags", SetVMTimelineFlags, | 4330 { "_setVMTimelineFlags", SetVMTimelineFlags, |
4369 set_vm_timeline_flags_params }, | 4331 set_vm_timeline_flags_params }, |
4370 { "_collectAllGarbage", CollectAllGarbage, | 4332 { "_collectAllGarbage", CollectAllGarbage, |
4371 collect_all_garbage_params }, | 4333 collect_all_garbage_params }, |
4372 { "_sendObjectToEditor", SendObjectToEditor, | |
4373 send_object_to_editor_params }, | |
4374 }; | 4334 }; |
4375 // clang-format on | 4335 // clang-format on |
4376 | 4336 |
4377 const ServiceMethodDescriptor* FindMethod(const char* method_name) { | 4337 const ServiceMethodDescriptor* FindMethod(const char* method_name) { |
4378 intptr_t num_methods = sizeof(service_methods_) / sizeof(service_methods_[0]); | 4338 intptr_t num_methods = sizeof(service_methods_) / sizeof(service_methods_[0]); |
4379 for (intptr_t i = 0; i < num_methods; i++) { | 4339 for (intptr_t i = 0; i < num_methods; i++) { |
4380 const ServiceMethodDescriptor& method = service_methods_[i]; | 4340 const ServiceMethodDescriptor& method = service_methods_[i]; |
4381 if (strcmp(method_name, method.name) == 0) { | 4341 if (strcmp(method_name, method.name) == 0) { |
4382 return &method; | 4342 return &method; |
4383 } | 4343 } |
4384 } | 4344 } |
4385 return NULL; | 4345 return NULL; |
4386 } | 4346 } |
4387 | 4347 |
4388 #endif // !PRODUCT | 4348 #endif // !PRODUCT |
4389 | 4349 |
4390 } // namespace dart | 4350 } // namespace dart |
OLD | NEW |