| 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 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 jsobj.AddProperty("kind", "Free"); | 1189 jsobj.AddProperty("kind", "Free"); |
| 1190 jsobj.AddProperty("valueAsString", "<free>"); | 1190 jsobj.AddProperty("valueAsString", "<free>"); |
| 1191 break; | 1191 break; |
| 1192 default: | 1192 default: |
| 1193 UNIMPLEMENTED(); | 1193 UNIMPLEMENTED(); |
| 1194 break; | 1194 break; |
| 1195 } | 1195 } |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 | 1198 |
| 1199 static SourceBreakpoint* LookupBreakpoint(Isolate* isolate, const char* id) { | 1199 static Breakpoint* LookupBreakpoint(Isolate* isolate, const char* id) { |
| 1200 size_t end_pos = strcspn(id, "/"); | 1200 size_t end_pos = strcspn(id, "/"); |
| 1201 if (end_pos == strlen(id)) { | 1201 if (end_pos == strlen(id)) { |
| 1202 return NULL; | 1202 return NULL; |
| 1203 } | 1203 } |
| 1204 const char* rest = id + end_pos + 1; // +1 for '/'. | 1204 const char* rest = id + end_pos + 1; // +1 for '/'. |
| 1205 if (strncmp("breakpoints", id, end_pos) == 0) { | 1205 if (strncmp("breakpoints", id, end_pos) == 0) { |
| 1206 intptr_t bpt_id = 0; | 1206 intptr_t bpt_id = 0; |
| 1207 SourceBreakpoint* bpt = NULL; | 1207 Breakpoint* bpt = NULL; |
| 1208 if (GetIntegerId(rest, &bpt_id)) { | 1208 if (GetIntegerId(rest, &bpt_id)) { |
| 1209 bpt = isolate->debugger()->GetBreakpointById(bpt_id); | 1209 bpt = isolate->debugger()->GetBreakpointById(bpt_id); |
| 1210 } | 1210 } |
| 1211 return bpt; | 1211 return bpt; |
| 1212 } | 1212 } |
| 1213 return NULL; | 1213 return NULL; |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 | 1216 |
| 1217 // Scans |isolate|'s message queue looking for a message with |id|. | 1217 // Scans |isolate|'s message queue looking for a message with |id|. |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 const char* line_param = js->LookupParam("line"); | 1801 const char* line_param = js->LookupParam("line"); |
| 1802 intptr_t line = UIntParameter::Parse(line_param); | 1802 intptr_t line = UIntParameter::Parse(line_param); |
| 1803 const char* script_id = js->LookupParam("scriptId"); | 1803 const char* script_id = js->LookupParam("scriptId"); |
| 1804 Object& obj = Object::Handle(LookupHeapObject(isolate, script_id, NULL)); | 1804 Object& obj = Object::Handle(LookupHeapObject(isolate, script_id, NULL)); |
| 1805 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { | 1805 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { |
| 1806 PrintInvalidParamError(js, "scriptId"); | 1806 PrintInvalidParamError(js, "scriptId"); |
| 1807 return true; | 1807 return true; |
| 1808 } | 1808 } |
| 1809 const Script& script = Script::Cast(obj); | 1809 const Script& script = Script::Cast(obj); |
| 1810 const String& script_url = String::Handle(script.url()); | 1810 const String& script_url = String::Handle(script.url()); |
| 1811 SourceBreakpoint* bpt = | 1811 Breakpoint* bpt = |
| 1812 isolate->debugger()->SetBreakpointAtLine(script_url, line); | 1812 isolate->debugger()->SetBreakpointAtLine(script_url, line); |
| 1813 if (bpt == NULL) { | 1813 if (bpt == NULL) { |
| 1814 js->PrintError(kNoBreakAtLine, NULL); | 1814 js->PrintError(kNoBreakAtLine, NULL); |
| 1815 return true; | 1815 return true; |
| 1816 } | 1816 } |
| 1817 bpt->PrintJSON(js); | 1817 bpt->PrintJSON(js); |
| 1818 return true; | 1818 return true; |
| 1819 } | 1819 } |
| 1820 | 1820 |
| 1821 | 1821 |
| 1822 static const MethodParameter* add_breakpoint_at_entry_params[] = { | 1822 static const MethodParameter* add_breakpoint_at_entry_params[] = { |
| 1823 ISOLATE_PARAMETER, | 1823 ISOLATE_PARAMETER, |
| 1824 new IdParameter("functionId", true), | 1824 new IdParameter("functionId", true), |
| 1825 NULL, | 1825 NULL, |
| 1826 }; | 1826 }; |
| 1827 | 1827 |
| 1828 | 1828 |
| 1829 static bool AddBreakpointAtEntry(Isolate* isolate, JSONStream* js) { | 1829 static bool AddBreakpointAtEntry(Isolate* isolate, JSONStream* js) { |
| 1830 const char* function_id = js->LookupParam("functionId"); | 1830 const char* function_id = js->LookupParam("functionId"); |
| 1831 Object& obj = Object::Handle(LookupHeapObject(isolate, function_id, NULL)); | 1831 Object& obj = Object::Handle(LookupHeapObject(isolate, function_id, NULL)); |
| 1832 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { | 1832 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { |
| 1833 PrintInvalidParamError(js, "functionId"); | 1833 PrintInvalidParamError(js, "functionId"); |
| 1834 return true; | 1834 return true; |
| 1835 } | 1835 } |
| 1836 const Function& function = Function::Cast(obj); | 1836 const Function& function = Function::Cast(obj); |
| 1837 SourceBreakpoint* bpt = | 1837 Breakpoint* bpt = |
| 1838 isolate->debugger()->SetBreakpointAtEntry(function); | 1838 isolate->debugger()->SetBreakpointAtEntry(function, false); |
| 1839 if (bpt == NULL) { | 1839 if (bpt == NULL) { |
| 1840 js->PrintError(kNoBreakAtFunction, NULL); | 1840 js->PrintError(kNoBreakAtFunction, NULL); |
| 1841 return true; | 1841 return true; |
| 1842 } |
| 1843 bpt->PrintJSON(js); |
| 1844 return true; |
| 1845 } |
| 1846 |
| 1847 |
| 1848 static const MethodParameter* add_breakpoint_at_activation_params[] = { |
| 1849 ISOLATE_PARAMETER, |
| 1850 new IdParameter("objectId", true), |
| 1851 NULL, |
| 1852 }; |
| 1853 |
| 1854 |
| 1855 static bool AddBreakpointAtActivation(Isolate* isolate, JSONStream* js) { |
| 1856 const char* object_id = js->LookupParam("objectId"); |
| 1857 Object& obj = Object::Handle(LookupHeapObject(isolate, object_id, NULL)); |
| 1858 if (obj.raw() == Object::sentinel().raw() || !obj.IsInstance()) { |
| 1859 PrintInvalidParamError(js, "objectId"); |
| 1860 return true; |
| 1861 } |
| 1862 const Instance& closure = Instance::Cast(obj); |
| 1863 Breakpoint* bpt = |
| 1864 isolate->debugger()->SetBreakpointAtActivation(closure); |
| 1865 if (bpt == NULL) { |
| 1866 js->PrintError(kNoBreakAtFunction, NULL); |
| 1867 return true; |
| 1842 } | 1868 } |
| 1843 bpt->PrintJSON(js); | 1869 bpt->PrintJSON(js); |
| 1844 return true; | 1870 return true; |
| 1845 } | 1871 } |
| 1846 | 1872 |
| 1847 | 1873 |
| 1848 static const MethodParameter* remove_breakpoint_params[] = { | 1874 static const MethodParameter* remove_breakpoint_params[] = { |
| 1849 ISOLATE_PARAMETER, | 1875 ISOLATE_PARAMETER, |
| 1850 NULL, | 1876 NULL, |
| 1851 }; | 1877 }; |
| 1852 | 1878 |
| 1853 | 1879 |
| 1854 static bool RemoveBreakpoint(Isolate* isolate, JSONStream* js) { | 1880 static bool RemoveBreakpoint(Isolate* isolate, JSONStream* js) { |
| 1855 if (!js->HasParam("breakpointId")) { | 1881 if (!js->HasParam("breakpointId")) { |
| 1856 PrintMissingParamError(js, "breakpointId"); | 1882 PrintMissingParamError(js, "breakpointId"); |
| 1857 return true; | 1883 return true; |
| 1858 } | 1884 } |
| 1859 const char* bpt_id = js->LookupParam("breakpointId"); | 1885 const char* bpt_id = js->LookupParam("breakpointId"); |
| 1860 SourceBreakpoint* bpt = LookupBreakpoint(isolate, bpt_id); | 1886 Breakpoint* bpt = LookupBreakpoint(isolate, bpt_id); |
| 1861 if (bpt == NULL) { | 1887 if (bpt == NULL) { |
| 1862 fprintf(stderr, "ERROR1"); | 1888 fprintf(stderr, "ERROR1"); |
| 1863 PrintInvalidParamError(js, "breakpointId"); | 1889 PrintInvalidParamError(js, "breakpointId"); |
| 1864 return true; | 1890 return true; |
| 1865 } | 1891 } |
| 1866 isolate->debugger()->RemoveBreakpoint(bpt->id()); | 1892 isolate->debugger()->RemoveBreakpoint(bpt->id()); |
| 1867 | 1893 |
| 1868 // TODO(turnidge): Consider whether the 'Success' type is proper. | 1894 // TODO(turnidge): Consider whether the 'Success' type is proper. |
| 1869 JSONObject jsobj(js); | 1895 JSONObject jsobj(js); |
| 1870 jsobj.AddProperty("type", "Success"); | 1896 jsobj.AddProperty("type", "Success"); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2395 return true; | 2421 return true; |
| 2396 } else if (lookup_result == ObjectIdRing::kCollected) { | 2422 } else if (lookup_result == ObjectIdRing::kCollected) { |
| 2397 PrintSentinel(js, kCollectedSentinel); | 2423 PrintSentinel(js, kCollectedSentinel); |
| 2398 return true; | 2424 return true; |
| 2399 } else if (lookup_result == ObjectIdRing::kExpired) { | 2425 } else if (lookup_result == ObjectIdRing::kExpired) { |
| 2400 PrintSentinel(js, kExpiredSentinel); | 2426 PrintSentinel(js, kExpiredSentinel); |
| 2401 return true; | 2427 return true; |
| 2402 } | 2428 } |
| 2403 | 2429 |
| 2404 // Handle non-heap objects. | 2430 // Handle non-heap objects. |
| 2405 SourceBreakpoint* bpt = LookupBreakpoint(isolate, id); | 2431 Breakpoint* bpt = LookupBreakpoint(isolate, id); |
| 2406 if (bpt != NULL) { | 2432 if (bpt != NULL) { |
| 2407 bpt->PrintJSON(js); | 2433 bpt->PrintJSON(js); |
| 2408 return true; | 2434 return true; |
| 2409 } | 2435 } |
| 2410 | 2436 |
| 2411 if (PrintMessage(js, isolate, id)) { | 2437 if (PrintMessage(js, isolate, id)) { |
| 2412 return true; | 2438 return true; |
| 2413 } | 2439 } |
| 2414 | 2440 |
| 2415 PrintInvalidParamError(js, "objectId"); | 2441 PrintInvalidParamError(js, "objectId"); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2585 { "_respondWithMalformedJson", RespondWithMalformedJson, | 2611 { "_respondWithMalformedJson", RespondWithMalformedJson, |
| 2586 NULL }, | 2612 NULL }, |
| 2587 { "_respondWithMalformedObject", RespondWithMalformedObject, | 2613 { "_respondWithMalformedObject", RespondWithMalformedObject, |
| 2588 NULL }, | 2614 NULL }, |
| 2589 { "_triggerEchoEvent", TriggerEchoEvent, | 2615 { "_triggerEchoEvent", TriggerEchoEvent, |
| 2590 NULL }, | 2616 NULL }, |
| 2591 { "addBreakpoint", AddBreakpoint, | 2617 { "addBreakpoint", AddBreakpoint, |
| 2592 add_breakpoint_params }, | 2618 add_breakpoint_params }, |
| 2593 { "addBreakpointAtEntry", AddBreakpointAtEntry, | 2619 { "addBreakpointAtEntry", AddBreakpointAtEntry, |
| 2594 add_breakpoint_at_entry_params }, | 2620 add_breakpoint_at_entry_params }, |
| 2621 { "_addBreakpointAtActivation", AddBreakpointAtActivation, |
| 2622 add_breakpoint_at_activation_params }, |
| 2595 { "clearCpuProfile", ClearCpuProfile, | 2623 { "clearCpuProfile", ClearCpuProfile, |
| 2596 clear_cpu_profile_params }, | 2624 clear_cpu_profile_params }, |
| 2597 { "evaluate", Evaluate, | 2625 { "evaluate", Evaluate, |
| 2598 evaluate_params }, | 2626 evaluate_params }, |
| 2599 { "evaluateInFrame", EvaluateInFrame, | 2627 { "evaluateInFrame", EvaluateInFrame, |
| 2600 evaluate_in_frame_params }, | 2628 evaluate_in_frame_params }, |
| 2601 { "_getAllocationProfile", GetAllocationProfile, | 2629 { "_getAllocationProfile", GetAllocationProfile, |
| 2602 get_allocation_profile_params }, | 2630 get_allocation_profile_params }, |
| 2603 { "_getCallSiteData", GetCallSiteData, | 2631 { "_getCallSiteData", GetCallSiteData, |
| 2604 get_call_site_data_params }, | 2632 get_call_site_data_params }, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2664 ServiceMethodDescriptor& method = service_methods_[i]; | 2692 ServiceMethodDescriptor& method = service_methods_[i]; |
| 2665 if (strcmp(method_name, method.name) == 0) { | 2693 if (strcmp(method_name, method.name) == 0) { |
| 2666 return &method; | 2694 return &method; |
| 2667 } | 2695 } |
| 2668 } | 2696 } |
| 2669 return NULL; | 2697 return NULL; |
| 2670 } | 2698 } |
| 2671 | 2699 |
| 2672 | 2700 |
| 2673 } // namespace dart | 2701 } // namespace dart |
| OLD | NEW |