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"); |
132 | 133 |
133 static StreamInfo* streams_[] = { | 134 static StreamInfo* streams_[] = { |
134 &Service::vm_stream, &Service::isolate_stream, | 135 &Service::vm_stream, &Service::isolate_stream, |
135 &Service::debug_stream, &Service::gc_stream, | 136 &Service::debug_stream, &Service::gc_stream, |
136 &Service::echo_stream, &Service::graph_stream, | 137 &Service::echo_stream, &Service::graph_stream, |
137 &Service::logging_stream, &Service::extension_stream, | 138 &Service::logging_stream, &Service::extension_stream, |
138 &Service::timeline_stream, | 139 &Service::timeline_stream, &Service::editor_stream}; |
139 }; | |
140 | 140 |
141 | 141 |
142 bool Service::ListenStream(const char* stream_id) { | 142 bool Service::ListenStream(const char* stream_id) { |
143 if (FLAG_trace_service) { | 143 if (FLAG_trace_service) { |
144 OS::Print("vm-service: starting stream '%s'\n", stream_id); | 144 OS::Print("vm-service: starting stream '%s'\n", stream_id); |
145 } | 145 } |
146 intptr_t num_streams = sizeof(streams_) / sizeof(streams_[0]); | 146 intptr_t num_streams = sizeof(streams_) / sizeof(streams_[0]); |
147 for (intptr_t i = 0; i < num_streams; i++) { | 147 for (intptr_t i = 0; i < num_streams; i++) { |
148 if (strcmp(stream_id, streams_[i]->id()) == 0) { | 148 if (strcmp(stream_id, streams_[i]->id()) == 0) { |
149 streams_[i]->set_enabled(true); | 149 streams_[i]->set_enabled(true); |
(...skipping 4046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4196 PrintInvalidParamError(js, "classId"); | 4196 PrintInvalidParamError(js, "classId"); |
4197 return true; | 4197 return true; |
4198 } | 4198 } |
4199 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); | 4199 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); |
4200 ASSERT(!cls.IsNull()); | 4200 ASSERT(!cls.IsNull()); |
4201 cls.SetTraceAllocation(enable); | 4201 cls.SetTraceAllocation(enable); |
4202 PrintSuccess(js); | 4202 PrintSuccess(js); |
4203 return true; | 4203 return true; |
4204 } | 4204 } |
4205 | 4205 |
| 4206 static const MethodParameter* send_object_to_editor_params[] = { |
| 4207 RUNNABLE_ISOLATE_PARAMETER, new StringParameter("editor", true), |
| 4208 new StringParameter("objectId", true), NULL, |
| 4209 }; |
| 4210 |
| 4211 static bool SendObjectToEditor(Thread* thread, JSONStream* js) { |
| 4212 // Handle heap objects. |
| 4213 ObjectIdRing::LookupResult lookup_result; |
| 4214 // Refreshing the id to avoid sending an expired ObjectRef |
| 4215 const Object& obj = Object::Handle( |
| 4216 LookupHeapObject(thread, js->LookupParam("objectId"), &lookup_result)); |
| 4217 if (obj.raw() != Object::sentinel().raw()) { |
| 4218 // We found a heap object for this id. Return it. |
| 4219 if (Service::editor_stream.enabled()) { |
| 4220 ServiceEvent event(thread->isolate(), |
| 4221 ServiceEvent::kEditorObjectSelected); |
| 4222 ServiceEvent::EditorEvent editor_event; |
| 4223 editor_event.object = &obj; |
| 4224 editor_event.editor = js->LookupParam("editor"); |
| 4225 event.set_editor_event(editor_event); |
| 4226 Service::HandleEvent(&event); |
| 4227 } |
| 4228 PrintSuccess(js); |
| 4229 return true; |
| 4230 } else if (lookup_result == ObjectIdRing::kCollected) { |
| 4231 PrintSentinel(js, kCollectedSentinel); |
| 4232 return true; |
| 4233 } else if (lookup_result == ObjectIdRing::kExpired) { |
| 4234 PrintSentinel(js, kExpiredSentinel); |
| 4235 return true; |
| 4236 } |
| 4237 PrintInvalidParamError(js, "objectId"); |
| 4238 |
| 4239 return true; |
| 4240 } |
| 4241 |
4206 | 4242 |
4207 // clang-format off | 4243 // clang-format off |
4208 static const ServiceMethodDescriptor service_methods_[] = { | 4244 static const ServiceMethodDescriptor service_methods_[] = { |
4209 { "_dumpIdZone", DumpIdZone, NULL }, | 4245 { "_dumpIdZone", DumpIdZone, NULL }, |
4210 { "_echo", Echo, | 4246 { "_echo", Echo, |
4211 NULL }, | 4247 NULL }, |
4212 { "_respondWithMalformedJson", RespondWithMalformedJson, | 4248 { "_respondWithMalformedJson", RespondWithMalformedJson, |
4213 NULL }, | 4249 NULL }, |
4214 { "_respondWithMalformedObject", RespondWithMalformedObject, | 4250 { "_respondWithMalformedObject", RespondWithMalformedObject, |
4215 NULL }, | 4251 NULL }, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4314 { "setName", SetName, | 4350 { "setName", SetName, |
4315 set_name_params }, | 4351 set_name_params }, |
4316 { "_setTraceClassAllocation", SetTraceClassAllocation, | 4352 { "_setTraceClassAllocation", SetTraceClassAllocation, |
4317 set_trace_class_allocation_params }, | 4353 set_trace_class_allocation_params }, |
4318 { "setVMName", SetVMName, | 4354 { "setVMName", SetVMName, |
4319 set_vm_name_params }, | 4355 set_vm_name_params }, |
4320 { "_setVMTimelineFlags", SetVMTimelineFlags, | 4356 { "_setVMTimelineFlags", SetVMTimelineFlags, |
4321 set_vm_timeline_flags_params }, | 4357 set_vm_timeline_flags_params }, |
4322 { "_collectAllGarbage", CollectAllGarbage, | 4358 { "_collectAllGarbage", CollectAllGarbage, |
4323 collect_all_garbage_params }, | 4359 collect_all_garbage_params }, |
| 4360 { "_sendObjectToEditor", SendObjectToEditor, |
| 4361 send_object_to_editor_params }, |
4324 }; | 4362 }; |
4325 // clang-format on | 4363 // clang-format on |
4326 | 4364 |
4327 const ServiceMethodDescriptor* FindMethod(const char* method_name) { | 4365 const ServiceMethodDescriptor* FindMethod(const char* method_name) { |
4328 intptr_t num_methods = sizeof(service_methods_) / sizeof(service_methods_[0]); | 4366 intptr_t num_methods = sizeof(service_methods_) / sizeof(service_methods_[0]); |
4329 for (intptr_t i = 0; i < num_methods; i++) { | 4367 for (intptr_t i = 0; i < num_methods; i++) { |
4330 const ServiceMethodDescriptor& method = service_methods_[i]; | 4368 const ServiceMethodDescriptor& method = service_methods_[i]; |
4331 if (strcmp(method_name, method.name) == 0) { | 4369 if (strcmp(method_name, method.name) == 0) { |
4332 return &method; | 4370 return &method; |
4333 } | 4371 } |
4334 } | 4372 } |
4335 return NULL; | 4373 return NULL; |
4336 } | 4374 } |
4337 | 4375 |
4338 #endif // !PRODUCT | 4376 #endif // !PRODUCT |
4339 | 4377 |
4340 } // namespace dart | 4378 } // namespace dart |
OLD | NEW |