Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index 77b6b3b475d119a088ce056c91ed88e78a54daa8..bb0018c06a0ec922bbffbf92b9f811ebb1108628 100644 |
--- a/runtime/vm/service.cc |
+++ b/runtime/vm/service.cc |
@@ -7,6 +7,8 @@ |
#include "vm/isolate.h" |
#include "vm/message.h" |
#include "vm/object.h" |
+#include "vm/object_id_ring.h" |
+#include "vm/object_store.h" |
#include "vm/port.h" |
#include "vm/service.h" |
@@ -116,6 +118,37 @@ void Service::HandleServiceMessage(Isolate* isolate, Dart_Port reply_port, |
} |
+static void PrintArgumentsAndOptions(JSONStream* js) { |
+ js->OpenObject("message"); |
+ js->OpenArray("arguments"); |
+ for (intptr_t i = 0; i < js->num_arguments(); i++) { |
+ js->PrintValue(js->GetArgument(i)); |
+ } |
+ js->CloseArray(); |
+ js->OpenArray("option_keys"); |
+ for (intptr_t i = 0; i < js->num_options(); i++) { |
+ js->PrintValue(js->GetOptionKey(i)); |
+ } |
+ js->CloseArray(); |
+ js->OpenArray("option_values"); |
+ for (intptr_t i = 0; i < js->num_options(); i++) { |
+ js->PrintValue(js->GetOptionValue(i)); |
+ } |
+ js->CloseArray(); |
+ js->CloseObject(); |
+} |
+ |
+ |
+static void PrintCollectionErrorResponse(const char* collection_name, |
+ JSONStream* js) { |
+ js->OpenObject(); |
+ js->PrintProperty("type", "error"); |
+ js->PrintfProperty("text", "Must specify collection object id: /%s/id", |
+ collection_name); |
+ js->CloseObject(); |
+} |
+ |
+ |
static void HandleName(Isolate* isolate, JSONStream* js) { |
js->OpenObject(); |
js->PrintProperty("type", "IsolateName"); |
@@ -154,8 +187,8 @@ static void HandleObjectHistogram(Isolate* isolate, JSONStream* js) { |
ObjectHistogram* histogram = Isolate::Current()->object_histogram(); |
if (histogram == NULL) { |
js->OpenObject(); |
- js->PrintProperty("type", "ObjectHistogram"); |
- js->PrintProperty("error", "Run with --print_object_histogram"); |
+ js->PrintProperty("type", "error"); |
+ js->PrintProperty("text", "Run with --print_object_histogram"); |
js->CloseObject(); |
return; |
} |
@@ -163,32 +196,83 @@ static void HandleObjectHistogram(Isolate* isolate, JSONStream* js) { |
} |
-static void PrintArgumentsAndOptions(JSONStream* js) { |
- js->OpenObject("message"); |
- js->OpenArray("arguments"); |
- for (intptr_t i = 0; i < js->num_arguments(); i++) { |
- js->PrintValue(js->GetArgument(i)); |
+static void HandleEcho(Isolate* isolate, JSONStream* js) { |
+ js->OpenObject(); |
+ js->PrintProperty("type", "message"); |
+ PrintArgumentsAndOptions(js); |
+ js->CloseObject(); |
+} |
+ |
+ |
+static void HandleLibraries(Isolate* isolate, JSONStream* js) { |
+ if (js->num_arguments() == 1) { |
+ js->PrintValue(Library::Handle(isolate->object_store()->root_library())); |
+ return; |
} |
- js->CloseArray(); |
- js->OpenArray("option_keys"); |
- for (intptr_t i = 0; i < js->num_options(); i++) { |
- js->PrintValue(js->GetOptionKey(i)); |
+ ASSERT(js->num_arguments() >= 2); |
+ ObjectIdRing* ring = isolate->object_id_ring(); |
+ ASSERT(ring != NULL); |
+ intptr_t id = atoi(js->GetArgument(1)); |
+ Object& obj = Object::Handle(ring->GetObjectForId(id)); |
+ if (!obj.IsLibrary()) { |
+ // Object is not a library, replace with null. |
+ obj = Object::null(); |
} |
- js->CloseArray(); |
- js->OpenArray("option_values"); |
- for (intptr_t i = 0; i < js->num_options(); i++) { |
- js->PrintValue(js->GetOptionValue(i)); |
+ js->PrintValue(obj, false); |
+} |
+ |
+ |
+static void HandleFunctions(Isolate* isolate, JSONStream* js) { |
+ if (js->num_arguments() == 1) { |
+ PrintCollectionErrorResponse("functions", js); |
+ return; |
} |
- js->CloseArray(); |
- js->CloseObject(); |
+ ASSERT(js->num_arguments() >= 2); |
+ ObjectIdRing* ring = isolate->object_id_ring(); |
+ ASSERT(ring != NULL); |
+ intptr_t id = atoi(js->GetArgument(1)); |
+ Object& obj = Object::Handle(ring->GetObjectForId(id)); |
+ if (!obj.IsFunction()) { |
+ // Object is not a function, replace with null. |
+ obj = Object::null(); |
+ } |
+ js->PrintValue(obj, false); |
} |
-static void HandleEcho(Isolate* isolate, JSONStream* js) { |
- js->OpenObject(); |
- js->PrintProperty("type", "message"); |
- PrintArgumentsAndOptions(js); |
- js->CloseObject(); |
+static void HandleClasses(Isolate* isolate, JSONStream* js) { |
+ if (js->num_arguments() == 1) { |
+ PrintCollectionErrorResponse("classes", js); |
+ return; |
+ } |
+ ASSERT(js->num_arguments() >= 2); |
+ ObjectIdRing* ring = isolate->object_id_ring(); |
+ ASSERT(ring != NULL); |
+ intptr_t id = atoi(js->GetArgument(1)); |
+ Object& obj = Object::Handle(ring->GetObjectForId(id)); |
+ if (!obj.IsClass()) { |
+ // Object is not a class, replace with null. |
+ obj = Object::null(); |
+ } |
+ js->PrintValue(obj, false); |
+} |
+ |
+ |
+static void HandleCodes(Isolate* isolate, JSONStream* js) { |
+ if (js->num_arguments() == 1) { |
+ PrintCollectionErrorResponse("codes", js); |
+ return; |
+ } |
+ ASSERT(js->num_arguments() >= 2); |
+ ObjectIdRing* ring = isolate->object_id_ring(); |
+ ASSERT(ring != NULL); |
+ intptr_t id = atoi(js->GetArgument(1)); |
+ Object& obj = Object::Handle(ring->GetObjectForId(id)); |
+ if (!obj.IsCode()) { |
Ivan Posva
2013/08/07 00:39:11
This code is duplicated across multiple functions
Cutch
2013/08/07 14:47:48
Done.
|
+ // Object is not a code, replace with null. |
+ obj = Object::null(); |
+ } |
+ js->PrintValue(obj, false); |
} |
@@ -196,6 +280,10 @@ static ServiceMessageHandlerEntry __message_handlers[] = { |
{ "name", HandleName }, |
{ "stacktrace", HandleStackTrace }, |
{ "objecthistogram", HandleObjectHistogram}, |
+ { "libraries", HandleLibraries }, |
+ { "functions", HandleFunctions }, |
+ { "classes", HandleClasses }, |
+ { "codes", HandleCodes }, |
{ "_echo", HandleEcho }, |
}; |