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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 Field& field = Field::Handle(cls.FieldFromIndex(id)); | 790 Field& field = Field::Handle(cls.FieldFromIndex(id)); |
791 if (field.IsNull()) { | 791 if (field.IsNull()) { |
792 PrintError(js, "Field %" Pd " not found", id); | 792 PrintError(js, "Field %" Pd " not found", id); |
793 return true; | 793 return true; |
794 } | 794 } |
795 field.PrintToJSONStream(js, false); | 795 field.PrintToJSONStream(js, false); |
796 return true; | 796 return true; |
797 } | 797 } |
798 | 798 |
799 | 799 |
800 static bool HandleClassesTypes(Isolate* isolate, const Class& cls, | |
801 JSONStream* js) { | |
802 if (js->num_arguments() == 3) { | |
803 JSONObject jsobj(js); | |
804 jsobj.AddProperty("type", "TypeList"); | |
805 JSONArray members(&jsobj, "members"); | |
806 const intptr_t num_types = cls.NumCanonicalTypes(); | |
807 Type& type = Type::Handle(); | |
808 for (intptr_t i = 0; i < num_types; i++) { | |
809 type = cls.CanonicalTypeFromIndex(i); | |
810 members.AddValue(type); | |
811 } | |
812 return true; | |
813 } | |
814 intptr_t id; | |
815 if (js->num_arguments() > 4) { | |
816 PrintError(js, "Command too long"); | |
817 return true; | |
818 } | |
819 if (!GetIntegerId(js->GetArgument(3), &id)) { | |
820 PrintError(js, "Must specify collection object id: types/id"); | |
821 return true; | |
822 } | |
823 Type& type = Type::Handle(); | |
824 type ^= cls.CanonicalTypeFromIndex(id); | |
825 if (type.IsNull()) { | |
826 PrintError(js, "Canonical type %" Pd " not found", id); | |
827 return true; | |
828 } | |
829 type.PrintToJSONStream(js, false); | |
830 return true; | |
831 } | |
832 | |
833 | |
800 static bool HandleClasses(Isolate* isolate, JSONStream* js) { | 834 static bool HandleClasses(Isolate* isolate, JSONStream* js) { |
801 if (js->num_arguments() == 1) { | 835 if (js->num_arguments() == 1) { |
802 ClassTable* table = isolate->class_table(); | 836 ClassTable* table = isolate->class_table(); |
803 table->PrintToJSONStream(js); | 837 table->PrintToJSONStream(js); |
804 return true; | 838 return true; |
805 } | 839 } |
806 ASSERT(js->num_arguments() >= 2); | 840 ASSERT(js->num_arguments() >= 2); |
807 intptr_t id; | 841 intptr_t id; |
808 if (!GetIntegerId(js->GetArgument(1), &id)) { | 842 if (!GetIntegerId(js->GetArgument(1), &id)) { |
809 PrintError(js, "Must specify collection object id: /classes/id"); | 843 PrintError(js, "Must specify collection object id: /classes/id"); |
810 return true; | 844 return true; |
811 } | 845 } |
812 ClassTable* table = isolate->class_table(); | 846 ClassTable* table = isolate->class_table(); |
813 if (!table->IsValidIndex(id)) { | 847 if (!table->IsValidIndex(id)) { |
814 PrintError(js, "%" Pd " is not a valid class id.", id);; | 848 PrintError(js, "%" Pd " is not a valid class id.", id); |
815 return true; | 849 return true; |
816 } | 850 } |
817 Class& cls = Class::Handle(table->At(id)); | 851 Class& cls = Class::Handle(table->At(id)); |
818 if (js->num_arguments() == 2) { | 852 if (js->num_arguments() == 2) { |
819 cls.PrintToJSONStream(js, false); | 853 cls.PrintToJSONStream(js, false); |
820 return true; | 854 return true; |
821 } else if (js->num_arguments() >= 3) { | 855 } else if (js->num_arguments() >= 3) { |
822 const char* second = js->GetArgument(2); | 856 const char* second = js->GetArgument(2); |
823 if (strcmp(second, "closures") == 0) { | 857 if (strcmp(second, "closures") == 0) { |
824 return HandleClassesClosures(isolate, cls, js); | 858 return HandleClassesClosures(isolate, cls, js); |
825 } else if (strcmp(second, "fields") == 0) { | 859 } else if (strcmp(second, "fields") == 0) { |
826 return HandleClassesFields(isolate, cls, js); | 860 return HandleClassesFields(isolate, cls, js); |
827 } else if (strcmp(second, "functions") == 0) { | 861 } else if (strcmp(second, "functions") == 0) { |
828 return HandleClassesFunctions(isolate, cls, js); | 862 return HandleClassesFunctions(isolate, cls, js); |
829 } else if (strcmp(second, "implicit_closures") == 0) { | 863 } else if (strcmp(second, "implicit_closures") == 0) { |
830 return HandleClassesImplicitClosures(isolate, cls, js); | 864 return HandleClassesImplicitClosures(isolate, cls, js); |
831 } else if (strcmp(second, "dispatchers") == 0) { | 865 } else if (strcmp(second, "dispatchers") == 0) { |
832 return HandleClassesDispatchers(isolate, cls, js); | 866 return HandleClassesDispatchers(isolate, cls, js); |
867 } else if (!strcmp(second, "types")) { | |
868 return HandleClassesTypes(isolate, cls, js); | |
833 } else { | 869 } else { |
834 PrintError(js, "Invalid sub collection %s", second); | 870 PrintError(js, "Invalid sub collection %s", second); |
835 return true; | 871 return true; |
836 } | 872 } |
837 } | 873 } |
838 UNREACHABLE(); | 874 UNREACHABLE(); |
839 return true; | 875 return true; |
840 } | 876 } |
841 | 877 |
842 | 878 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 } | 1198 } |
1163 | 1199 |
1164 | 1200 |
1165 static bool HandleUnpin(Isolate* isolate, JSONStream* js) { | 1201 static bool HandleUnpin(Isolate* isolate, JSONStream* js) { |
1166 // TODO(johnmccutchan): What do I respond with?? | 1202 // TODO(johnmccutchan): What do I respond with?? |
1167 isolate->ClosePinPort(); | 1203 isolate->ClosePinPort(); |
1168 return true; | 1204 return true; |
1169 } | 1205 } |
1170 | 1206 |
1171 | 1207 |
1208 static bool HandleTypeArguments(Isolate* isolate, JSONStream* js, | |
1209 bool only_with_instantiations) { | |
1210 ObjectStore* object_store = isolate->object_store(); | |
1211 const Array& table = Array::Handle(object_store->canonical_type_arguments()); | |
1212 ASSERT(table.Length() > 0); | |
1213 TypeArguments& type_args = TypeArguments::Handle(); | |
1214 const intptr_t table_size = table.Length() - 1; | |
1215 const intptr_t table_used = Smi::Value(Smi::RawCast(table.At(table_size))); | |
1216 if (js->num_arguments() == 1) { | |
1217 JSONObject jsobj(js); | |
1218 jsobj.AddProperty("type", "TypeArgumentsList"); | |
1219 jsobj.AddProperty("table_size", table_size); | |
1220 jsobj.AddProperty("table_used", table_used); | |
1221 const char* members_kind = only_with_instantiations ? | |
1222 "members with instantiations" : "members"; | |
Cutch
2014/03/11 13:50:01
This should always be "members". Also, please do n
regis
2014/03/14 23:52:07
Done.
| |
1223 JSONArray members(&jsobj, members_kind); | |
1224 for (intptr_t i = 0; i < table_size; i++) { | |
1225 type_args ^= table.At(i); | |
1226 if (!type_args.IsNull()) { | |
1227 if (!only_with_instantiations || type_args.HasInstantiations()) { | |
1228 members.AddValue(type_args); | |
1229 } | |
1230 } | |
1231 } | |
1232 return true; | |
1233 } | |
1234 ASSERT(js->num_arguments() >= 2); | |
1235 if (only_with_instantiations) { | |
1236 PrintError(js, "Command too long"); | |
1237 return true; | |
1238 } | |
1239 intptr_t id; | |
1240 if (!GetIntegerId(js->GetArgument(1), &id)) { | |
1241 // Note that the table index of the canonical type arguments will change | |
1242 // when the table grows. Should we not support this access at all? | |
1243 PrintError(js, "Must specify collection object id: /typearguments/id"); | |
1244 return true; | |
1245 } | |
1246 if ((id < 0) || (id >= table_size) || (table.At(id) == Object::null())) { | |
1247 PrintError(js, "%" Pd " is not a valid typearguments id.", id); | |
1248 return true; | |
1249 } | |
1250 type_args ^= table.At(id); | |
1251 type_args.PrintToJSONStream(js, false); | |
1252 return true; | |
1253 } | |
1254 | |
1255 | |
1256 static bool HandleTypeArgumentsAll(Isolate* isolate, JSONStream* js) { | |
1257 return HandleTypeArguments(isolate, js, false); | |
1258 } | |
1259 | |
1260 | |
1261 static bool HandleTypeArgumentsWithInstantiations(Isolate* isolate, | |
1262 JSONStream* js) { | |
1263 return HandleTypeArguments(isolate, js, true); | |
1264 } | |
1265 | |
1266 | |
1172 static IsolateMessageHandlerEntry isolate_handlers[] = { | 1267 static IsolateMessageHandlerEntry isolate_handlers[] = { |
1173 { "_echo", HandleIsolateEcho }, | 1268 { "_echo", HandleIsolateEcho }, |
1174 { "", HandleIsolate }, | 1269 { "", HandleIsolate }, |
1175 { "allocationprofile", HandleAllocationProfile }, | 1270 { "allocationprofile", HandleAllocationProfile }, |
1176 { "classes", HandleClasses }, | 1271 { "classes", HandleClasses }, |
1177 { "code", HandleCode }, | 1272 { "code", HandleCode }, |
1178 { "coverage", HandleCoverage }, | 1273 { "coverage", HandleCoverage }, |
1179 { "cpu", HandleCpu }, | 1274 { "cpu", HandleCpu }, |
1180 { "debug", HandleDebug }, | 1275 { "debug", HandleDebug }, |
1181 { "libraries", HandleLibraries }, | 1276 { "libraries", HandleLibraries }, |
1182 { "objects", HandleObjects }, | 1277 { "objects", HandleObjects }, |
1183 { "profile", HandleProfile }, | 1278 { "profile", HandleProfile }, |
1184 { "unpin", HandleUnpin }, | 1279 { "unpin", HandleUnpin }, |
1185 { "scripts", HandleScripts }, | 1280 { "scripts", HandleScripts }, |
1186 { "stacktrace", HandleStackTrace }, | 1281 { "stacktrace", HandleStackTrace }, |
1282 { "typearguments", HandleTypeArgumentsAll }, | |
1283 { "typeargumentswithinstantiations", HandleTypeArgumentsWithInstantiations }, | |
Cutch
2014/03/11 13:50:01
Does it make sense to make the "withinstantiations
regis
2014/03/14 23:52:07
Good idea. Done.
| |
1187 }; | 1284 }; |
1188 | 1285 |
1189 | 1286 |
1190 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 1287 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
1191 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 1288 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
1192 sizeof(isolate_handlers[0]); | 1289 sizeof(isolate_handlers[0]); |
1193 for (intptr_t i = 0; i < num_message_handlers; i++) { | 1290 for (intptr_t i = 0; i < num_message_handlers; i++) { |
1194 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; | 1291 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; |
1195 if (strcmp(command, entry.command) == 0) { | 1292 if (strcmp(command, entry.command) == 0) { |
1196 return entry.handler; | 1293 return entry.handler; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1396 while (current != NULL) { | 1493 while (current != NULL) { |
1397 if (strcmp(name, current->name()) == 0) { | 1494 if (strcmp(name, current->name()) == 0) { |
1398 return current; | 1495 return current; |
1399 } | 1496 } |
1400 current = current->next(); | 1497 current = current->next(); |
1401 } | 1498 } |
1402 return NULL; | 1499 return NULL; |
1403 } | 1500 } |
1404 | 1501 |
1405 } // namespace dart | 1502 } // namespace dart |
OLD | NEW |