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/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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 }; | 726 }; |
727 | 727 |
728 | 728 |
729 static bool GetStack(Isolate* isolate, JSONStream* js) { | 729 static bool GetStack(Isolate* isolate, JSONStream* js) { |
730 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 730 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
731 // Do we want the complete script object and complete local variable objects? | 731 // Do we want the complete script object and complete local variable objects? |
732 // This is true for dump requests. | 732 // This is true for dump requests. |
733 const bool full = BoolParameter::Parse(js->LookupParam("full"), false); | 733 const bool full = BoolParameter::Parse(js->LookupParam("full"), false); |
734 JSONObject jsobj(js); | 734 JSONObject jsobj(js); |
735 jsobj.AddProperty("type", "Stack"); | 735 jsobj.AddProperty("type", "Stack"); |
736 JSONArray jsarr(&jsobj, "frames"); | 736 { |
| 737 JSONArray jsarr(&jsobj, "frames"); |
737 | 738 |
738 intptr_t num_frames = stack->Length(); | 739 intptr_t num_frames = stack->Length(); |
739 for (intptr_t i = 0; i < num_frames; i++) { | 740 for (intptr_t i = 0; i < num_frames; i++) { |
740 ActivationFrame* frame = stack->FrameAt(i); | 741 ActivationFrame* frame = stack->FrameAt(i); |
741 JSONObject jsobj(&jsarr); | 742 JSONObject jsobj(&jsarr); |
742 frame->PrintToJSONObject(&jsobj, full); | 743 frame->PrintToJSONObject(&jsobj, full); |
743 // TODO(turnidge): Implement depth differently -- differentiate | 744 // TODO(turnidge): Implement depth differently -- differentiate |
744 // inlined frames. | 745 // inlined frames. |
745 jsobj.AddProperty("depth", i); | 746 jsobj.AddProperty("depth", i); |
| 747 } |
746 } | 748 } |
| 749 |
| 750 { |
| 751 MessageHandler::AcquiredQueues aq; |
| 752 isolate->message_handler()->AcquireQueues(&aq); |
| 753 jsobj.AddProperty("messages", aq.queue()); |
| 754 } |
| 755 |
747 return true; | 756 return true; |
748 } | 757 } |
749 | 758 |
750 | 759 |
751 static bool HandleCommonEcho(JSONObject* jsobj, JSONStream* js) { | 760 static bool HandleCommonEcho(JSONObject* jsobj, JSONStream* js) { |
752 jsobj->AddProperty("type", "_EchoResponse"); | 761 jsobj->AddProperty("type", "_EchoResponse"); |
753 if (js->HasParam("text")) { | 762 if (js->HasParam("text")) { |
754 jsobj->AddProperty("text", js->LookupParam("text")); | 763 jsobj->AddProperty("text", js->LookupParam("text")); |
755 } | 764 } |
756 return true; | 765 return true; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 const char* preview) { | 1165 const char* preview) { |
1157 JSONObject jsobj(js); | 1166 JSONObject jsobj(js); |
1158 jsobj.AddProperty("type", "Sentinel"); | 1167 jsobj.AddProperty("type", "Sentinel"); |
1159 jsobj.AddProperty("id", id); | 1168 jsobj.AddProperty("id", id); |
1160 jsobj.AddProperty("valueAsString", preview); | 1169 jsobj.AddProperty("valueAsString", preview); |
1161 } | 1170 } |
1162 | 1171 |
1163 | 1172 |
1164 static SourceBreakpoint* LookupBreakpoint(Isolate* isolate, const char* id) { | 1173 static SourceBreakpoint* LookupBreakpoint(Isolate* isolate, const char* id) { |
1165 size_t end_pos = strcspn(id, "/"); | 1174 size_t end_pos = strcspn(id, "/"); |
1166 const char* rest = NULL; | 1175 if (end_pos == strlen(id)) { |
1167 if (end_pos < strlen(id)) { | 1176 return false; |
1168 rest = id + end_pos + 1; // +1 for '/'. | |
1169 } | 1177 } |
| 1178 const char* rest = id + end_pos + 1; // +1 for '/'. |
1170 if (strncmp("breakpoints", id, end_pos) == 0) { | 1179 if (strncmp("breakpoints", id, end_pos) == 0) { |
1171 if (rest == NULL) { | |
1172 return NULL; | |
1173 } | |
1174 intptr_t bpt_id = 0; | 1180 intptr_t bpt_id = 0; |
1175 SourceBreakpoint* bpt = NULL; | 1181 SourceBreakpoint* bpt = NULL; |
1176 if (GetIntegerId(rest, &bpt_id)) { | 1182 if (GetIntegerId(rest, &bpt_id)) { |
1177 bpt = isolate->debugger()->GetBreakpointById(bpt_id); | 1183 bpt = isolate->debugger()->GetBreakpointById(bpt_id); |
1178 } | 1184 } |
1179 return bpt; | 1185 return bpt; |
1180 } | 1186 } |
1181 return NULL; | 1187 return NULL; |
1182 } | 1188 } |
1183 | 1189 |
1184 | 1190 |
| 1191 // Scans |isolate|'s message queue looking for a message with |id|. |
| 1192 // If found, the message is printed to |js| and true is returned. |
| 1193 // If not found, false is returned. |
| 1194 static bool PrintMessage(JSONStream* js, Isolate* isolate, const char* id) { |
| 1195 size_t end_pos = strcspn(id, "/"); |
| 1196 if (end_pos == strlen(id)) { |
| 1197 return false; |
| 1198 } |
| 1199 const char* rest = id + end_pos + 1; // +1 for '/'. |
| 1200 if (strncmp("messages", id, end_pos) == 0) { |
| 1201 uword message_id = 0; |
| 1202 if (GetUnsignedIntegerId(rest, &message_id, 16)) { |
| 1203 MessageHandler::AcquiredQueues aq; |
| 1204 isolate->message_handler()->AcquireQueues(&aq); |
| 1205 Message* message = aq.queue()->FindMessageById(message_id); |
| 1206 if (message == NULL) { |
| 1207 printf("Could not find message %" Px "\n", message_id); |
| 1208 // Not found. |
| 1209 return false; |
| 1210 } |
| 1211 SnapshotReader reader(message->data(), |
| 1212 message->len(), |
| 1213 Snapshot::kMessage, |
| 1214 isolate, |
| 1215 isolate->current_zone()); |
| 1216 const Object& msg_obj = Object::Handle(reader.ReadObject()); |
| 1217 msg_obj.PrintJSON(js); |
| 1218 return true; |
| 1219 } else { |
| 1220 printf("Could not get id from %s\n", rest); |
| 1221 } |
| 1222 } |
| 1223 return false; |
| 1224 } |
1185 | 1225 |
1186 | 1226 |
1187 static bool PrintInboundReferences(Isolate* isolate, | 1227 static bool PrintInboundReferences(Isolate* isolate, |
1188 Object* target, | 1228 Object* target, |
1189 intptr_t limit, | 1229 intptr_t limit, |
1190 JSONStream* js) { | 1230 JSONStream* js) { |
1191 ObjectGraph graph(isolate); | 1231 ObjectGraph graph(isolate); |
1192 Array& path = Array::Handle(Array::New(limit * 2)); | 1232 Array& path = Array::Handle(Array::New(limit * 2)); |
1193 intptr_t length = graph.InboundReferences(target, path); | 1233 intptr_t length = graph.InboundReferences(target, path); |
1194 JSONObject jsobj(js); | 1234 JSONObject jsobj(js); |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2324 return true; | 2364 return true; |
2325 } | 2365 } |
2326 | 2366 |
2327 // Handle non-heap objects. | 2367 // Handle non-heap objects. |
2328 SourceBreakpoint* bpt = LookupBreakpoint(isolate, id); | 2368 SourceBreakpoint* bpt = LookupBreakpoint(isolate, id); |
2329 if (bpt != NULL) { | 2369 if (bpt != NULL) { |
2330 bpt->PrintJSON(js); | 2370 bpt->PrintJSON(js); |
2331 return true; | 2371 return true; |
2332 } | 2372 } |
2333 | 2373 |
| 2374 if (PrintMessage(js, isolate, id)) { |
| 2375 return true; |
| 2376 } |
| 2377 |
2334 PrintError(js, "Unrecognized object id: %s\n", id); | 2378 PrintError(js, "Unrecognized object id: %s\n", id); |
2335 return true; | 2379 return true; |
2336 } | 2380 } |
2337 | 2381 |
2338 | 2382 |
2339 static const MethodParameter* get_class_list_params[] = { | 2383 static const MethodParameter* get_class_list_params[] = { |
2340 ISOLATE_PARAMETER, | 2384 ISOLATE_PARAMETER, |
2341 NULL, | 2385 NULL, |
2342 }; | 2386 }; |
2343 | 2387 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 ServiceMethodDescriptor& method = service_methods_[i]; | 2626 ServiceMethodDescriptor& method = service_methods_[i]; |
2583 if (strcmp(method_name, method.name) == 0) { | 2627 if (strcmp(method_name, method.name) == 0) { |
2584 return &method; | 2628 return &method; |
2585 } | 2629 } |
2586 } | 2630 } |
2587 return NULL; | 2631 return NULL; |
2588 } | 2632 } |
2589 | 2633 |
2590 | 2634 |
2591 } // namespace dart | 2635 } // namespace dart |
OLD | NEW |