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

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

Issue 869773007: Port _echo, etc commands to RPC (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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/service.h ('k') | runtime/vm/service/service.idl » ('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 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 frame->PrintToJSONObject(&jsobj); 1064 frame->PrintToJSONObject(&jsobj);
1065 // TODO(turnidge): Implement depth differently -- differentiate 1065 // TODO(turnidge): Implement depth differently -- differentiate
1066 // inlined frames. 1066 // inlined frames.
1067 jsobj.AddProperty("depth", i); 1067 jsobj.AddProperty("depth", i);
1068 } 1068 }
1069 return true; 1069 return true;
1070 } 1070 }
1071 1071
1072 1072
1073 static bool HandleCommonEcho(JSONObject* jsobj, JSONStream* js) { 1073 static bool HandleCommonEcho(JSONObject* jsobj, JSONStream* js) {
1074 jsobj->AddProperty("type", "message"); 1074 jsobj->AddProperty("type", "_EchoResponse");
1075 PrintArgumentsAndOptions(*jsobj, js); 1075 if (js->HasOption("text")) {
1076 jsobj->AddProperty("text", js->LookupOption("text"));
1077 }
1076 return true; 1078 return true;
1077 } 1079 }
1078 1080
1079 1081
1080 void Service::SendEchoEvent(Isolate* isolate) { 1082 void Service::SendEchoEvent(Isolate* isolate, const char* text) {
1081 JSONStream js; 1083 JSONStream js;
1082 { 1084 {
1083 JSONObject jsobj(&js); 1085 JSONObject jsobj(&js);
1084 jsobj.AddProperty("type", "ServiceEvent"); 1086 jsobj.AddProperty("type", "ServiceEvent");
1085 jsobj.AddPropertyF("id", "_echoEvent");
1086 jsobj.AddProperty("eventType", "_Echo"); 1087 jsobj.AddProperty("eventType", "_Echo");
1087 jsobj.AddProperty("isolate", isolate); 1088 jsobj.AddProperty("isolate", isolate);
1089 if (text != NULL) {
1090 jsobj.AddProperty("text", text);
1091 }
1088 } 1092 }
1089 const String& message = String::Handle(String::New(js.ToCString())); 1093 const String& message = String::Handle(String::New(js.ToCString()));
1090 uint8_t data[] = {0, 128, 255}; 1094 uint8_t data[] = {0, 128, 255};
1091 // TODO(koda): Add 'testing' event family. 1095 // TODO(koda): Add 'testing' event family.
1092 SendEvent(kEventFamilyDebug, message, data, sizeof(data)); 1096 SendEvent(kEventFamilyDebug, message, data, sizeof(data));
1093 } 1097 }
1094 1098
1095 1099
1100 static bool HandleIsolateTriggerEchoEvent(Isolate* isolate, JSONStream* js) {
1101 Service::SendEchoEvent(isolate, js->LookupOption("text"));
1102 JSONObject jsobj(js);
1103 return HandleCommonEcho(&jsobj, js);
1104 }
1105
1106
1096 static bool HandleIsolateEcho(Isolate* isolate, JSONStream* js) { 1107 static bool HandleIsolateEcho(Isolate* isolate, JSONStream* js) {
1097 JSONObject jsobj(js); 1108 JSONObject jsobj(js);
1098 jsobj.AddProperty("id", "_echo");
1099 if (js->num_arguments() == 2 && strcmp(js->GetArgument(1), "event") == 0) {
1100 Service::SendEchoEvent(isolate);
1101 }
1102 return HandleCommonEcho(&jsobj, js); 1109 return HandleCommonEcho(&jsobj, js);
1103 } 1110 }
1104 1111
1105 1112
1106 // Print an error message if there is no ID argument. 1113 // Print an error message if there is no ID argument.
1107 #define REQUIRE_COLLECTION_ID(collection) \ 1114 #define REQUIRE_COLLECTION_ID(collection) \
1108 if (js->num_arguments() == 1) { \ 1115 if (js->num_arguments() == 1) { \
1109 PrintError(js, "Must specify collection object id: /%s/id", collection); \ 1116 PrintError(js, "Must specify collection object id: /%s/id", collection); \
1110 return true; \ 1117 return true; \
1111 } 1118 }
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 { 2883 {
2877 NoGCScope no_gc; 2884 NoGCScope no_gc;
2878 ContainsAddressVisitor visitor(isolate, addr); 2885 ContainsAddressVisitor visitor(isolate, addr);
2879 object = isolate->heap()->FindObject(&visitor); 2886 object = isolate->heap()->FindObject(&visitor);
2880 } 2887 }
2881 object.PrintJSON(js, ref); 2888 object.PrintJSON(js, ref);
2882 return true; 2889 return true;
2883 } 2890 }
2884 2891
2885 2892
2886 static bool HandleMalformedJson(Isolate* isolate, JSONStream* js) { 2893 static bool HandleIsolateRespondWithMalformedJson(Isolate* isolate,
2894 JSONStream* js) {
2887 JSONObject jsobj(js); 2895 JSONObject jsobj(js);
2888 jsobj.AddProperty("a", "a"); 2896 jsobj.AddProperty("a", "a");
2889 JSONObject jsobj1(js); 2897 JSONObject jsobj1(js);
2890 jsobj1.AddProperty("a", "a"); 2898 jsobj1.AddProperty("a", "a");
2891 JSONObject jsobj2(js); 2899 JSONObject jsobj2(js);
2892 jsobj2.AddProperty("a", "a"); 2900 jsobj2.AddProperty("a", "a");
2893 JSONObject jsobj3(js); 2901 JSONObject jsobj3(js);
2894 jsobj3.AddProperty("a", "a"); 2902 jsobj3.AddProperty("a", "a");
2895 return true; 2903 return true;
2896 } 2904 }
2897 2905
2898 2906
2899 static bool HandleMalformedObject(Isolate* isolate, JSONStream* js) { 2907 static bool HandleIsolateRespondWithMalformedObject(Isolate* isolate,
2908 JSONStream* js) {
2900 JSONObject jsobj(js); 2909 JSONObject jsobj(js);
2901 jsobj.AddProperty("bart", "simpson"); 2910 jsobj.AddProperty("bart", "simpson");
2902 return true; 2911 return true;
2903 } 2912 }
2904 2913
2905 2914
2906 static IsolateMessageHandlerEntry isolate_handlers[] = { 2915 static IsolateMessageHandlerEntry isolate_handlers[] = {
2907 { "_malformedjson", HandleMalformedJson }, // debug
2908 { "_malformedobject", HandleMalformedObject }, // debug
2909 { "_echo", HandleIsolateEcho }, // debug
2910 { "", HandleIsolate }, // getObject 2916 { "", HandleIsolate }, // getObject
2911 { "address", HandleAddress }, // to do 2917 { "address", HandleAddress }, // to do
2912 { "classes", HandleClasses }, // getObject 2918 { "classes", HandleClasses }, // getObject
2913 { "code", HandleCode }, // getObject 2919 { "code", HandleCode }, // getObject
2914 { "libraries", HandleLibraries }, // getObject 2920 { "libraries", HandleLibraries }, // getObject
2915 { "metrics", HandleMetrics }, // to do - complex? 2921 { "metrics", HandleMetrics }, // to do - complex?
2916 { "objects", HandleObjects }, // getObject 2922 { "objects", HandleObjects }, // getObject
2917 { "scripts", HandleScripts }, // getObject 2923 { "scripts", HandleScripts }, // getObject
2918 }; 2924 };
2919 2925
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 { "addBreakpoint", HandleIsolateAddBreakpoint }, 3026 { "addBreakpoint", HandleIsolateAddBreakpoint },
3021 { "removeBreakpoint", HandleIsolateRemoveBreakpoint }, 3027 { "removeBreakpoint", HandleIsolateRemoveBreakpoint },
3022 { "getCoverage", HandleIsolateGetCoverage }, 3028 { "getCoverage", HandleIsolateGetCoverage },
3023 { "eval", HandleIsolateEval }, 3029 { "eval", HandleIsolateEval },
3024 { "getRetainedSize", HandleIsolateGetRetainedSize }, 3030 { "getRetainedSize", HandleIsolateGetRetainedSize },
3025 { "getRetainingPath", HandleIsolateGetRetainingPath }, 3031 { "getRetainingPath", HandleIsolateGetRetainingPath },
3026 { "getInboundReferences", HandleIsolateGetInboundReferences }, 3032 { "getInboundReferences", HandleIsolateGetInboundReferences },
3027 { "getInstances", HandleIsolateGetInstances }, 3033 { "getInstances", HandleIsolateGetInstances },
3028 { "requestHeapSnapshot", HandleIsolateRequestHeapSnapshot }, 3034 { "requestHeapSnapshot", HandleIsolateRequestHeapSnapshot },
3029 { "getClassList", HandleIsolateGetClassList }, 3035 { "getClassList", HandleIsolateGetClassList },
3030 { "getTypeArgumentsList", HandleIsolateGetTypeArgumentsList } 3036 { "getTypeArgumentsList", HandleIsolateGetTypeArgumentsList },
3037 { "_echo", HandleIsolateEcho },
3038 { "_triggerEchoEvent", HandleIsolateTriggerEchoEvent },
3039 { "_respondWithMalformedJson", HandleIsolateRespondWithMalformedJson },
3040 { "_respondWithMalformedObject", HandleIsolateRespondWithMalformedObject },
3031 }; 3041 };
3032 3042
3033 3043
3034 static IsolateMessageHandler FindIsolateMessageHandlerNew(const char* command) { 3044 static IsolateMessageHandler FindIsolateMessageHandlerNew(const char* command) {
3035 intptr_t num_message_handlers = sizeof(isolate_handlers_new) / 3045 intptr_t num_message_handlers = sizeof(isolate_handlers_new) /
3036 sizeof(isolate_handlers_new[0]); 3046 sizeof(isolate_handlers_new[0]);
3037 for (intptr_t i = 0; i < num_message_handlers; i++) { 3047 for (intptr_t i = 0; i < num_message_handlers; i++) {
3038 const IsolateMessageHandlerEntry& entry = isolate_handlers_new[i]; 3048 const IsolateMessageHandlerEntry& entry = isolate_handlers_new[i];
3039 if (strcmp(command, entry.command) == 0) { 3049 if (strcmp(command, entry.command) == 0) {
3040 return entry.handler; 3050 return entry.handler;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3183 js.PostReply(); 3193 js.PostReply();
3184 } 3194 }
3185 } 3195 }
3186 } 3196 }
3187 } 3197 }
3188 } 3198 }
3189 3199
3190 3200
3191 static bool HandleRootEcho(JSONStream* js) { 3201 static bool HandleRootEcho(JSONStream* js) {
3192 JSONObject jsobj(js); 3202 JSONObject jsobj(js);
3193 jsobj.AddProperty("id", "_echo");
3194 return HandleCommonEcho(&jsobj, js); 3203 return HandleCommonEcho(&jsobj, js);
3195 } 3204 }
3196 3205
3197 3206
3198 class ServiceIsolateVisitor : public IsolateVisitor { 3207 class ServiceIsolateVisitor : public IsolateVisitor {
3199 public: 3208 public:
3200 explicit ServiceIsolateVisitor(JSONArray* jsarr) 3209 explicit ServiceIsolateVisitor(JSONArray* jsarr)
3201 : jsarr_(jsarr) { 3210 : jsarr_(jsarr) {
3202 } 3211 }
3203 3212
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
3274 } 3283 }
3275 } 3284 }
3276 } 3285 }
3277 return true; 3286 return true;
3278 } else { 3287 } else {
3279 PrintError(js, "Command too long"); 3288 PrintError(js, "Command too long");
3280 return true; 3289 return true;
3281 } 3290 }
3282 } 3291 }
3283 3292
3284
3285 static RootMessageHandlerEntry root_handlers[] = { 3293 static RootMessageHandlerEntry root_handlers[] = {
3286 { "_echo", HandleRootEcho },
3287 { "vm", HandleVM }, 3294 { "vm", HandleVM },
3288 { "flags", HandleFlags }, 3295 { "flags", HandleFlags },
3289 }; 3296 };
3290 3297
3291 3298
3292 static RootMessageHandler FindRootMessageHandler(const char* command) { 3299 static RootMessageHandler FindRootMessageHandler(const char* command) {
3293 intptr_t num_message_handlers = sizeof(root_handlers) / 3300 intptr_t num_message_handlers = sizeof(root_handlers) /
3294 sizeof(root_handlers[0]); 3301 sizeof(root_handlers[0]);
3295 for (intptr_t i = 0; i < num_message_handlers; i++) { 3302 for (intptr_t i = 0; i < num_message_handlers; i++) {
3296 const RootMessageHandlerEntry& entry = root_handlers[i]; 3303 const RootMessageHandlerEntry& entry = root_handlers[i];
3297 if (strcmp(command, entry.command) == 0) { 3304 if (strcmp(command, entry.command) == 0) {
3298 return entry.handler; 3305 return entry.handler;
3299 } 3306 }
3300 } 3307 }
3301 if (FLAG_trace_service) { 3308 if (FLAG_trace_service) {
3302 OS::Print("vm-service: No root message handler for <%s>.\n", command); 3309 OS::Print("vm-service: No root message handler for <%s>.\n", command);
3303 } 3310 }
3304 return NULL; 3311 return NULL;
3305 } 3312 }
3306 3313
3307 3314
3308 static RootMessageHandlerEntry root_handlers_new[] = { 3315 static RootMessageHandlerEntry root_handlers_new[] = {
3309 { "getVM", HandleVM }, 3316 { "getVM", HandleVM },
3317 { "_echo", HandleRootEcho },
3310 }; 3318 };
3311 3319
3312 3320
3313 static RootMessageHandler FindRootMessageHandlerNew(const char* command) { 3321 static RootMessageHandler FindRootMessageHandlerNew(const char* command) {
3314 intptr_t num_message_handlers = sizeof(root_handlers_new) / 3322 intptr_t num_message_handlers = sizeof(root_handlers_new) /
3315 sizeof(root_handlers_new[0]); 3323 sizeof(root_handlers_new[0]);
3316 for (intptr_t i = 0; i < num_message_handlers; i++) { 3324 for (intptr_t i = 0; i < num_message_handlers; i++) {
3317 const RootMessageHandlerEntry& entry = root_handlers_new[i]; 3325 const RootMessageHandlerEntry& entry = root_handlers_new[i];
3318 if (strcmp(command, entry.command) == 0) { 3326 if (strcmp(command, entry.command) == 0) {
3319 return entry.handler; 3327 return entry.handler;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
3490 while (current != NULL) { 3498 while (current != NULL) {
3491 if (strcmp(name, current->name()) == 0) { 3499 if (strcmp(name, current->name()) == 0) {
3492 return current; 3500 return current;
3493 } 3501 }
3494 current = current->next(); 3502 current = current->next();
3495 } 3503 }
3496 return NULL; 3504 return NULL;
3497 } 3505 }
3498 3506
3499 } // namespace dart 3507 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/service/service.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698