Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 43 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
| 44 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 44 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
| 45 struct ServiceMethodDescriptor; | 45 struct ServiceMethodDescriptor; |
| 46 ServiceMethodDescriptor* FindMethod(const char* method_name); | 46 ServiceMethodDescriptor* FindMethod(const char* method_name); |
| 47 | 47 |
| 48 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 48 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 49 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 49 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 50 return reinterpret_cast<uint8_t*>(new_ptr); | 50 return reinterpret_cast<uint8_t*>(new_ptr); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void PrintRequest(const JSONObject& obj, JSONStream* js) { | |
| 54 JSONObject jsobj(&obj, "request"); | |
| 55 jsobj.AddProperty("method", js->method()); | |
| 56 { | |
| 57 JSONObject params(&jsobj, "params"); | |
| 58 for (intptr_t i = 0; i < js->num_params(); i++) { | |
| 59 params.AddProperty(js->GetParamKey(i), js->GetParamValue(i)); | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 | |
| 65 static void PrintError(JSONStream* js, | |
| 66 const char* format, ...) { | |
| 67 Isolate* isolate = Isolate::Current(); | |
| 68 | |
| 69 va_list args; | |
| 70 va_start(args, format); | |
| 71 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | |
| 72 va_end(args); | |
| 73 | |
| 74 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
| 75 va_list args2; | |
| 76 va_start(args2, format); | |
| 77 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 78 va_end(args2); | |
| 79 | |
| 80 JSONObject jsobj(js); | |
| 81 jsobj.AddProperty("type", "Error"); | |
| 82 jsobj.AddProperty("message", buffer); | |
| 83 PrintRequest(jsobj, js); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 static void PrintMissingParamError(JSONStream* js, | 53 static void PrintMissingParamError(JSONStream* js, |
| 88 const char* param) { | 54 const char* param) { |
| 89 PrintError(js, "%s expects the '%s' parameter", | 55 js->PrintError(kInvalidParams, |
| 90 js->method(), param); | 56 "%s expects the '%s' parameter", js->method(), param); |
| 91 } | 57 } |
| 92 | 58 |
| 93 | 59 |
| 94 static void PrintInvalidParamError(JSONStream* js, | 60 static void PrintInvalidParamError(JSONStream* js, |
| 95 const char* param) { | 61 const char* param) { |
| 96 PrintError(js, "%s: invalid '%s' parameter: %s", | 62 js->PrintError(kInvalidParams, |
| 97 js->method(), param, js->LookupParam(param)); | 63 "%s: invalid '%s' parameter: %s", |
| 64 js->method(), param, js->LookupParam(param)); | |
| 98 } | 65 } |
| 99 | 66 |
| 100 | 67 |
| 101 static void PrintUnrecognizedMethodError(JSONStream* js) { | 68 static void PrintUnrecognizedMethodError(JSONStream* js) { |
| 102 PrintError(js, "unrecognized method: %s", js->method()); | 69 js->PrintError(kMethodNotFound, NULL); |
| 103 } | 70 } |
| 104 | 71 |
| 105 | 72 |
| 106 static void PrintErrorWithKind(JSONStream* js, | |
| 107 const char* kind, | |
| 108 const char* format, ...) { | |
| 109 Isolate* isolate = Isolate::Current(); | |
| 110 | |
| 111 va_list args; | |
| 112 va_start(args, format); | |
| 113 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | |
| 114 va_end(args); | |
| 115 | |
| 116 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
| 117 va_list args2; | |
| 118 va_start(args2, format); | |
| 119 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 120 va_end(args2); | |
| 121 | |
| 122 JSONObject jsobj(js); | |
| 123 jsobj.AddProperty("type", "Error"); | |
| 124 jsobj.AddProperty("id", ""); | |
| 125 jsobj.AddProperty("kind", kind); | |
| 126 jsobj.AddProperty("message", buffer); | |
| 127 PrintRequest(jsobj, js); | |
| 128 } | |
| 129 | |
| 130 | |
| 131 static bool GetIntegerId(const char* s, intptr_t* id, int base = 10) { | 73 static bool GetIntegerId(const char* s, intptr_t* id, int base = 10) { |
| 132 if ((s == NULL) || (*s == '\0')) { | 74 if ((s == NULL) || (*s == '\0')) { |
| 133 // Empty string. | 75 // Empty string. |
| 134 return false; | 76 return false; |
| 135 } | 77 } |
| 136 if (id == NULL) { | 78 if (id == NULL) { |
| 137 // No id pointer. | 79 // No id pointer. |
| 138 return false; | 80 return false; |
| 139 } | 81 } |
| 140 intptr_t r = 0; | 82 intptr_t r = 0; |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 return false; | 1137 return false; |
| 1196 } | 1138 } |
| 1197 const char* rest = id + end_pos + 1; // +1 for '/'. | 1139 const char* rest = id + end_pos + 1; // +1 for '/'. |
| 1198 if (strncmp("messages", id, end_pos) == 0) { | 1140 if (strncmp("messages", id, end_pos) == 0) { |
| 1199 uword message_id = 0; | 1141 uword message_id = 0; |
| 1200 if (GetUnsignedIntegerId(rest, &message_id, 16)) { | 1142 if (GetUnsignedIntegerId(rest, &message_id, 16)) { |
| 1201 MessageHandler::AcquiredQueues aq; | 1143 MessageHandler::AcquiredQueues aq; |
| 1202 isolate->message_handler()->AcquireQueues(&aq); | 1144 isolate->message_handler()->AcquireQueues(&aq); |
| 1203 Message* message = aq.queue()->FindMessageById(message_id); | 1145 Message* message = aq.queue()->FindMessageById(message_id); |
| 1204 if (message == NULL) { | 1146 if (message == NULL) { |
| 1205 printf("Could not find message %" Px "\n", message_id); | 1147 // The user may try to load an expired message, so we treat |
| 1206 // Not found. | 1148 // unrecognized ids as if they are expired. |
| 1207 return false; | 1149 PrintSentinel(js, "objects/expired", "<expired>"); |
|
Cutch
2015/05/13 17:50:10
Should PrintSentinel take an enum and handle setti
turnidge
2015/05/14 17:53:43
Done.
| |
| 1150 return true; | |
| 1208 } | 1151 } |
| 1209 SnapshotReader reader(message->data(), | 1152 SnapshotReader reader(message->data(), |
| 1210 message->len(), | 1153 message->len(), |
| 1211 Snapshot::kMessage, | 1154 Snapshot::kMessage, |
| 1212 isolate, | 1155 isolate, |
| 1213 isolate->current_zone()); | 1156 isolate->current_zone()); |
| 1214 const Object& msg_obj = Object::Handle(reader.ReadObject()); | 1157 const Object& msg_obj = Object::Handle(reader.ReadObject()); |
| 1215 msg_obj.PrintJSON(js); | 1158 msg_obj.PrintJSON(js); |
| 1216 return true; | 1159 return true; |
| 1217 } else { | |
| 1218 printf("Could not get id from %s\n", rest); | |
| 1219 } | 1160 } |
| 1220 } | 1161 } |
| 1221 return false; | 1162 return false; |
| 1222 } | 1163 } |
| 1223 | 1164 |
| 1224 | 1165 |
| 1225 static bool PrintInboundReferences(Isolate* isolate, | 1166 static bool PrintInboundReferences(Isolate* isolate, |
| 1226 Object* target, | 1167 Object* target, |
| 1227 intptr_t limit, | 1168 intptr_t limit, |
| 1228 JSONStream* js) { | 1169 JSONStream* js) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1276 }; | 1217 }; |
| 1277 | 1218 |
| 1278 | 1219 |
| 1279 static bool GetInboundReferences(Isolate* isolate, JSONStream* js) { | 1220 static bool GetInboundReferences(Isolate* isolate, JSONStream* js) { |
| 1280 const char* target_id = js->LookupParam("targetId"); | 1221 const char* target_id = js->LookupParam("targetId"); |
| 1281 if (target_id == NULL) { | 1222 if (target_id == NULL) { |
| 1282 PrintMissingParamError(js, "targetId"); | 1223 PrintMissingParamError(js, "targetId"); |
| 1283 return true; | 1224 return true; |
| 1284 } | 1225 } |
| 1285 const char* limit_cstr = js->LookupParam("limit"); | 1226 const char* limit_cstr = js->LookupParam("limit"); |
| 1286 if (target_id == NULL) { | 1227 if (limit_cstr == NULL) { |
| 1287 PrintMissingParamError(js, "limit"); | 1228 PrintMissingParamError(js, "limit"); |
| 1288 return true; | 1229 return true; |
| 1289 } | 1230 } |
| 1290 intptr_t limit; | 1231 intptr_t limit; |
| 1291 if (!GetIntegerId(limit_cstr, &limit)) { | 1232 if (!GetIntegerId(limit_cstr, &limit)) { |
| 1292 PrintInvalidParamError(js, "limit"); | 1233 PrintInvalidParamError(js, "limit"); |
| 1293 return true; | 1234 return true; |
| 1294 } | 1235 } |
| 1295 | 1236 |
| 1296 Object& obj = Object::Handle(isolate); | 1237 Object& obj = Object::Handle(isolate); |
| 1297 ObjectIdRing::LookupResult lookup_result; | 1238 ObjectIdRing::LookupResult lookup_result; |
| 1298 { | 1239 { |
| 1299 HANDLESCOPE(isolate); | 1240 HANDLESCOPE(isolate); |
| 1300 obj = LookupHeapObject(isolate, target_id, &lookup_result); | 1241 obj = LookupHeapObject(isolate, target_id, &lookup_result); |
| 1301 } | 1242 } |
| 1302 if (obj.raw() == Object::sentinel().raw()) { | 1243 if (obj.raw() == Object::sentinel().raw()) { |
| 1303 if (lookup_result == ObjectIdRing::kCollected) { | 1244 if (lookup_result == ObjectIdRing::kCollected) { |
| 1304 PrintErrorWithKind( | 1245 PrintSentinel(js, "objects/collected", "<collected>"); |
| 1305 js, "InboundReferencesCollected", | |
| 1306 "attempt to find a retaining path for a collected object\n"); | |
| 1307 return true; | |
| 1308 } else if (lookup_result == ObjectIdRing::kExpired) { | 1246 } else if (lookup_result == ObjectIdRing::kExpired) { |
| 1309 PrintErrorWithKind( | 1247 PrintSentinel(js, "objects/expired", "<expired>"); |
| 1310 js, "InboundReferencesExpired", | 1248 } else { |
| 1311 "attempt to find a retaining path for an expired object\n"); | 1249 PrintInvalidParamError(js, "targetId"); |
| 1312 return true; | |
| 1313 } | 1250 } |
| 1314 PrintInvalidParamError(js, "targetId"); | |
| 1315 return true; | 1251 return true; |
| 1316 } | 1252 } |
| 1317 return PrintInboundReferences(isolate, &obj, limit, js); | 1253 return PrintInboundReferences(isolate, &obj, limit, js); |
| 1318 } | 1254 } |
| 1319 | 1255 |
| 1320 | 1256 |
| 1321 static bool PrintRetainingPath(Isolate* isolate, | 1257 static bool PrintRetainingPath(Isolate* isolate, |
| 1322 Object* obj, | 1258 Object* obj, |
| 1323 intptr_t limit, | 1259 intptr_t limit, |
| 1324 JSONStream* js) { | 1260 JSONStream* js) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1380 }; | 1316 }; |
| 1381 | 1317 |
| 1382 | 1318 |
| 1383 static bool GetRetainingPath(Isolate* isolate, JSONStream* js) { | 1319 static bool GetRetainingPath(Isolate* isolate, JSONStream* js) { |
| 1384 const char* target_id = js->LookupParam("targetId"); | 1320 const char* target_id = js->LookupParam("targetId"); |
| 1385 if (target_id == NULL) { | 1321 if (target_id == NULL) { |
| 1386 PrintMissingParamError(js, "targetId"); | 1322 PrintMissingParamError(js, "targetId"); |
| 1387 return true; | 1323 return true; |
| 1388 } | 1324 } |
| 1389 const char* limit_cstr = js->LookupParam("limit"); | 1325 const char* limit_cstr = js->LookupParam("limit"); |
| 1390 if (target_id == NULL) { | 1326 if (limit_cstr == NULL) { |
| 1391 PrintMissingParamError(js, "limit"); | 1327 PrintMissingParamError(js, "limit"); |
| 1392 return true; | 1328 return true; |
| 1393 } | 1329 } |
| 1394 intptr_t limit; | 1330 intptr_t limit; |
| 1395 if (!GetIntegerId(limit_cstr, &limit)) { | 1331 if (!GetIntegerId(limit_cstr, &limit)) { |
| 1396 PrintInvalidParamError(js, "limit"); | 1332 PrintInvalidParamError(js, "limit"); |
| 1397 return true; | 1333 return true; |
| 1398 } | 1334 } |
| 1399 | 1335 |
| 1400 Object& obj = Object::Handle(isolate); | 1336 Object& obj = Object::Handle(isolate); |
| 1401 ObjectIdRing::LookupResult lookup_result; | 1337 ObjectIdRing::LookupResult lookup_result; |
| 1402 { | 1338 { |
| 1403 HANDLESCOPE(isolate); | 1339 HANDLESCOPE(isolate); |
| 1404 obj = LookupHeapObject(isolate, target_id, &lookup_result); | 1340 obj = LookupHeapObject(isolate, target_id, &lookup_result); |
| 1405 } | 1341 } |
| 1406 if (obj.raw() == Object::sentinel().raw()) { | 1342 if (obj.raw() == Object::sentinel().raw()) { |
| 1407 if (lookup_result == ObjectIdRing::kCollected) { | 1343 if (lookup_result == ObjectIdRing::kCollected) { |
| 1408 PrintErrorWithKind( | 1344 PrintSentinel(js, "objects/collected", "<collected>"); |
| 1409 js, "RetainingPathCollected", | |
| 1410 "attempt to find a retaining path for a collected object\n"); | |
| 1411 return true; | |
| 1412 } else if (lookup_result == ObjectIdRing::kExpired) { | 1345 } else if (lookup_result == ObjectIdRing::kExpired) { |
| 1413 PrintErrorWithKind( | 1346 PrintSentinel(js, "objects/expired", "<expired>"); |
| 1414 js, "RetainingPathExpired", | 1347 } else { |
| 1415 "attempt to find a retaining path for an expired object\n"); | 1348 PrintInvalidParamError(js, "targetId"); |
| 1416 return true; | |
| 1417 } | 1349 } |
| 1418 PrintInvalidParamError(js, "targetId"); | |
| 1419 return true; | 1350 return true; |
| 1420 } | 1351 } |
| 1421 return PrintRetainingPath(isolate, &obj, limit, js); | 1352 return PrintRetainingPath(isolate, &obj, limit, js); |
| 1422 } | 1353 } |
| 1423 | 1354 |
| 1424 | 1355 |
| 1425 static const MethodParameter* get_retained_size_params[] = { | 1356 static const MethodParameter* get_retained_size_params[] = { |
| 1426 ISOLATE_PARAMETER, | 1357 ISOLATE_PARAMETER, |
| 1427 NULL, | 1358 NULL, |
| 1428 }; | 1359 }; |
| 1429 | 1360 |
| 1430 | 1361 |
| 1431 static bool GetRetainedSize(Isolate* isolate, JSONStream* js) { | 1362 static bool GetRetainedSize(Isolate* isolate, JSONStream* js) { |
| 1432 const char* target_id = js->LookupParam("targetId"); | 1363 const char* target_id = js->LookupParam("targetId"); |
| 1433 if (target_id == NULL) { | 1364 if (target_id == NULL) { |
| 1434 PrintMissingParamError(js, "targetId"); | 1365 PrintMissingParamError(js, "targetId"); |
| 1435 return true; | 1366 return true; |
| 1436 } | 1367 } |
| 1437 ObjectIdRing::LookupResult lookup_result; | 1368 ObjectIdRing::LookupResult lookup_result; |
| 1438 Object& obj = Object::Handle(LookupHeapObject(isolate, target_id, | 1369 Object& obj = Object::Handle(LookupHeapObject(isolate, target_id, |
| 1439 &lookup_result)); | 1370 &lookup_result)); |
| 1440 if (obj.raw() == Object::sentinel().raw()) { | 1371 if (obj.raw() == Object::sentinel().raw()) { |
| 1441 if (lookup_result == ObjectIdRing::kCollected) { | 1372 if (lookup_result == ObjectIdRing::kCollected) { |
| 1442 PrintErrorWithKind( | 1373 PrintSentinel(js, "objects/collected", "<collected>"); |
| 1443 js, "RetainedCollected", | |
| 1444 "attempt to calculate size retained by a collected object\n"); | |
| 1445 return true; | |
| 1446 } else if (lookup_result == ObjectIdRing::kExpired) { | 1374 } else if (lookup_result == ObjectIdRing::kExpired) { |
| 1447 PrintErrorWithKind( | 1375 PrintSentinel(js, "objects/expired", "<expired>"); |
| 1448 js, "RetainedExpired", | 1376 } else { |
| 1449 "attempt to calculate size retained by an expired object\n"); | 1377 PrintInvalidParamError(js, "targetId"); |
| 1450 return true; | |
| 1451 } | 1378 } |
| 1452 PrintInvalidParamError(js, "targetId"); | |
| 1453 return true; | 1379 return true; |
| 1454 } | 1380 } |
| 1455 if (obj.IsClass()) { | 1381 if (obj.IsClass()) { |
| 1456 const Class& cls = Class::Cast(obj); | 1382 const Class& cls = Class::Cast(obj); |
| 1457 ObjectGraph graph(isolate); | 1383 ObjectGraph graph(isolate); |
| 1458 intptr_t retained_size = graph.SizeRetainedByClass(cls.id()); | 1384 intptr_t retained_size = graph.SizeRetainedByClass(cls.id()); |
| 1459 const Object& result = Object::Handle(Integer::New(retained_size)); | 1385 const Object& result = Object::Handle(Integer::New(retained_size)); |
| 1460 result.PrintJSON(js, true); | 1386 result.PrintJSON(js, true); |
| 1461 return true; | 1387 return true; |
| 1462 } | 1388 } |
| 1463 if (obj.IsInstance() || obj.IsNull()) { | 1389 if (obj.IsInstance() || obj.IsNull()) { |
| 1464 // We don't use Instance::Cast here because it doesn't allow null. | 1390 // We don't use Instance::Cast here because it doesn't allow null. |
| 1465 ObjectGraph graph(isolate); | 1391 ObjectGraph graph(isolate); |
| 1466 intptr_t retained_size = graph.SizeRetainedByInstance(obj); | 1392 intptr_t retained_size = graph.SizeRetainedByInstance(obj); |
| 1467 const Object& result = Object::Handle(Integer::New(retained_size)); | 1393 const Object& result = Object::Handle(Integer::New(retained_size)); |
| 1468 result.PrintJSON(js, true); | 1394 result.PrintJSON(js, true); |
| 1469 return true; | 1395 return true; |
| 1470 } | 1396 } |
| 1471 PrintError(js, "%s: Invalid 'targetId' parameter value: " | 1397 js->PrintError(kInvalidParams, |
| 1472 "id '%s' does not correspond to a " | 1398 "%s: invalid 'targetId' parameter: " |
| 1473 "library, class, or instance", js->method(), target_id); | 1399 "id '%s' does not correspond to a " |
| 1400 "library, class, or instance", js->method(), target_id); | |
| 1474 return true; | 1401 return true; |
| 1475 } | 1402 } |
| 1476 | 1403 |
| 1477 | 1404 |
| 1478 static const MethodParameter* eval_params[] = { | 1405 static const MethodParameter* eval_params[] = { |
| 1479 ISOLATE_PARAMETER, | 1406 ISOLATE_PARAMETER, |
| 1480 NULL, | 1407 NULL, |
| 1481 }; | 1408 }; |
| 1482 | 1409 |
| 1483 | 1410 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 // We don't use Instance::Cast here because it doesn't allow null. | 1454 // We don't use Instance::Cast here because it doesn't allow null. |
| 1528 Instance& instance = Instance::Handle(isolate); | 1455 Instance& instance = Instance::Handle(isolate); |
| 1529 instance ^= obj.raw(); | 1456 instance ^= obj.raw(); |
| 1530 const Object& result = | 1457 const Object& result = |
| 1531 Object::Handle(instance.Evaluate(expr_str, | 1458 Object::Handle(instance.Evaluate(expr_str, |
| 1532 Array::empty_array(), | 1459 Array::empty_array(), |
| 1533 Array::empty_array())); | 1460 Array::empty_array())); |
| 1534 result.PrintJSON(js, true); | 1461 result.PrintJSON(js, true); |
| 1535 return true; | 1462 return true; |
| 1536 } | 1463 } |
| 1537 PrintError(js, "%s: Invalid 'targetId' parameter value: " | 1464 js->PrintError(kInvalidParams, |
| 1538 "id '%s' does not correspond to a " | 1465 "%s: invalid 'targetId' parameter: " |
| 1539 "library, class, or instance", js->method(), target_id); | 1466 "id '%s' does not correspond to a " |
| 1467 "library, class, or instance", js->method(), target_id); | |
| 1540 return true; | 1468 return true; |
| 1541 } | 1469 } |
| 1542 | 1470 |
| 1543 | 1471 |
| 1544 static const MethodParameter* eval_frame_params[] = { | 1472 static const MethodParameter* eval_frame_params[] = { |
| 1545 ISOLATE_PARAMETER, | 1473 ISOLATE_PARAMETER, |
| 1546 new UIntParameter("frame", true), | 1474 new UIntParameter("frame", true), |
| 1547 new MethodParameter("expression", true), | 1475 new MethodParameter("expression", true), |
| 1548 NULL, | 1476 NULL, |
| 1549 }; | 1477 }; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 }; | 1533 }; |
| 1606 | 1534 |
| 1607 | 1535 |
| 1608 static bool GetInstances(Isolate* isolate, JSONStream* js) { | 1536 static bool GetInstances(Isolate* isolate, JSONStream* js) { |
| 1609 const char* target_id = js->LookupParam("classId"); | 1537 const char* target_id = js->LookupParam("classId"); |
| 1610 if (target_id == NULL) { | 1538 if (target_id == NULL) { |
| 1611 PrintMissingParamError(js, "classId"); | 1539 PrintMissingParamError(js, "classId"); |
| 1612 return true; | 1540 return true; |
| 1613 } | 1541 } |
| 1614 const char* limit_cstr = js->LookupParam("limit"); | 1542 const char* limit_cstr = js->LookupParam("limit"); |
| 1615 if (target_id == NULL) { | 1543 if (limit_cstr == NULL) { |
| 1616 PrintMissingParamError(js, "limit"); | 1544 PrintMissingParamError(js, "limit"); |
| 1617 return true; | 1545 return true; |
| 1618 } | 1546 } |
| 1619 intptr_t limit; | 1547 intptr_t limit; |
| 1620 if (!GetIntegerId(limit_cstr, &limit)) { | 1548 if (!GetIntegerId(limit_cstr, &limit)) { |
| 1621 PrintInvalidParamError(js, "limit"); | 1549 PrintInvalidParamError(js, "limit"); |
| 1622 return true; | 1550 return true; |
| 1623 } | 1551 } |
| 1624 const Object& obj = | 1552 const Object& obj = |
| 1625 Object::Handle(LookupHeapObject(isolate, target_id, NULL)); | 1553 Object::Handle(LookupHeapObject(isolate, target_id, NULL)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1736 if (obj.IsClass()) { | 1664 if (obj.IsClass()) { |
| 1737 ClassCoverageFilter cf(Class::Cast(obj)); | 1665 ClassCoverageFilter cf(Class::Cast(obj)); |
| 1738 CodeCoverage::PrintJSON(isolate, js, &cf, as_sites); | 1666 CodeCoverage::PrintJSON(isolate, js, &cf, as_sites); |
| 1739 return true; | 1667 return true; |
| 1740 } | 1668 } |
| 1741 if (obj.IsFunction()) { | 1669 if (obj.IsFunction()) { |
| 1742 FunctionCoverageFilter ff(Function::Cast(obj)); | 1670 FunctionCoverageFilter ff(Function::Cast(obj)); |
| 1743 CodeCoverage::PrintJSON(isolate, js, &ff, as_sites); | 1671 CodeCoverage::PrintJSON(isolate, js, &ff, as_sites); |
| 1744 return true; | 1672 return true; |
| 1745 } | 1673 } |
| 1746 PrintError(js, "%s: Invalid 'targetId' parameter value: " | 1674 js->PrintError(kInvalidParams, |
| 1747 "id '%s' does not correspond to a " | 1675 "%s: invalid 'targetId' parameter: " |
| 1748 "script, library, class, or function", js->method(), target_id); | 1676 "id '%s' does not correspond to a " |
| 1677 "script, library, class, or function", | |
| 1678 js->method(), target_id); | |
| 1749 return true; | 1679 return true; |
| 1750 } | 1680 } |
| 1751 | 1681 |
| 1752 | 1682 |
| 1753 static const MethodParameter* get_coverage_params[] = { | 1683 static const MethodParameter* get_coverage_params[] = { |
| 1754 ISOLATE_PARAMETER, | 1684 ISOLATE_PARAMETER, |
| 1755 NULL, | 1685 NULL, |
| 1756 }; | 1686 }; |
| 1757 | 1687 |
| 1758 | 1688 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1789 Object& obj = Object::Handle(LookupHeapObject(isolate, script_id, NULL)); | 1719 Object& obj = Object::Handle(LookupHeapObject(isolate, script_id, NULL)); |
| 1790 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { | 1720 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { |
| 1791 PrintInvalidParamError(js, "scriptId"); | 1721 PrintInvalidParamError(js, "scriptId"); |
| 1792 return true; | 1722 return true; |
| 1793 } | 1723 } |
| 1794 const Script& script = Script::Cast(obj); | 1724 const Script& script = Script::Cast(obj); |
| 1795 const String& script_url = String::Handle(script.url()); | 1725 const String& script_url = String::Handle(script.url()); |
| 1796 SourceBreakpoint* bpt = | 1726 SourceBreakpoint* bpt = |
| 1797 isolate->debugger()->SetBreakpointAtLine(script_url, line); | 1727 isolate->debugger()->SetBreakpointAtLine(script_url, line); |
| 1798 if (bpt == NULL) { | 1728 if (bpt == NULL) { |
| 1799 PrintError(js, "Unable to set breakpoint at line %s", line_param); | 1729 js->PrintError(kNoBreakAtLine, NULL); |
| 1800 return true; | 1730 return true; |
| 1801 } | 1731 } |
| 1802 bpt->PrintJSON(js); | 1732 bpt->PrintJSON(js); |
| 1803 return true; | 1733 return true; |
| 1804 } | 1734 } |
| 1805 | 1735 |
| 1806 | 1736 |
| 1807 static const MethodParameter* add_breakpoint_at_entry_params[] = { | 1737 static const MethodParameter* add_breakpoint_at_entry_params[] = { |
| 1808 ISOLATE_PARAMETER, | 1738 ISOLATE_PARAMETER, |
| 1809 new IdParameter("functionId", true), | 1739 new IdParameter("functionId", true), |
| 1810 NULL, | 1740 NULL, |
| 1811 }; | 1741 }; |
| 1812 | 1742 |
| 1813 | 1743 |
| 1814 static bool AddBreakpointAtEntry(Isolate* isolate, JSONStream* js) { | 1744 static bool AddBreakpointAtEntry(Isolate* isolate, JSONStream* js) { |
| 1815 const char* function_id = js->LookupParam("functionId"); | 1745 const char* function_id = js->LookupParam("functionId"); |
| 1816 Object& obj = Object::Handle(LookupHeapObject(isolate, function_id, NULL)); | 1746 Object& obj = Object::Handle(LookupHeapObject(isolate, function_id, NULL)); |
| 1817 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { | 1747 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { |
| 1818 PrintInvalidParamError(js, "functionId"); | 1748 PrintInvalidParamError(js, "functionId"); |
| 1819 return true; | 1749 return true; |
| 1820 } | 1750 } |
| 1821 const Function& function = Function::Cast(obj); | 1751 const Function& function = Function::Cast(obj); |
| 1822 SourceBreakpoint* bpt = | 1752 SourceBreakpoint* bpt = |
| 1823 isolate->debugger()->SetBreakpointAtEntry(function); | 1753 isolate->debugger()->SetBreakpointAtEntry(function); |
| 1824 if (bpt == NULL) { | 1754 if (bpt == NULL) { |
| 1825 const String& funcName = String::Handle(function.PrettyName()); | 1755 js->PrintError(kNoBreakAtFunction, NULL); |
| 1826 PrintError(js, "Unable to set breakpoint at function '%s'", | |
| 1827 funcName.ToCString()); | |
| 1828 return true; | 1756 return true; |
| 1829 } | 1757 } |
| 1830 bpt->PrintJSON(js); | 1758 bpt->PrintJSON(js); |
| 1831 return true; | 1759 return true; |
| 1832 } | 1760 } |
| 1833 | 1761 |
| 1834 | 1762 |
| 1835 static const MethodParameter* remove_breakpoint_params[] = { | 1763 static const MethodParameter* remove_breakpoint_params[] = { |
| 1836 ISOLATE_PARAMETER, | 1764 ISOLATE_PARAMETER, |
| 1837 NULL, | 1765 NULL, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 Metric* current = isolate->metrics_list_head(); | 1823 Metric* current = isolate->metrics_list_head(); |
| 1896 while (current != NULL) { | 1824 while (current != NULL) { |
| 1897 const char* name = current->name(); | 1825 const char* name = current->name(); |
| 1898 ASSERT(name != NULL); | 1826 ASSERT(name != NULL); |
| 1899 if (strcmp(name, id) == 0) { | 1827 if (strcmp(name, id) == 0) { |
| 1900 current->PrintJSON(js); | 1828 current->PrintJSON(js); |
| 1901 return true; | 1829 return true; |
| 1902 } | 1830 } |
| 1903 current = current->next(); | 1831 current = current->next(); |
| 1904 } | 1832 } |
| 1905 PrintError(js, "Native Metric %s not found\n", id); | 1833 PrintInvalidParamError(js, "metricId"); |
| 1906 return true; | 1834 return true; |
| 1907 } | 1835 } |
| 1908 | 1836 |
| 1909 | 1837 |
| 1910 static bool HandleDartMetricsList(Isolate* isolate, JSONStream* js) { | 1838 static bool HandleDartMetricsList(Isolate* isolate, JSONStream* js) { |
| 1911 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | 1839 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
| 1912 const String& print_metrics_name = | 1840 const String& print_metrics_name = |
| 1913 String::Handle(String::New("_printMetrics")); | 1841 String::Handle(String::New("_printMetrics")); |
| 1914 ASSERT(!print_metrics_name.IsNull()); | 1842 ASSERT(!print_metrics_name.IsNull()); |
| 1915 const Function& print_metrics = Function::Handle( | 1843 const Function& print_metrics = Function::Handle( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1942 ASSERT(!args.IsNull()); | 1870 ASSERT(!args.IsNull()); |
| 1943 args.SetAt(0, arg0); | 1871 args.SetAt(0, arg0); |
| 1944 const Object& result = | 1872 const Object& result = |
| 1945 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); | 1873 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); |
| 1946 if (!result.IsNull()) { | 1874 if (!result.IsNull()) { |
| 1947 ASSERT(result.IsString()); | 1875 ASSERT(result.IsString()); |
| 1948 TextBuffer* buffer = js->buffer(); | 1876 TextBuffer* buffer = js->buffer(); |
| 1949 buffer->AddString(String::Cast(result).ToCString()); | 1877 buffer->AddString(String::Cast(result).ToCString()); |
| 1950 return true; | 1878 return true; |
| 1951 } | 1879 } |
| 1952 PrintError(js, "Dart Metric %s not found\n", id); | 1880 PrintInvalidParamError(js, "metricId"); |
| 1953 return true; | 1881 return true; |
| 1954 } | 1882 } |
| 1955 | 1883 |
| 1956 | 1884 |
| 1957 static const MethodParameter* get_isolate_metric_list_params[] = { | 1885 static const MethodParameter* get_isolate_metric_list_params[] = { |
| 1958 ISOLATE_PARAMETER, | 1886 ISOLATE_PARAMETER, |
| 1959 NULL, | 1887 NULL, |
| 1960 }; | 1888 }; |
| 1961 | 1889 |
| 1962 | 1890 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1991 static bool GetIsolateMetric(Isolate* isolate, JSONStream* js) { | 1919 static bool GetIsolateMetric(Isolate* isolate, JSONStream* js) { |
| 1992 const char* metric_id = js->LookupParam("metricId"); | 1920 const char* metric_id = js->LookupParam("metricId"); |
| 1993 if (metric_id == NULL) { | 1921 if (metric_id == NULL) { |
| 1994 PrintMissingParamError(js, "metricId"); | 1922 PrintMissingParamError(js, "metricId"); |
| 1995 return true; | 1923 return true; |
| 1996 } | 1924 } |
| 1997 // Verify id begins with "metrics/". | 1925 // Verify id begins with "metrics/". |
| 1998 static const char* kMetricIdPrefix = "metrics/"; | 1926 static const char* kMetricIdPrefix = "metrics/"; |
| 1999 static intptr_t kMetricIdPrefixLen = strlen(kMetricIdPrefix); | 1927 static intptr_t kMetricIdPrefixLen = strlen(kMetricIdPrefix); |
| 2000 if (strncmp(metric_id, kMetricIdPrefix, kMetricIdPrefixLen) != 0) { | 1928 if (strncmp(metric_id, kMetricIdPrefix, kMetricIdPrefixLen) != 0) { |
| 2001 PrintError(js, "Metric %s not found\n", metric_id); | 1929 PrintInvalidParamError(js, "metricId"); |
| 1930 return true; | |
| 2002 } | 1931 } |
| 2003 // Check if id begins with "metrics/native/". | 1932 // Check if id begins with "metrics/native/". |
| 2004 static const char* kNativeMetricIdPrefix = "metrics/native/"; | 1933 static const char* kNativeMetricIdPrefix = "metrics/native/"; |
| 2005 static intptr_t kNativeMetricIdPrefixLen = strlen(kNativeMetricIdPrefix); | 1934 static intptr_t kNativeMetricIdPrefixLen = strlen(kNativeMetricIdPrefix); |
| 2006 const bool native_metric = | 1935 const bool native_metric = |
| 2007 strncmp(metric_id, kNativeMetricIdPrefix, kNativeMetricIdPrefixLen) == 0; | 1936 strncmp(metric_id, kNativeMetricIdPrefix, kNativeMetricIdPrefixLen) == 0; |
| 2008 if (native_metric) { | 1937 if (native_metric) { |
| 2009 const char* id = metric_id + kNativeMetricIdPrefixLen; | 1938 const char* id = metric_id + kNativeMetricIdPrefixLen; |
| 2010 return HandleNativeMetric(isolate, js, id); | 1939 return HandleNativeMetric(isolate, js, id); |
| 2011 } | 1940 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2077 PrintInvalidParamError(js, "step"); | 2006 PrintInvalidParamError(js, "step"); |
| 2078 return true; | 2007 return true; |
| 2079 } | 2008 } |
| 2080 } | 2009 } |
| 2081 isolate->Resume(); | 2010 isolate->Resume(); |
| 2082 JSONObject jsobj(js); | 2011 JSONObject jsobj(js); |
| 2083 jsobj.AddProperty("type", "Success"); | 2012 jsobj.AddProperty("type", "Success"); |
| 2084 return true; | 2013 return true; |
| 2085 } | 2014 } |
| 2086 | 2015 |
| 2087 PrintError(js, "VM was not paused"); | 2016 js->PrintError(kVMMustBePaused, NULL); |
| 2088 return true; | 2017 return true; |
| 2089 } | 2018 } |
| 2090 | 2019 |
| 2091 | 2020 |
| 2092 static const MethodParameter* pause_params[] = { | 2021 static const MethodParameter* pause_params[] = { |
| 2093 ISOLATE_PARAMETER, | 2022 ISOLATE_PARAMETER, |
| 2094 NULL, | 2023 NULL, |
| 2095 }; | 2024 }; |
| 2096 | 2025 |
| 2097 | 2026 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2373 SourceBreakpoint* bpt = LookupBreakpoint(isolate, id); | 2302 SourceBreakpoint* bpt = LookupBreakpoint(isolate, id); |
| 2374 if (bpt != NULL) { | 2303 if (bpt != NULL) { |
| 2375 bpt->PrintJSON(js); | 2304 bpt->PrintJSON(js); |
| 2376 return true; | 2305 return true; |
| 2377 } | 2306 } |
| 2378 | 2307 |
| 2379 if (PrintMessage(js, isolate, id)) { | 2308 if (PrintMessage(js, isolate, id)) { |
| 2380 return true; | 2309 return true; |
| 2381 } | 2310 } |
| 2382 | 2311 |
| 2383 PrintError(js, "Unrecognized object id: %s\n", id); | 2312 PrintInvalidParamError(js, "objectId"); |
| 2384 return true; | 2313 return true; |
| 2385 } | 2314 } |
| 2386 | 2315 |
| 2387 | 2316 |
| 2388 static const MethodParameter* get_class_list_params[] = { | 2317 static const MethodParameter* get_class_list_params[] = { |
| 2389 ISOLATE_PARAMETER, | 2318 ISOLATE_PARAMETER, |
| 2390 NULL, | 2319 NULL, |
| 2391 }; | 2320 }; |
| 2392 | 2321 |
| 2393 | 2322 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2631 ServiceMethodDescriptor& method = service_methods_[i]; | 2560 ServiceMethodDescriptor& method = service_methods_[i]; |
| 2632 if (strcmp(method_name, method.name) == 0) { | 2561 if (strcmp(method_name, method.name) == 0) { |
| 2633 return &method; | 2562 return &method; |
| 2634 } | 2563 } |
| 2635 } | 2564 } |
| 2636 return NULL; | 2565 return NULL; |
| 2637 } | 2566 } |
| 2638 | 2567 |
| 2639 | 2568 |
| 2640 } // namespace dart | 2569 } // namespace dart |
| OLD | NEW |