Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: runtime/vm/service.cc

Issue 184653003: Support displaying of types in the observatory (back-end only for now): (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 Field& field = Field::Handle(cls.FieldFromIndex(id)); 921 Field& field = Field::Handle(cls.FieldFromIndex(id));
922 if (field.IsNull()) { 922 if (field.IsNull()) {
923 PrintError(js, "Field %" Pd " not found", id); 923 PrintError(js, "Field %" Pd " not found", id);
924 return true; 924 return true;
925 } 925 }
926 field.PrintToJSONStream(js, false); 926 field.PrintToJSONStream(js, false);
927 return true; 927 return true;
928 } 928 }
929 929
930 930
931 static bool HandleClassesTypes(Isolate* isolate, const Class& cls,
932 JSONStream* js) {
933 if (js->num_arguments() == 3) {
934 JSONObject jsobj(js);
935 jsobj.AddProperty("type", "TypeList");
936 JSONArray members(&jsobj, "members");
937 const intptr_t num_types = cls.NumCanonicalTypes();
938 Type& type = Type::Handle();
939 for (intptr_t i = 0; i < num_types; i++) {
940 type = cls.CanonicalTypeFromIndex(i);
941 members.AddValue(type);
942 }
943 return true;
944 }
945 intptr_t id;
946 if (js->num_arguments() > 4) {
947 PrintError(js, "Command too long");
948 return true;
949 }
950 if (!GetIntegerId(js->GetArgument(3), &id)) {
951 PrintError(js, "Must specify collection object id: types/id");
952 return true;
953 }
954 Type& type = Type::Handle();
955 type ^= cls.CanonicalTypeFromIndex(id);
956 if (type.IsNull()) {
957 PrintError(js, "Canonical type %" Pd " not found", id);
958 return true;
959 }
960 type.PrintToJSONStream(js, false);
961 return true;
962 }
963
964
931 static bool HandleClasses(Isolate* isolate, JSONStream* js) { 965 static bool HandleClasses(Isolate* isolate, JSONStream* js) {
932 if (js->num_arguments() == 1) { 966 if (js->num_arguments() == 1) {
933 ClassTable* table = isolate->class_table(); 967 ClassTable* table = isolate->class_table();
934 table->PrintToJSONStream(js); 968 table->PrintToJSONStream(js);
935 return true; 969 return true;
936 } 970 }
937 ASSERT(js->num_arguments() >= 2); 971 ASSERT(js->num_arguments() >= 2);
938 intptr_t id; 972 intptr_t id;
939 if (!GetIntegerId(js->GetArgument(1), &id)) { 973 if (!GetIntegerId(js->GetArgument(1), &id)) {
940 PrintError(js, "Must specify collection object id: /classes/id"); 974 PrintError(js, "Must specify collection object id: /classes/id");
941 return true; 975 return true;
942 } 976 }
943 ClassTable* table = isolate->class_table(); 977 ClassTable* table = isolate->class_table();
944 if (!table->IsValidIndex(id)) { 978 if (!table->IsValidIndex(id)) {
945 PrintError(js, "%" Pd " is not a valid class id.", id);; 979 PrintError(js, "%" Pd " is not a valid class id.", id);
946 return true; 980 return true;
947 } 981 }
948 Class& cls = Class::Handle(table->At(id)); 982 Class& cls = Class::Handle(table->At(id));
949 if (js->num_arguments() == 2) { 983 if (js->num_arguments() == 2) {
950 cls.PrintToJSONStream(js, false); 984 cls.PrintToJSONStream(js, false);
951 return true; 985 return true;
952 } else if (js->num_arguments() >= 3) { 986 } else if (js->num_arguments() >= 3) {
953 const char* second = js->GetArgument(2); 987 const char* second = js->GetArgument(2);
954 if (strcmp(second, "eval") == 0) { 988 if (strcmp(second, "eval") == 0) {
955 return HandleClassesEval(isolate, cls, js); 989 return HandleClassesEval(isolate, cls, js);
956 } else if (strcmp(second, "closures") == 0) { 990 } else if (strcmp(second, "closures") == 0) {
957 return HandleClassesClosures(isolate, cls, js); 991 return HandleClassesClosures(isolate, cls, js);
958 } else if (strcmp(second, "fields") == 0) { 992 } else if (strcmp(second, "fields") == 0) {
959 return HandleClassesFields(isolate, cls, js); 993 return HandleClassesFields(isolate, cls, js);
960 } else if (strcmp(second, "functions") == 0) { 994 } else if (strcmp(second, "functions") == 0) {
961 return HandleClassesFunctions(isolate, cls, js); 995 return HandleClassesFunctions(isolate, cls, js);
962 } else if (strcmp(second, "implicit_closures") == 0) { 996 } else if (strcmp(second, "implicit_closures") == 0) {
963 return HandleClassesImplicitClosures(isolate, cls, js); 997 return HandleClassesImplicitClosures(isolate, cls, js);
964 } else if (strcmp(second, "dispatchers") == 0) { 998 } else if (strcmp(second, "dispatchers") == 0) {
965 return HandleClassesDispatchers(isolate, cls, js); 999 return HandleClassesDispatchers(isolate, cls, js);
1000 } else if (!strcmp(second, "types")) {
1001 return HandleClassesTypes(isolate, cls, js);
966 } else { 1002 } else {
967 PrintError(js, "Invalid sub collection %s", second); 1003 PrintError(js, "Invalid sub collection %s", second);
968 return true; 1004 return true;
969 } 1005 }
970 } 1006 }
971 UNREACHABLE(); 1007 UNREACHABLE();
972 return true; 1008 return true;
973 } 1009 }
974 1010
975 1011
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 return true; 1473 return true;
1438 } 1474 }
1439 if (isolate->message_handler()->pause_on_exit()) { 1475 if (isolate->message_handler()->pause_on_exit()) {
1440 isolate->message_handler()->set_pause_on_exit(false); 1476 isolate->message_handler()->set_pause_on_exit(false);
1441 return true; 1477 return true;
1442 } 1478 }
1443 return true; 1479 return true;
1444 } 1480 }
1445 1481
1446 1482
1483 static bool HandleTypeArguments(Isolate* isolate, JSONStream* js) {
1484 ObjectStore* object_store = isolate->object_store();
1485 const Array& table = Array::Handle(object_store->canonical_type_arguments());
1486 ASSERT(table.Length() > 0);
1487 TypeArguments& type_args = TypeArguments::Handle();
1488 const intptr_t table_size = table.Length() - 1;
1489 const intptr_t table_used = Smi::Value(Smi::RawCast(table.At(table_size)));
1490 bool only_with_instantiations = false;
1491 if (js->num_arguments() >= 2) {
1492 const char* second = js->GetArgument(1);
1493 if (strcmp(second, "withinstantiations") == 0) {
1494 only_with_instantiations = true;
1495 if (js->num_arguments() > 2) {
1496 PrintError(js, "Command too long");
1497 return true;
1498 }
1499 }
1500 }
1501 if ((js->num_arguments() == 1) || only_with_instantiations) {
1502 JSONObject jsobj(js);
1503 jsobj.AddProperty("type", "TypeArgumentsList");
1504 jsobj.AddProperty("table_size", table_size);
1505 jsobj.AddProperty("table_used", table_used);
1506 JSONArray members(&jsobj, "members");
1507 for (intptr_t i = 0; i < table_size; i++) {
1508 type_args ^= table.At(i);
1509 if (!type_args.IsNull()) {
1510 if (!only_with_instantiations || type_args.HasInstantiations()) {
1511 members.AddValue(type_args);
1512 }
1513 }
1514 }
1515 return true;
1516 }
1517 ASSERT((js->num_arguments() >= 2) && !only_with_instantiations);
1518 intptr_t id;
1519 if (!GetIntegerId(js->GetArgument(1), &id)) {
1520 // Note that the table index of the canonical type arguments will change
1521 // when the table grows. Should we not support this access at all?
1522 PrintError(js, "Must specify collection object id: /typearguments/id");
1523 return true;
1524 }
1525 if ((id < 0) || (id >= table_size) || (table.At(id) == Object::null())) {
1526 PrintError(js, "%" Pd " is not a valid typearguments id.", id);
1527 return true;
1528 }
1529 type_args ^= table.At(id);
1530 type_args.PrintToJSONStream(js, false);
1531 return true;
1532 }
1533
1534
1447 static bool HandleHeapMap(Isolate* isolate, JSONStream* js) { 1535 static bool HandleHeapMap(Isolate* isolate, JSONStream* js) {
1448 isolate->heap()->PrintHeapMapToJSONStream(js); 1536 isolate->heap()->PrintHeapMapToJSONStream(js);
1449 return true; 1537 return true;
1450 } 1538 }
1451 1539
1452 1540
1453 static IsolateMessageHandlerEntry isolate_handlers[] = { 1541 static IsolateMessageHandlerEntry isolate_handlers[] = {
1454 { "_echo", HandleIsolateEcho }, 1542 { "_echo", HandleIsolateEcho },
1455 { "", HandleIsolate }, 1543 { "", HandleIsolate },
1456 { "allocationprofile", HandleAllocationProfile }, 1544 { "allocationprofile", HandleAllocationProfile },
1457 { "classes", HandleClasses }, 1545 { "classes", HandleClasses },
1458 { "code", HandleCode }, 1546 { "code", HandleCode },
1459 { "coverage", HandleCoverage }, 1547 { "coverage", HandleCoverage },
1460 { "cpu", HandleCpu }, 1548 { "cpu", HandleCpu },
1461 { "debug", HandleDebug }, 1549 { "debug", HandleDebug },
1462 { "heapmap", HandleHeapMap }, 1550 { "heapmap", HandleHeapMap },
1463 { "libraries", HandleLibraries }, 1551 { "libraries", HandleLibraries },
1464 { "objects", HandleObjects }, 1552 { "objects", HandleObjects },
1465 { "profile", HandleProfile }, 1553 { "profile", HandleProfile },
1466 { "resume", HandleResume }, 1554 { "resume", HandleResume },
1467 { "scripts", HandleScripts }, 1555 { "scripts", HandleScripts },
1468 { "stacktrace", HandleStackTrace }, 1556 { "stacktrace", HandleStackTrace },
1557 { "typearguments", HandleTypeArguments },
1469 }; 1558 };
1470 1559
1471 1560
1472 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { 1561 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) {
1473 intptr_t num_message_handlers = sizeof(isolate_handlers) / 1562 intptr_t num_message_handlers = sizeof(isolate_handlers) /
1474 sizeof(isolate_handlers[0]); 1563 sizeof(isolate_handlers[0]);
1475 for (intptr_t i = 0; i < num_message_handlers; i++) { 1564 for (intptr_t i = 0; i < num_message_handlers; i++) {
1476 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; 1565 const IsolateMessageHandlerEntry& entry = isolate_handlers[i];
1477 if (strcmp(command, entry.command) == 0) { 1566 if (strcmp(command, entry.command) == 0) {
1478 return entry.handler; 1567 return entry.handler;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 while (current != NULL) { 1767 while (current != NULL) {
1679 if (strcmp(name, current->name()) == 0) { 1768 if (strcmp(name, current->name()) == 0) {
1680 return current; 1769 return current;
1681 } 1770 }
1682 current = current->next(); 1771 current = current->next();
1683 } 1772 }
1684 return NULL; 1773 return NULL;
1685 } 1774 }
1686 1775
1687 } // namespace dart 1776 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698