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/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 REQUIRE_COLLECTION_ID("classes"); | |
|
siva
2013/09/17 17:25:33
We have already checked and processed for
'if (js-
Cutch
2013/09/19 23:57:39
Done.
| |
| 224 ASSERT(js->num_arguments() >= 2); | |
| 225 intptr_t id = atoi(js->GetArgument(1)); | |
| 226 ClassTable* table = isolate->class_table(); | |
| 227 if (!table->IsValidIndex(id)) { | |
| 228 Object& obj = Object::Handle(Object::null()); | |
| 229 obj.PrintToJSONStream(js, false); | |
|
siva
2013/09/17 17:25:33
You could do this as:
Object::null_object().Print
Cutch
2013/09/19 23:57:39
Done.
| |
| 226 } else { | 230 } else { |
| 227 PRINT_RING_OBJ(Library); | 231 Class& cls = Class::Handle(table->At(id)); |
| 232 cls.PrintToJSONStream(js, false); | |
| 228 } | 233 } |
| 229 } | 234 } |
| 230 | 235 |
| 231 | 236 |
| 232 static void HandleFunctions(Isolate* isolate, JSONStream* js) { | 237 static void HandleLibrary(Isolate* isolate, JSONStream* js) { |
| 233 REQUIRE_COLLECTION_ID("functions"); | 238 if (js->num_arguments() == 1) { |
| 234 PRINT_RING_OBJ(Function); | 239 const Library& lib = |
| 240 Library::Handle(isolate->object_store()->root_library()); | |
| 241 lib.PrintToJSONStream(js, false); | |
| 242 return; | |
| 243 } | |
| 244 PrintGenericError(js); | |
| 235 } | 245 } |
| 236 | 246 |
| 237 | 247 |
| 238 static void HandleClasses(Isolate* isolate, JSONStream* js) { | 248 static void HandleObjects(Isolate* isolate, JSONStream* js) { |
| 239 REQUIRE_COLLECTION_ID("classes"); | 249 REQUIRE_COLLECTION_ID("objects"); |
| 240 PRINT_RING_OBJ(Class); | 250 ASSERT(js->num_arguments() >= 2); |
| 251 ObjectIdRing* ring = isolate->object_id_ring(); | |
| 252 ASSERT(ring != NULL); | |
| 253 intptr_t id = atoi(js->GetArgument(1)); | |
| 254 Object& obj = Object::Handle(ring->GetObjectForId(id)); | |
| 255 obj.PrintToJSONStream(js, false); | |
| 241 } | 256 } |
| 242 | 257 |
| 243 | 258 |
| 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[] = { | 259 static ServiceMessageHandlerEntry __message_handlers[] = { |
| 251 { "name", HandleName }, | 260 { "name", HandleName }, |
| 252 { "stacktrace", HandleStackTrace }, | 261 { "stacktrace", HandleStackTrace }, |
| 253 { "objecthistogram", HandleObjectHistogram}, | 262 { "objecthistogram", HandleObjectHistogram}, |
| 254 { "libraries", HandleLibraries }, | 263 { "library", HandleLibrary }, |
| 255 { "functions", HandleFunctions }, | |
| 256 { "classes", HandleClasses }, | 264 { "classes", HandleClasses }, |
| 257 { "codes", HandleCodes }, | 265 { "objects", HandleObjects }, |
| 258 { "_echo", HandleEcho }, | 266 { "_echo", HandleEcho }, |
| 259 }; | 267 }; |
| 260 | 268 |
| 261 | 269 |
| 262 static void HandleFallthrough(Isolate* isolate, JSONStream* js) { | 270 static void HandleFallthrough(Isolate* isolate, JSONStream* js) { |
| 263 JSONObject jsobj(js); | 271 JSONObject jsobj(js); |
| 264 jsobj.AddProperty("type", "error"); | 272 jsobj.AddProperty("type", "error"); |
| 265 jsobj.AddProperty("text", "request not understood."); | 273 jsobj.AddProperty("text", "request not understood."); |
| 266 PrintArgumentsAndOptions(jsobj, js); | 274 PrintArgumentsAndOptions(jsobj, js); |
| 267 } | 275 } |
| 268 | 276 |
| 269 | 277 |
| 270 static ServiceMessageHandler FindServiceMessageHandler(const char* command) { | 278 static ServiceMessageHandler FindServiceMessageHandler(const char* command) { |
| 271 intptr_t num_message_handlers = sizeof(__message_handlers) / | 279 intptr_t num_message_handlers = sizeof(__message_handlers) / |
| 272 sizeof(__message_handlers[0]); | 280 sizeof(__message_handlers[0]); |
| 273 for (intptr_t i = 0; i < num_message_handlers; i++) { | 281 for (intptr_t i = 0; i < num_message_handlers; i++) { |
| 274 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; | 282 const ServiceMessageHandlerEntry& entry = __message_handlers[i]; |
| 275 if (!strcmp(command, entry.command)) { | 283 if (!strcmp(command, entry.command)) { |
| 276 return entry.handler; | 284 return entry.handler; |
| 277 } | 285 } |
| 278 } | 286 } |
| 279 return HandleFallthrough; | 287 return HandleFallthrough; |
| 280 } | 288 } |
| 281 | 289 |
| 282 } // namespace dart | 290 } // namespace dart |
| OLD | NEW |