| 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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 // Skip the dash. | 791 // Skip the dash. |
| 792 s++; | 792 s++; |
| 793 // Extract the PC. | 793 // Extract the PC. |
| 794 if (!GetUnsignedIntegerId(s, address, 16)) { | 794 if (!GetUnsignedIntegerId(s, address, 16)) { |
| 795 return false; | 795 return false; |
| 796 } | 796 } |
| 797 return true; | 797 return true; |
| 798 } | 798 } |
| 799 | 799 |
| 800 | 800 |
| 801 static bool HandleInstanceCommands(Isolate* isolate, |
| 802 const Object& obj, |
| 803 JSONStream* js, |
| 804 intptr_t arg_pos) { |
| 805 ASSERT(js->num_arguments() > arg_pos); |
| 806 const char* action = js->GetArgument(arg_pos); |
| 807 if (strcmp(action, "eval") == 0) { |
| 808 if (js->num_arguments() > (arg_pos + 1)) { |
| 809 PrintError(js, "expected at most %" Pd " arguments but found %" Pd "\n", |
| 810 arg_pos + 1, |
| 811 js->num_arguments()); |
| 812 return true; |
| 813 } |
| 814 if (obj.IsNull()) { |
| 815 PrintErrorWithKind(js, "EvalCollected", |
| 816 "attempt to evaluate against collected object\n", |
| 817 js->num_arguments()); |
| 818 return true; |
| 819 } |
| 820 if (obj.raw() == Object::sentinel().raw()) { |
| 821 PrintErrorWithKind(js, "EvalExpired", |
| 822 "attempt to evaluate against expired object\n", |
| 823 js->num_arguments()); |
| 824 return true; |
| 825 } |
| 826 const char* expr = js->LookupOption("expr"); |
| 827 if (expr == NULL) { |
| 828 PrintError(js, "eval expects an 'expr' option\n", |
| 829 js->num_arguments()); |
| 830 return true; |
| 831 } |
| 832 const String& expr_str = String::Handle(isolate, String::New(expr)); |
| 833 ASSERT(obj.IsInstance()); |
| 834 const Instance& instance = Instance::Cast(obj); |
| 835 const Object& result = Object::Handle(instance.Evaluate(expr_str)); |
| 836 if (result.IsNull()) { |
| 837 Object::null_instance().PrintToJSONStream(js, true); |
| 838 } else { |
| 839 result.PrintToJSONStream(js, true); |
| 840 } |
| 841 return true; |
| 842 } |
| 843 |
| 844 PrintError(js, "unrecognized action '%s'\n", action); |
| 845 return true; |
| 846 } |
| 847 |
| 848 |
| 801 static bool HandleClassesClosures(Isolate* isolate, const Class& cls, | 849 static bool HandleClassesClosures(Isolate* isolate, const Class& cls, |
| 802 JSONStream* js) { | 850 JSONStream* js) { |
| 803 intptr_t id; | 851 intptr_t id; |
| 804 if (js->num_arguments() > 4) { | 852 if (js->num_arguments() > 4) { |
| 805 PrintError(js, "Command too long"); | 853 PrintError(js, "Command too long"); |
| 806 return true; | 854 return true; |
| 807 } | 855 } |
| 808 if (!GetIntegerId(js->GetArgument(3), &id)) { | 856 if (!GetIntegerId(js->GetArgument(3), &id)) { |
| 809 PrintError(js, "Must specify collection object id: closures/id"); | 857 PrintError(js, "Must specify collection object id: closures/id"); |
| 810 return true; | 858 return true; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 jsobj.AddProperty("type", "TypeList"); | 985 jsobj.AddProperty("type", "TypeList"); |
| 938 JSONArray members(&jsobj, "members"); | 986 JSONArray members(&jsobj, "members"); |
| 939 const intptr_t num_types = cls.NumCanonicalTypes(); | 987 const intptr_t num_types = cls.NumCanonicalTypes(); |
| 940 Type& type = Type::Handle(); | 988 Type& type = Type::Handle(); |
| 941 for (intptr_t i = 0; i < num_types; i++) { | 989 for (intptr_t i = 0; i < num_types; i++) { |
| 942 type = cls.CanonicalTypeFromIndex(i); | 990 type = cls.CanonicalTypeFromIndex(i); |
| 943 members.AddValue(type); | 991 members.AddValue(type); |
| 944 } | 992 } |
| 945 return true; | 993 return true; |
| 946 } | 994 } |
| 995 ASSERT(js->num_arguments() >= 4); |
| 947 intptr_t id; | 996 intptr_t id; |
| 948 if (js->num_arguments() > 4) { | |
| 949 PrintError(js, "Command too long"); | |
| 950 return true; | |
| 951 } | |
| 952 if (!GetIntegerId(js->GetArgument(3), &id)) { | 997 if (!GetIntegerId(js->GetArgument(3), &id)) { |
| 953 PrintError(js, "Must specify collection object id: types/id"); | 998 PrintError(js, "Must specify collection object id: types/id"); |
| 954 return true; | 999 return true; |
| 955 } | 1000 } |
| 956 Type& type = Type::Handle(); | 1001 Type& type = Type::Handle(); |
| 957 type ^= cls.CanonicalTypeFromIndex(id); | 1002 type ^= cls.CanonicalTypeFromIndex(id); |
| 958 if (type.IsNull()) { | 1003 if (type.IsNull()) { |
| 959 PrintError(js, "Canonical type %" Pd " not found", id); | 1004 PrintError(js, "Canonical type %" Pd " not found", id); |
| 960 return true; | 1005 return true; |
| 961 } | 1006 } |
| 962 type.PrintToJSONStream(js, false); | 1007 if (js->num_arguments() == 4) { |
| 963 return true; | 1008 type.PrintToJSONStream(js, false); |
| 1009 return true; |
| 1010 } |
| 1011 return HandleInstanceCommands(isolate, type, js, 4); |
| 964 } | 1012 } |
| 965 | 1013 |
| 966 | 1014 |
| 967 static bool HandleClasses(Isolate* isolate, JSONStream* js) { | 1015 static bool HandleClasses(Isolate* isolate, JSONStream* js) { |
| 968 if (js->num_arguments() == 1) { | 1016 if (js->num_arguments() == 1) { |
| 969 ClassTable* table = isolate->class_table(); | 1017 ClassTable* table = isolate->class_table(); |
| 970 JSONObject jsobj(js); | 1018 JSONObject jsobj(js); |
| 971 table->PrintToJSONObject(&jsobj); | 1019 table->PrintToJSONObject(&jsobj); |
| 972 return true; | 1020 return true; |
| 973 } | 1021 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 } | 1222 } |
| 1175 | 1223 |
| 1176 // Lookup the object. | 1224 // Lookup the object. |
| 1177 Object& obj = Object::Handle(isolate); | 1225 Object& obj = Object::Handle(isolate); |
| 1178 bool error = false; | 1226 bool error = false; |
| 1179 obj = LookupObjectId(isolate, arg, &error); | 1227 obj = LookupObjectId(isolate, arg, &error); |
| 1180 if (error) { | 1228 if (error) { |
| 1181 PrintError(js, "unrecognized object id '%s'", arg); | 1229 PrintError(js, "unrecognized object id '%s'", arg); |
| 1182 return true; | 1230 return true; |
| 1183 } | 1231 } |
| 1184 | |
| 1185 // Now what should we do with the object? | |
| 1186 if (js->num_arguments() == 2) { | 1232 if (js->num_arguments() == 2) { |
| 1187 // Print. | 1233 // Print. |
| 1188 if (obj.IsNull()) { | 1234 if (obj.IsNull()) { |
| 1189 // The object has been collected by the gc. | 1235 // The object has been collected by the gc. |
| 1190 PrintPseudoNull(js, "objects/collected", "<collected>"); | 1236 PrintPseudoNull(js, "objects/collected", "<collected>"); |
| 1191 return true; | 1237 return true; |
| 1192 } else if (obj.raw() == Object::sentinel().raw()) { | 1238 } else if (obj.raw() == Object::sentinel().raw()) { |
| 1193 // The object id has expired. | 1239 // The object id has expired. |
| 1194 PrintPseudoNull(js, "objects/expired", "<expired>"); | 1240 PrintPseudoNull(js, "objects/expired", "<expired>"); |
| 1195 return true; | 1241 return true; |
| 1196 } | 1242 } |
| 1197 obj.PrintToJSONStream(js, false); | 1243 obj.PrintToJSONStream(js, false); |
| 1198 return true; | 1244 return true; |
| 1199 } | 1245 } |
| 1200 ASSERT(js->num_arguments() > 2); | 1246 return HandleInstanceCommands(isolate, obj, js, 2); |
| 1201 | |
| 1202 const char* action = js->GetArgument(2); | |
| 1203 if (strcmp(action, "eval") == 0) { | |
| 1204 if (js->num_arguments() > 3) { | |
| 1205 PrintError(js, "expected at most 3 arguments but found %" Pd "\n", | |
| 1206 js->num_arguments()); | |
| 1207 return true; | |
| 1208 } | |
| 1209 if (obj.IsNull()) { | |
| 1210 PrintErrorWithKind(js, "EvalCollected", | |
| 1211 "attempt to evaluate against collected object\n", | |
| 1212 js->num_arguments()); | |
| 1213 return true; | |
| 1214 } | |
| 1215 if (obj.raw() == Object::sentinel().raw()) { | |
| 1216 PrintErrorWithKind(js, "EvalExpired", | |
| 1217 "attempt to evaluate against expired object\n", | |
| 1218 js->num_arguments()); | |
| 1219 return true; | |
| 1220 } | |
| 1221 const char* expr = js->LookupOption("expr"); | |
| 1222 if (expr == NULL) { | |
| 1223 PrintError(js, "eval expects an 'expr' option\n", | |
| 1224 js->num_arguments()); | |
| 1225 return true; | |
| 1226 } | |
| 1227 const String& expr_str = String::Handle(isolate, String::New(expr)); | |
| 1228 ASSERT(obj.IsInstance()); | |
| 1229 const Instance& instance = Instance::Cast(obj); | |
| 1230 const Object& result = Object::Handle(instance.Evaluate(expr_str)); | |
| 1231 if (result.IsNull()) { | |
| 1232 Object::null_instance().PrintToJSONStream(js, true); | |
| 1233 } else { | |
| 1234 result.PrintToJSONStream(js, true); | |
| 1235 } | |
| 1236 return true; | |
| 1237 } | |
| 1238 | |
| 1239 PrintError(js, "unrecognized action '%s'\n", action); | |
| 1240 return true; | |
| 1241 } | 1247 } |
| 1242 | 1248 |
| 1243 | 1249 |
| 1244 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) { | 1250 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) { |
| 1245 JSONObject jsobj(js); | 1251 JSONObject jsobj(js); |
| 1246 jsobj.AddProperty("type", "ScriptList"); | 1252 jsobj.AddProperty("type", "ScriptList"); |
| 1247 JSONArray members(&jsobj, "members"); | 1253 JSONArray members(&jsobj, "members"); |
| 1248 const GrowableObjectArray& libs = | 1254 const GrowableObjectArray& libs = |
| 1249 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | 1255 GrowableObjectArray::Handle(isolate->object_store()->libraries()); |
| 1250 int num_libs = libs.Length(); | 1256 int num_libs = libs.Length(); |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 while (current != NULL) { | 1886 while (current != NULL) { |
| 1881 if (strcmp(name, current->name()) == 0) { | 1887 if (strcmp(name, current->name()) == 0) { |
| 1882 return current; | 1888 return current; |
| 1883 } | 1889 } |
| 1884 current = current->next(); | 1890 current = current->next(); |
| 1885 } | 1891 } |
| 1886 return NULL; | 1892 return NULL; |
| 1887 } | 1893 } |
| 1888 | 1894 |
| 1889 } // namespace dart | 1895 } // namespace dart |
| OLD | NEW |