| 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 | 8 |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/coverage.h" | 10 #include "vm/coverage.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return NULL; | 209 return NULL; |
| 210 } | 210 } |
| 211 const char* function_name = obj.ToCString(); | 211 const char* function_name = obj.ToCString(); |
| 212 ASSERT(function_name != NULL); | 212 ASSERT(function_name != NULL); |
| 213 ASSERT(auto_setup_scope != NULL); | 213 ASSERT(auto_setup_scope != NULL); |
| 214 *auto_setup_scope = true; | 214 *auto_setup_scope = true; |
| 215 intptr_t n = | 215 intptr_t n = |
| 216 sizeof(_VmServiceNativeEntries) / sizeof(_VmServiceNativeEntries[0]); | 216 sizeof(_VmServiceNativeEntries) / sizeof(_VmServiceNativeEntries[0]); |
| 217 for (intptr_t i = 0; i < n; i++) { | 217 for (intptr_t i = 0; i < n; i++) { |
| 218 VmServiceNativeEntry entry = _VmServiceNativeEntries[i]; | 218 VmServiceNativeEntry entry = _VmServiceNativeEntries[i]; |
| 219 if (!strcmp(function_name, entry.name) && | 219 if ((strcmp(function_name, entry.name) == 0) && |
| 220 (num_arguments == entry.num_arguments)) { | 220 (num_arguments == entry.num_arguments)) { |
| 221 return entry.function; | 221 return entry.function; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 return NULL; | 224 return NULL; |
| 225 } | 225 } |
| 226 | 226 |
| 227 | 227 |
| 228 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 228 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
| 229 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 229 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 if (!table->IsValidIndex(id)) { | 827 if (!table->IsValidIndex(id)) { |
| 828 PrintError(js, "%" Pd " is not a valid class id.", id);; | 828 PrintError(js, "%" Pd " is not a valid class id.", id);; |
| 829 return true; | 829 return true; |
| 830 } | 830 } |
| 831 Class& cls = Class::Handle(table->At(id)); | 831 Class& cls = Class::Handle(table->At(id)); |
| 832 if (js->num_arguments() == 2) { | 832 if (js->num_arguments() == 2) { |
| 833 cls.PrintToJSONStream(js, false); | 833 cls.PrintToJSONStream(js, false); |
| 834 return true; | 834 return true; |
| 835 } else if (js->num_arguments() >= 3) { | 835 } else if (js->num_arguments() >= 3) { |
| 836 const char* second = js->GetArgument(2); | 836 const char* second = js->GetArgument(2); |
| 837 if (!strcmp(second, "closures")) { | 837 if (strcmp(second, "closures") == 0) { |
| 838 return HandleClassesClosures(isolate, cls, js); | 838 return HandleClassesClosures(isolate, cls, js); |
| 839 } else if (!strcmp(second, "fields")) { | 839 } else if (strcmp(second, "fields") == 0) { |
| 840 return HandleClassesFields(isolate, cls, js); | 840 return HandleClassesFields(isolate, cls, js); |
| 841 } else if (!strcmp(second, "functions")) { | 841 } else if (strcmp(second, "functions") == 0) { |
| 842 return HandleClassesFunctions(isolate, cls, js); | 842 return HandleClassesFunctions(isolate, cls, js); |
| 843 } else if (!strcmp(second, "implicit_closures")) { | 843 } else if (strcmp(second, "implicit_closures") == 0) { |
| 844 return HandleClassesImplicitClosures(isolate, cls, js); | 844 return HandleClassesImplicitClosures(isolate, cls, js); |
| 845 } else if (!strcmp(second, "dispatchers")) { | 845 } else if (strcmp(second, "dispatchers") == 0) { |
| 846 return HandleClassesDispatchers(isolate, cls, js); | 846 return HandleClassesDispatchers(isolate, cls, js); |
| 847 } else { | 847 } else { |
| 848 PrintError(js, "Invalid sub collection %s", second); | 848 PrintError(js, "Invalid sub collection %s", second); |
| 849 return true; | 849 return true; |
| 850 } | 850 } |
| 851 } | 851 } |
| 852 UNREACHABLE(); | 852 UNREACHABLE(); |
| 853 return true; | 853 return true; |
| 854 } | 854 } |
| 855 | 855 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 | 1011 |
| 1012 static bool HandleDebug(Isolate* isolate, JSONStream* js) { | 1012 static bool HandleDebug(Isolate* isolate, JSONStream* js) { |
| 1013 if (js->num_arguments() == 1) { | 1013 if (js->num_arguments() == 1) { |
| 1014 PrintError(js, "Must specify a subcommand"); | 1014 PrintError(js, "Must specify a subcommand"); |
| 1015 return true; | 1015 return true; |
| 1016 } | 1016 } |
| 1017 const char* command = js->GetArgument(1); | 1017 const char* command = js->GetArgument(1); |
| 1018 if (!strcmp(command, "breakpoints")) { | 1018 if (strcmp(command, "breakpoints") == 0) { |
| 1019 if (js->num_arguments() == 2) { | 1019 if (js->num_arguments() == 2) { |
| 1020 // Print breakpoint list. | 1020 // Print breakpoint list. |
| 1021 JSONObject jsobj(js); | 1021 JSONObject jsobj(js); |
| 1022 jsobj.AddProperty("type", "BreakpointList"); | 1022 jsobj.AddProperty("type", "BreakpointList"); |
| 1023 JSONArray jsarr(&jsobj, "breakpoints"); | 1023 JSONArray jsarr(&jsobj, "breakpoints"); |
| 1024 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr); | 1024 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr); |
| 1025 return true; | 1025 return true; |
| 1026 } else if (js->num_arguments() == 3) { | 1026 } else if (js->num_arguments() == 3) { |
| 1027 // Print individual breakpoint. | 1027 // Print individual breakpoint. |
| 1028 intptr_t id = 0; | 1028 intptr_t id = 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1050 | 1050 |
| 1051 static bool HandleCpu(Isolate* isolate, JSONStream* js) { | 1051 static bool HandleCpu(Isolate* isolate, JSONStream* js) { |
| 1052 JSONObject jsobj(js); | 1052 JSONObject jsobj(js); |
| 1053 jsobj.AddProperty("type", "CPU"); | 1053 jsobj.AddProperty("type", "CPU"); |
| 1054 jsobj.AddProperty("targetCPU", CPU::Id()); | 1054 jsobj.AddProperty("targetCPU", CPU::Id()); |
| 1055 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); | 1055 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); |
| 1056 return true; | 1056 return true; |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 | 1059 |
| 1060 static bool HandleNullCode(uintptr_t pc, JSONStream* js) { |
| 1061 Object::null_object().PrintToJSONStream(js, false); |
| 1062 return true; |
| 1063 } |
| 1064 |
| 1065 |
| 1060 static bool HandleCode(Isolate* isolate, JSONStream* js) { | 1066 static bool HandleCode(Isolate* isolate, JSONStream* js) { |
| 1061 REQUIRE_COLLECTION_ID("code"); | 1067 REQUIRE_COLLECTION_ID("code"); |
| 1062 uintptr_t pc; | 1068 uintptr_t pc; |
| 1069 if (js->num_arguments() > 3) { |
| 1070 PrintError(js, "Command too long"); |
| 1071 return true; |
| 1072 } |
| 1073 if (js->num_arguments() == 3) { |
| 1074 const char* command = js->GetArgument(1); |
| 1075 if ((strcmp("collected", command) == 0) || |
| 1076 (strcmp("native", command) == 0)) { |
| 1077 if (!GetUnsignedIntegerId(js->GetArgument(1), &pc, 16)) { |
| 1078 PrintError(js, "Must specify code address: code/%s/c0deadd0.", command); |
| 1079 return true; |
| 1080 } |
| 1081 return HandleNullCode(pc, js); |
| 1082 } else { |
| 1083 PrintError(js, "Unrecognized subcommand '%s'", js->GetArgument(1)); |
| 1084 return true; |
| 1085 } |
| 1086 } |
| 1087 ASSERT(js->num_arguments() == 2); |
| 1063 if (!GetUnsignedIntegerId(js->GetArgument(1), &pc, 16)) { | 1088 if (!GetUnsignedIntegerId(js->GetArgument(1), &pc, 16)) { |
| 1064 PrintError(js, "Must specify code address: code/c0deadd0."); | 1089 PrintError(js, "Must specify code address: code/c0deadd0."); |
| 1065 return true; | 1090 return true; |
| 1066 } | 1091 } |
| 1067 Code& code = Code::Handle(Code::LookupCode(pc)); | 1092 Code& code = Code::Handle(); |
| 1068 if (code.IsNull()) { | 1093 code ^= Code::LookupCode(pc); |
| 1069 PrintError(js, "Could not find code at %" Px "", pc); | 1094 if (!code.IsNull()) { |
| 1095 code.PrintToJSONStream(js, false); |
| 1070 return true; | 1096 return true; |
| 1071 } | 1097 } |
| 1072 code.PrintToJSONStream(js, false); | 1098 code ^= Code::LookupCodeInVmIsolate(pc); |
| 1099 if (!code.IsNull()) { |
| 1100 code.PrintToJSONStream(js, false); |
| 1101 return true; |
| 1102 } |
| 1103 PrintError(js, "Could not find code at %" Px "", pc); |
| 1073 return true; | 1104 return true; |
| 1074 } | 1105 } |
| 1075 | 1106 |
| 1076 | 1107 |
| 1077 static bool HandleProfile(Isolate* isolate, JSONStream* js) { | 1108 static bool HandleProfile(Isolate* isolate, JSONStream* js) { |
| 1078 Profiler::PrintToJSONStream(isolate, js, true); | 1109 Profiler::PrintToJSONStream(isolate, js, true); |
| 1079 return true; | 1110 return true; |
| 1080 } | 1111 } |
| 1081 | 1112 |
| 1082 static bool HandleCoverage(Isolate* isolate, JSONStream* js) { | 1113 static bool HandleCoverage(Isolate* isolate, JSONStream* js) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 { "scripts", HandleScripts }, | 1146 { "scripts", HandleScripts }, |
| 1116 { "stacktrace", HandleStackTrace }, | 1147 { "stacktrace", HandleStackTrace }, |
| 1117 }; | 1148 }; |
| 1118 | 1149 |
| 1119 | 1150 |
| 1120 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 1151 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
| 1121 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 1152 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
| 1122 sizeof(isolate_handlers[0]); | 1153 sizeof(isolate_handlers[0]); |
| 1123 for (intptr_t i = 0; i < num_message_handlers; i++) { | 1154 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 1124 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; | 1155 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; |
| 1125 if (!strcmp(command, entry.command)) { | 1156 if (strcmp(command, entry.command) == 0) { |
| 1126 return entry.handler; | 1157 return entry.handler; |
| 1127 } | 1158 } |
| 1128 } | 1159 } |
| 1129 if (FLAG_trace_service) { | 1160 if (FLAG_trace_service) { |
| 1130 OS::Print("Service has no isolate message handler for <%s>\n", command); | 1161 OS::Print("Service has no isolate message handler for <%s>\n", command); |
| 1131 } | 1162 } |
| 1132 return NULL; | 1163 return NULL; |
| 1133 } | 1164 } |
| 1134 | 1165 |
| 1135 | 1166 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 { "_echo", HandleRootEcho }, | 1250 { "_echo", HandleRootEcho }, |
| 1220 { "cpu", HandleCpu }, | 1251 { "cpu", HandleCpu }, |
| 1221 }; | 1252 }; |
| 1222 | 1253 |
| 1223 | 1254 |
| 1224 static RootMessageHandler FindRootMessageHandler(const char* command) { | 1255 static RootMessageHandler FindRootMessageHandler(const char* command) { |
| 1225 intptr_t num_message_handlers = sizeof(root_handlers) / | 1256 intptr_t num_message_handlers = sizeof(root_handlers) / |
| 1226 sizeof(root_handlers[0]); | 1257 sizeof(root_handlers[0]); |
| 1227 for (intptr_t i = 0; i < num_message_handlers; i++) { | 1258 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 1228 const RootMessageHandlerEntry& entry = root_handlers[i]; | 1259 const RootMessageHandlerEntry& entry = root_handlers[i]; |
| 1229 if (!strcmp(command, entry.command)) { | 1260 if (strcmp(command, entry.command) == 0) { |
| 1230 return entry.handler; | 1261 return entry.handler; |
| 1231 } | 1262 } |
| 1232 } | 1263 } |
| 1233 if (FLAG_trace_service) { | 1264 if (FLAG_trace_service) { |
| 1234 OS::Print("Service has no root message handler for <%s>\n", command); | 1265 OS::Print("Service has no root message handler for <%s>\n", command); |
| 1235 } | 1266 } |
| 1236 return NULL; | 1267 return NULL; |
| 1237 } | 1268 } |
| 1238 | 1269 |
| 1239 | 1270 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 // Insert into isolate_service_handler_head_ list. | 1310 // Insert into isolate_service_handler_head_ list. |
| 1280 handler->set_next(isolate_service_handler_head_); | 1311 handler->set_next(isolate_service_handler_head_); |
| 1281 isolate_service_handler_head_ = handler; | 1312 isolate_service_handler_head_ = handler; |
| 1282 } | 1313 } |
| 1283 | 1314 |
| 1284 | 1315 |
| 1285 EmbedderServiceHandler* Service::FindIsolateEmbedderHandler( | 1316 EmbedderServiceHandler* Service::FindIsolateEmbedderHandler( |
| 1286 const char* name) { | 1317 const char* name) { |
| 1287 EmbedderServiceHandler* current = isolate_service_handler_head_; | 1318 EmbedderServiceHandler* current = isolate_service_handler_head_; |
| 1288 while (current != NULL) { | 1319 while (current != NULL) { |
| 1289 if (!strcmp(name, current->name())) { | 1320 if (strcmp(name, current->name()) == 0) { |
| 1290 return current; | 1321 return current; |
| 1291 } | 1322 } |
| 1292 current = current->next(); | 1323 current = current->next(); |
| 1293 } | 1324 } |
| 1294 return NULL; | 1325 return NULL; |
| 1295 } | 1326 } |
| 1296 | 1327 |
| 1297 | 1328 |
| 1298 void Service::RegisterRootEmbedderCallback( | 1329 void Service::RegisterRootEmbedderCallback( |
| 1299 const char* name, | 1330 const char* name, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1317 // Insert into root_service_handler_head_ list. | 1348 // Insert into root_service_handler_head_ list. |
| 1318 handler->set_next(root_service_handler_head_); | 1349 handler->set_next(root_service_handler_head_); |
| 1319 root_service_handler_head_ = handler; | 1350 root_service_handler_head_ = handler; |
| 1320 } | 1351 } |
| 1321 | 1352 |
| 1322 | 1353 |
| 1323 EmbedderServiceHandler* Service::FindRootEmbedderHandler( | 1354 EmbedderServiceHandler* Service::FindRootEmbedderHandler( |
| 1324 const char* name) { | 1355 const char* name) { |
| 1325 EmbedderServiceHandler* current = root_service_handler_head_; | 1356 EmbedderServiceHandler* current = root_service_handler_head_; |
| 1326 while (current != NULL) { | 1357 while (current != NULL) { |
| 1327 if (!strcmp(name, current->name())) { | 1358 if (strcmp(name, current->name()) == 0) { |
| 1328 return current; | 1359 return current; |
| 1329 } | 1360 } |
| 1330 current = current->next(); | 1361 current = current->next(); |
| 1331 } | 1362 } |
| 1332 return NULL; | 1363 return NULL; |
| 1333 } | 1364 } |
| 1334 | 1365 |
| 1335 } // namespace dart | 1366 } // namespace dart |
| OLD | NEW |