| 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/debugger.h" | 5 #include "vm/debugger.h" |
| 6 #include "vm/heap_histogram.h" | 6 #include "vm/heap_histogram.h" |
| 7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
| 8 #include "vm/message.h" | 8 #include "vm/message.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/object_id_ring.h" | 10 #include "vm/object_id_ring.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 static void PrintCollectionErrorResponse(const char* collection_name, | 143 static void PrintCollectionErrorResponse(const char* collection_name, |
| 144 JSONStream* js) { | 144 JSONStream* js) { |
| 145 JSONObject jsobj(js); | 145 JSONObject jsobj(js); |
| 146 jsobj.AddProperty("type", "error"); | 146 jsobj.AddProperty("type", "error"); |
| 147 jsobj.AddPropertyF("text", "Must specify collection object id: /%s/id", | 147 jsobj.AddPropertyF("text", "Must specify collection object id: /%s/id", |
| 148 collection_name); | 148 collection_name); |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 static void PrintGenericError(JSONStream* js) { |
| 153 JSONObject jsobj(js); |
| 154 jsobj.AddProperty("type", "error"); |
| 155 jsobj.AddProperty("text", "Invalid request."); |
| 156 PrintArgumentsAndOptions(jsobj, js); |
| 157 } |
| 158 |
| 159 |
| 152 static void HandleName(Isolate* isolate, JSONStream* js) { | 160 static void HandleName(Isolate* isolate, JSONStream* js) { |
| 153 JSONObject jsobj(js); | 161 JSONObject jsobj(js); |
| 154 jsobj.AddProperty("type", "IsolateName"); | 162 jsobj.AddProperty("type", "IsolateName"); |
| 155 jsobj.AddProperty("id", static_cast<intptr_t>(isolate->main_port())); | 163 jsobj.AddProperty("id", static_cast<intptr_t>(isolate->main_port())); |
| 156 jsobj.AddProperty("name", isolate->name()); | 164 jsobj.AddProperty("name", isolate->name()); |
| 157 } | 165 } |
| 158 | 166 |
| 159 | 167 |
| 160 static void HandleStackTrace(Isolate* isolate, JSONStream* js) { | 168 static void HandleStackTrace(Isolate* isolate, JSONStream* js) { |
| 161 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 169 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 190 histogram->PrintToJSONStream(js); | 198 histogram->PrintToJSONStream(js); |
| 191 } | 199 } |
| 192 | 200 |
| 193 | 201 |
| 194 static void HandleEcho(Isolate* isolate, JSONStream* js) { | 202 static void HandleEcho(Isolate* isolate, JSONStream* js) { |
| 195 JSONObject jsobj(js); | 203 JSONObject jsobj(js); |
| 196 jsobj.AddProperty("type", "message"); | 204 jsobj.AddProperty("type", "message"); |
| 197 PrintArgumentsAndOptions(jsobj, js); | 205 PrintArgumentsAndOptions(jsobj, js); |
| 198 } | 206 } |
| 199 | 207 |
| 208 |
| 200 // Print an error message if there is no ID argument. | 209 // Print an error message if there is no ID argument. |
| 201 #define REQUIRE_COLLECTION_ID(collection) \ | 210 #define REQUIRE_COLLECTION_ID(collection) \ |
| 202 if (js->num_arguments() == 1) { \ | 211 if (js->num_arguments() == 1) { \ |
| 203 PrintCollectionErrorResponse(collection, js); \ | 212 PrintCollectionErrorResponse(collection, js); \ |
| 204 return; \ | 213 return; \ |
| 205 } | 214 } |
| 206 | 215 |
| 207 // Print a Dart object to the stream if found in ring. Otherwise print null. | |
| 208 #define PRINT_RING_OBJ(type) \ | |
| 209 ASSERT(js->num_arguments() >= 2); \ | |
| 210 ObjectIdRing* ring = isolate->object_id_ring(); \ | |
| 211 ASSERT(ring != NULL); \ | |
| 212 intptr_t id = atoi(js->GetArgument(1)); \ | |
| 213 Object& obj = Object::Handle(ring->GetObjectForId(id)); \ | |
| 214 if (!obj.Is##type()) { \ | |
| 215 /* Object is not type, replace with null. */ \ | |
| 216 obj = Object::null(); \ | |
| 217 } \ | |
| 218 obj.PrintToJSONStream(js, false) | |
| 219 | 216 |
| 220 | 217 static void HandleClasses(Isolate* isolate, JSONStream* js) { |
| 221 static void HandleLibraries(Isolate* isolate, JSONStream* js) { | |
| 222 if (js->num_arguments() == 1) { | 218 if (js->num_arguments() == 1) { |
| 223 const Library& lib = | 219 ClassTable* table = isolate->class_table(); |
| 224 Library::Handle(isolate->object_store()->root_library()); | 220 table->PrintToJSONStream(js); |
| 225 lib.PrintToJSONStream(js, true); | 221 return; |
| 222 } |
| 223 ASSERT(js->num_arguments() >= 2); |
| 224 intptr_t id = atoi(js->GetArgument(1)); |
| 225 ClassTable* table = isolate->class_table(); |
| 226 if (!table->IsValidIndex(id)) { |
| 227 Object::null_object().PrintToJSONStream(js, false); |
| 226 } else { | 228 } else { |
| 227 PRINT_RING_OBJ(Library); | 229 Class& cls = Class::Handle(table->At(id)); |
| 230 cls.PrintToJSONStream(js, false); |
| 228 } | 231 } |
| 229 } | 232 } |
| 230 | 233 |
| 231 | 234 |
| 232 static void HandleFunctions(Isolate* isolate, JSONStream* js) { | 235 static void HandleLibrary(Isolate* isolate, JSONStream* js) { |
| 233 REQUIRE_COLLECTION_ID("functions"); | 236 if (js->num_arguments() == 1) { |
| 234 PRINT_RING_OBJ(Function); | 237 const Library& lib = |
| 238 Library::Handle(isolate->object_store()->root_library()); |
| 239 lib.PrintToJSONStream(js, false); |
| 240 return; |
| 241 } |
| 242 PrintGenericError(js); |
| 235 } | 243 } |
| 236 | 244 |
| 237 | 245 |
| 238 static void HandleClasses(Isolate* isolate, JSONStream* js) { | 246 static void HandleObjects(Isolate* isolate, JSONStream* js) { |
| 239 REQUIRE_COLLECTION_ID("classes"); | 247 REQUIRE_COLLECTION_ID("objects"); |
| 240 PRINT_RING_OBJ(Class); | 248 ASSERT(js->num_arguments() >= 2); |
| 249 ObjectIdRing* ring = isolate->object_id_ring(); |
| 250 ASSERT(ring != NULL); |
| 251 intptr_t id = atoi(js->GetArgument(1)); |
| 252 Object& obj = Object::Handle(ring->GetObjectForId(id)); |
| 253 obj.PrintToJSONStream(js, false); |
| 241 } | 254 } |
| 242 | 255 |
| 243 | 256 |
| 244 static void HandleCodes(Isolate* isolate, JSONStream* js) { | |
| 245 REQUIRE_COLLECTION_ID("codes"); | |
| 246 PRINT_RING_OBJ(Code); | |
| 247 } | |
| 248 | |
| 249 | |
| 250 static ServiceMessageHandlerEntry __message_handlers[] = { | 257 static ServiceMessageHandlerEntry __message_handlers[] = { |
| 251 { "name", HandleName }, | 258 { "name", HandleName }, |
| 252 { "stacktrace", HandleStackTrace }, | 259 { "stacktrace", HandleStackTrace }, |
| 253 { "objecthistogram", HandleObjectHistogram}, | 260 { "objecthistogram", HandleObjectHistogram}, |
| 254 { "libraries", HandleLibraries }, | 261 { "library", HandleLibrary }, |
| 255 { "functions", HandleFunctions }, | |
| 256 { "classes", HandleClasses }, | 262 { "classes", HandleClasses }, |
| 257 { "codes", HandleCodes }, | 263 { "objects", HandleObjects }, |
| 258 { "_echo", HandleEcho }, | 264 { "_echo", HandleEcho }, |
| 259 }; | 265 }; |
| 260 | 266 |
| 261 | 267 |
| 262 static void HandleFallthrough(Isolate* isolate, JSONStream* js) { | 268 static void HandleFallthrough(Isolate* isolate, JSONStream* js) { |
| 263 JSONObject jsobj(js); | 269 JSONObject jsobj(js); |
| 264 jsobj.AddProperty("type", "error"); | 270 jsobj.AddProperty("type", "error"); |
| 265 jsobj.AddProperty("text", "request not understood."); | 271 jsobj.AddProperty("text", "request not understood."); |
| 266 PrintArgumentsAndOptions(jsobj, js); | 272 PrintArgumentsAndOptions(jsobj, js); |
| 267 } | 273 } |
| 268 | 274 |
| 269 | 275 |
| 270 static ServiceMessageHandler FindServiceMessageHandler(const char* command) { | 276 static ServiceMessageHandler FindServiceMessageHandler(const char* command) { |
| 271 intptr_t num_message_handlers = sizeof(__message_handlers) / | 277 intptr_t num_message_handlers = sizeof(__message_handlers) / |
| 272 sizeof(__message_handlers[0]); | 278 sizeof(__message_handlers[0]); |
| 273 for (intptr_t i = 0; i < num_message_handlers; i++) { | 279 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 274 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; | 280 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; |
| 275 if (!strcmp(command, entry.command)) { | 281 if (!strcmp(command, entry.command)) { |
| 276 return entry.handler; | 282 return entry.handler; |
| 277 } | 283 } |
| 278 } | 284 } |
| 279 return HandleFallthrough; | 285 return HandleFallthrough; |
| 280 } | 286 } |
| 281 | 287 |
| 282 } // namespace dart | 288 } // namespace dart |
| OLD | NEW |