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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 intptr_t count = visitor.count(); | 1596 intptr_t count = visitor.count(); |
1597 if (count < limit) { | 1597 if (count < limit) { |
1598 // Truncate the list using utility method for GrowableObjectArray. | 1598 // Truncate the list using utility method for GrowableObjectArray. |
1599 GrowableObjectArray& wrapper = GrowableObjectArray::Handle( | 1599 GrowableObjectArray& wrapper = GrowableObjectArray::Handle( |
1600 GrowableObjectArray::New(storage)); | 1600 GrowableObjectArray::New(storage)); |
1601 wrapper.SetLength(count); | 1601 wrapper.SetLength(count); |
1602 storage = Array::MakeArray(wrapper); | 1602 storage = Array::MakeArray(wrapper); |
1603 } | 1603 } |
1604 JSONObject jsobj(js); | 1604 JSONObject jsobj(js); |
1605 jsobj.AddProperty("type", "InstanceSet"); | 1605 jsobj.AddProperty("type", "InstanceSet"); |
1606 jsobj.AddProperty("id", "instance_set"); | |
1607 jsobj.AddProperty("totalCount", count); | 1606 jsobj.AddProperty("totalCount", count); |
1608 jsobj.AddProperty("sampleCount", storage.Length()); | 1607 { |
1609 jsobj.AddProperty("sample", storage); | 1608 JSONArray samples(&jsobj, "samples"); |
| 1609 for (int i = 0; i < storage.Length(); i++) { |
| 1610 const Object& sample = Object::Handle(storage.At(i)); |
| 1611 samples.AddValue(Instance::Cast(sample)); |
| 1612 } |
| 1613 } |
1610 return true; | 1614 return true; |
1611 } | 1615 } |
1612 | 1616 |
1613 | 1617 |
1614 class LibraryCoverageFilter : public CoverageFilter { | 1618 class LibraryCoverageFilter : public CoverageFilter { |
1615 public: | 1619 public: |
1616 explicit LibraryCoverageFilter(const Library& lib) : lib_(lib) {} | 1620 explicit LibraryCoverageFilter(const Library& lib) : lib_(lib) {} |
1617 bool ShouldOutputCoverageFor(const Library& lib, | 1621 bool ShouldOutputCoverageFor(const Library& lib, |
1618 const Script& script, | 1622 const Script& script, |
1619 const Class& cls, | 1623 const Class& cls, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 if (bpt == NULL) { | 1808 if (bpt == NULL) { |
1805 fprintf(stderr, "ERROR1"); | 1809 fprintf(stderr, "ERROR1"); |
1806 PrintInvalidParamError(js, "breakpointId"); | 1810 PrintInvalidParamError(js, "breakpointId"); |
1807 return true; | 1811 return true; |
1808 } | 1812 } |
1809 isolate->debugger()->RemoveBreakpoint(bpt->id()); | 1813 isolate->debugger()->RemoveBreakpoint(bpt->id()); |
1810 | 1814 |
1811 // TODO(turnidge): Consider whether the 'Success' type is proper. | 1815 // TODO(turnidge): Consider whether the 'Success' type is proper. |
1812 JSONObject jsobj(js); | 1816 JSONObject jsobj(js); |
1813 jsobj.AddProperty("type", "Success"); | 1817 jsobj.AddProperty("type", "Success"); |
1814 jsobj.AddProperty("id", ""); | |
1815 return true; | 1818 return true; |
1816 } | 1819 } |
1817 | 1820 |
1818 | 1821 |
1819 static RawClass* GetMetricsClass(Isolate* isolate) { | 1822 static RawClass* GetMetricsClass(Isolate* isolate) { |
1820 const Library& prof_lib = | 1823 const Library& prof_lib = |
1821 Library::Handle(isolate, Library::ProfilerLibrary()); | 1824 Library::Handle(isolate, Library::ProfilerLibrary()); |
1822 ASSERT(!prof_lib.IsNull()); | 1825 ASSERT(!prof_lib.IsNull()); |
1823 const String& metrics_cls_name = | 1826 const String& metrics_cls_name = |
1824 String::Handle(isolate, String::New("Metrics")); | 1827 String::Handle(isolate, String::New("Metrics")); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 NULL, | 2005 NULL, |
2003 }; | 2006 }; |
2004 | 2007 |
2005 | 2008 |
2006 static bool Resume(Isolate* isolate, JSONStream* js) { | 2009 static bool Resume(Isolate* isolate, JSONStream* js) { |
2007 const char* step_param = js->LookupParam("step"); | 2010 const char* step_param = js->LookupParam("step"); |
2008 if (isolate->message_handler()->paused_on_start()) { | 2011 if (isolate->message_handler()->paused_on_start()) { |
2009 isolate->message_handler()->set_pause_on_start(false); | 2012 isolate->message_handler()->set_pause_on_start(false); |
2010 JSONObject jsobj(js); | 2013 JSONObject jsobj(js); |
2011 jsobj.AddProperty("type", "Success"); | 2014 jsobj.AddProperty("type", "Success"); |
2012 jsobj.AddProperty("id", ""); | |
2013 { | 2015 { |
2014 ServiceEvent event(isolate, ServiceEvent::kResume); | 2016 ServiceEvent event(isolate, ServiceEvent::kResume); |
2015 Service::HandleEvent(&event); | 2017 Service::HandleEvent(&event); |
2016 } | 2018 } |
2017 return true; | 2019 return true; |
2018 } | 2020 } |
2019 if (isolate->message_handler()->paused_on_exit()) { | 2021 if (isolate->message_handler()->paused_on_exit()) { |
2020 isolate->message_handler()->set_pause_on_exit(false); | 2022 isolate->message_handler()->set_pause_on_exit(false); |
2021 JSONObject jsobj(js); | 2023 JSONObject jsobj(js); |
2022 jsobj.AddProperty("type", "Success"); | 2024 jsobj.AddProperty("type", "Success"); |
2023 jsobj.AddProperty("id", ""); | |
2024 // We don't send a resume event because we will be exiting. | 2025 // We don't send a resume event because we will be exiting. |
2025 return true; | 2026 return true; |
2026 } | 2027 } |
2027 if (isolate->debugger()->PauseEvent() != NULL) { | 2028 if (isolate->debugger()->PauseEvent() != NULL) { |
2028 if (step_param != NULL) { | 2029 if (step_param != NULL) { |
2029 if (strcmp(step_param, "into") == 0) { | 2030 if (strcmp(step_param, "into") == 0) { |
2030 isolate->debugger()->SetSingleStep(); | 2031 isolate->debugger()->SetSingleStep(); |
2031 } else if (strcmp(step_param, "over") == 0) { | 2032 } else if (strcmp(step_param, "over") == 0) { |
2032 isolate->debugger()->SetStepOver(); | 2033 isolate->debugger()->SetStepOver(); |
2033 } else if (strcmp(step_param, "out") == 0) { | 2034 } else if (strcmp(step_param, "out") == 0) { |
2034 isolate->debugger()->SetStepOut(); | 2035 isolate->debugger()->SetStepOut(); |
2035 } else { | 2036 } else { |
2036 PrintInvalidParamError(js, "step"); | 2037 PrintInvalidParamError(js, "step"); |
2037 return true; | 2038 return true; |
2038 } | 2039 } |
2039 } | 2040 } |
2040 isolate->Resume(); | 2041 isolate->Resume(); |
2041 JSONObject jsobj(js); | 2042 JSONObject jsobj(js); |
2042 jsobj.AddProperty("type", "Success"); | 2043 jsobj.AddProperty("type", "Success"); |
2043 jsobj.AddProperty("id", ""); | |
2044 return true; | 2044 return true; |
2045 } | 2045 } |
2046 | 2046 |
2047 PrintError(js, "VM was not paused"); | 2047 PrintError(js, "VM was not paused"); |
2048 return true; | 2048 return true; |
2049 } | 2049 } |
2050 | 2050 |
2051 | 2051 |
2052 static const MethodParameter* pause_params[] = { | 2052 static const MethodParameter* pause_params[] = { |
2053 ISOLATE_PARAMETER, | 2053 ISOLATE_PARAMETER, |
2054 NULL, | 2054 NULL, |
2055 }; | 2055 }; |
2056 | 2056 |
2057 | 2057 |
2058 static bool Pause(Isolate* isolate, JSONStream* js) { | 2058 static bool Pause(Isolate* isolate, JSONStream* js) { |
2059 // TODO(turnidge): Don't double-interrupt the isolate here. | 2059 // TODO(turnidge): Don't double-interrupt the isolate here. |
2060 isolate->ScheduleInterrupts(Isolate::kApiInterrupt); | 2060 isolate->ScheduleInterrupts(Isolate::kApiInterrupt); |
2061 JSONObject jsobj(js); | 2061 JSONObject jsobj(js); |
2062 jsobj.AddProperty("type", "Success"); | 2062 jsobj.AddProperty("type", "Success"); |
2063 jsobj.AddProperty("id", ""); | |
2064 return true; | 2063 return true; |
2065 } | 2064 } |
2066 | 2065 |
2067 | 2066 |
2068 static const MethodParameter* get_tag_profile_params[] = { | 2067 static const MethodParameter* get_tag_profile_params[] = { |
2069 ISOLATE_PARAMETER, | 2068 ISOLATE_PARAMETER, |
2070 NULL, | 2069 NULL, |
2071 }; | 2070 }; |
2072 | 2071 |
2073 | 2072 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 PrintInvalidParamError(js, "address"); | 2252 PrintInvalidParamError(js, "address"); |
2254 return true; | 2253 return true; |
2255 } | 2254 } |
2256 bool ref = js->HasParam("ref") && js->ParamIs("ref", "true"); | 2255 bool ref = js->HasParam("ref") && js->ParamIs("ref", "true"); |
2257 Object& object = Object::Handle(isolate); | 2256 Object& object = Object::Handle(isolate); |
2258 { | 2257 { |
2259 NoSafepointScope no_safepoint; | 2258 NoSafepointScope no_safepoint; |
2260 ContainsAddressVisitor visitor(isolate, addr); | 2259 ContainsAddressVisitor visitor(isolate, addr); |
2261 object = isolate->heap()->FindObject(&visitor); | 2260 object = isolate->heap()->FindObject(&visitor); |
2262 } | 2261 } |
2263 object.PrintJSON(js, ref); | 2262 if (object.IsNull()) { |
| 2263 PrintSentinel(js, "objects/free", "<free>"); |
| 2264 } else { |
| 2265 object.PrintJSON(js, ref); |
| 2266 } |
2264 return true; | 2267 return true; |
2265 } | 2268 } |
2266 | 2269 |
2267 | 2270 |
2268 static bool _RespondWithMalformedJson(Isolate* isolate, | 2271 static bool _RespondWithMalformedJson(Isolate* isolate, |
2269 JSONStream* js) { | 2272 JSONStream* js) { |
2270 JSONObject jsobj(js); | 2273 JSONObject jsobj(js); |
2271 jsobj.AddProperty("a", "a"); | 2274 jsobj.AddProperty("a", "a"); |
2272 JSONObject jsobj1(js); | 2275 JSONObject jsobj1(js); |
2273 jsobj1.AddProperty("a", "a"); | 2276 jsobj1.AddProperty("a", "a"); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 } | 2457 } |
2455 const char* flag_value = js->LookupParam("value"); | 2458 const char* flag_value = js->LookupParam("value"); |
2456 if (flag_value == NULL) { | 2459 if (flag_value == NULL) { |
2457 PrintMissingParamError(js, "value"); | 2460 PrintMissingParamError(js, "value"); |
2458 return true; | 2461 return true; |
2459 } | 2462 } |
2460 JSONObject jsobj(js); | 2463 JSONObject jsobj(js); |
2461 const char* error = NULL; | 2464 const char* error = NULL; |
2462 if (Flags::SetFlag(flag_name, flag_value, &error)) { | 2465 if (Flags::SetFlag(flag_name, flag_value, &error)) { |
2463 jsobj.AddProperty("type", "Success"); | 2466 jsobj.AddProperty("type", "Success"); |
2464 jsobj.AddProperty("id", ""); | |
2465 return true; | 2467 return true; |
2466 } else { | 2468 } else { |
2467 jsobj.AddProperty("type", "Failure"); | 2469 jsobj.AddProperty("type", "Error"); |
2468 jsobj.AddProperty("id", ""); | |
2469 jsobj.AddProperty("message", error); | 2470 jsobj.AddProperty("message", error); |
2470 return true; | 2471 return true; |
2471 } | 2472 } |
2472 } | 2473 } |
2473 | 2474 |
2474 | 2475 |
2475 static const MethodParameter* set_name_params[] = { | 2476 static const MethodParameter* set_name_params[] = { |
2476 ISOLATE_PARAMETER, | 2477 ISOLATE_PARAMETER, |
2477 new MethodParameter("name", true), | 2478 new MethodParameter("name", true), |
2478 NULL, | 2479 NULL, |
(...skipping 24 matching lines...) Expand all Loading... |
2503 { "addBreakpoint", AddBreakpoint, | 2504 { "addBreakpoint", AddBreakpoint, |
2504 add_breakpoint_params }, | 2505 add_breakpoint_params }, |
2505 { "addBreakpointAtEntry", AddBreakpointAtEntry, | 2506 { "addBreakpointAtEntry", AddBreakpointAtEntry, |
2506 add_breakpoint_at_entry_params }, | 2507 add_breakpoint_at_entry_params }, |
2507 { "clearCpuProfile", ClearCpuProfile, | 2508 { "clearCpuProfile", ClearCpuProfile, |
2508 clear_cpu_profile_params }, | 2509 clear_cpu_profile_params }, |
2509 { "eval", Eval, | 2510 { "eval", Eval, |
2510 eval_params }, | 2511 eval_params }, |
2511 { "evalFrame", EvalFrame, | 2512 { "evalFrame", EvalFrame, |
2512 eval_frame_params }, | 2513 eval_frame_params }, |
2513 { "getAllocationProfile", GetAllocationProfile, | 2514 { "_getAllocationProfile", GetAllocationProfile, |
2514 get_allocation_profile_params }, | 2515 get_allocation_profile_params }, |
2515 { "_getCallSiteData", GetCallSiteData, | 2516 { "_getCallSiteData", GetCallSiteData, |
2516 get_call_site_data_params }, | 2517 get_call_site_data_params }, |
2517 { "getClassList", GetClassList, | 2518 { "getClassList", GetClassList, |
2518 get_class_list_params }, | 2519 get_class_list_params }, |
2519 { "getCoverage", GetCoverage, | 2520 { "getCoverage", GetCoverage, |
2520 get_coverage_params }, | 2521 get_coverage_params }, |
2521 { "getCpuProfile", GetCpuProfile, | 2522 { "getCpuProfile", GetCpuProfile, |
2522 get_cpu_profile_params }, | 2523 get_cpu_profile_params }, |
2523 { "getFlagList", GetFlagList , | 2524 { "getFlagList", GetFlagList , |
2524 get_flag_list_params }, | 2525 get_flag_list_params }, |
2525 { "getHeapMap", GetHeapMap, | 2526 { "getHeapMap", GetHeapMap, |
2526 get_heap_map_params }, | 2527 get_heap_map_params }, |
2527 { "getInboundReferences", GetInboundReferences, | 2528 { "_getInboundReferences", GetInboundReferences, |
2528 get_inbound_references_params }, | 2529 get_inbound_references_params }, |
2529 { "getInstances", GetInstances, | 2530 { "_getInstances", GetInstances, |
2530 get_instances_params }, | 2531 get_instances_params }, |
2531 { "getIsolate", GetIsolate, | 2532 { "getIsolate", GetIsolate, |
2532 get_isolate_params }, | 2533 get_isolate_params }, |
2533 { "getIsolateMetric", GetIsolateMetric, | 2534 { "getIsolateMetric", GetIsolateMetric, |
2534 get_isolate_metric_params }, | 2535 get_isolate_metric_params }, |
2535 { "getIsolateMetricList", GetIsolateMetricList, | 2536 { "getIsolateMetricList", GetIsolateMetricList, |
2536 get_isolate_metric_list_params }, | 2537 get_isolate_metric_list_params }, |
2537 { "getObject", GetObject, | 2538 { "getObject", GetObject, |
2538 get_object_params }, | 2539 get_object_params }, |
2539 { "getObjectByAddress", GetObjectByAddress, | 2540 { "getObjectByAddress", GetObjectByAddress, |
2540 get_object_by_address_params }, | 2541 get_object_by_address_params }, |
2541 { "getRetainedSize", GetRetainedSize, | 2542 { "_getRetainedSize", GetRetainedSize, |
2542 get_retained_size_params }, | 2543 get_retained_size_params }, |
2543 { "getRetainingPath", GetRetainingPath, | 2544 { "_getRetainingPath", GetRetainingPath, |
2544 get_retaining_path_params }, | 2545 get_retaining_path_params }, |
2545 { "getStack", GetStack, | 2546 { "getStack", GetStack, |
2546 get_stack_params }, | 2547 get_stack_params }, |
2547 { "getTagProfile", GetTagProfile, | 2548 { "getTagProfile", GetTagProfile, |
2548 get_tag_profile_params }, | 2549 get_tag_profile_params }, |
2549 { "getTypeArgumentsList", GetTypeArgumentsList, | 2550 { "getTypeArgumentsList", GetTypeArgumentsList, |
2550 get_type_arguments_list_params }, | 2551 get_type_arguments_list_params }, |
2551 { "getVM", GetVM, | 2552 { "getVM", GetVM, |
2552 get_vm_params }, | 2553 get_vm_params }, |
2553 { "getVMMetric", GetVMMetric, | 2554 { "getVMMetric", GetVMMetric, |
(...skipping 22 matching lines...) Expand all Loading... |
2576 ServiceMethodDescriptor& method = service_methods_[i]; | 2577 ServiceMethodDescriptor& method = service_methods_[i]; |
2577 if (strcmp(method_name, method.name) == 0) { | 2578 if (strcmp(method_name, method.name) == 0) { |
2578 return &method; | 2579 return &method; |
2579 } | 2580 } |
2580 } | 2581 } |
2581 return NULL; | 2582 return NULL; |
2582 } | 2583 } |
2583 | 2584 |
2584 | 2585 |
2585 } // namespace dart | 2586 } // namespace dart |
OLD | NEW |