OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #include "vm/service_event.h" |
| 6 |
| 7 namespace dart { |
| 8 |
| 9 // Translate from the legacy DebugEvent to a ServiceEvent. |
| 10 static ServiceEvent::EventType TranslateEventType( |
| 11 DebuggerEvent::EventType type) { |
| 12 switch (type) { |
| 13 case DebuggerEvent::kIsolateCreated: |
| 14 return ServiceEvent::kIsolateStart; |
| 15 |
| 16 case DebuggerEvent::kIsolateShutdown: |
| 17 return ServiceEvent::kIsolateExit; |
| 18 |
| 19 case DebuggerEvent::kBreakpointReached: |
| 20 return ServiceEvent::kPauseBreakpoint; |
| 21 |
| 22 case DebuggerEvent::kIsolateInterrupted: |
| 23 return ServiceEvent::kPauseInterrupted; |
| 24 |
| 25 case DebuggerEvent::kExceptionThrown: |
| 26 return ServiceEvent::kPauseException; |
| 27 |
| 28 default: |
| 29 UNREACHABLE(); |
| 30 return ServiceEvent::kIllegal; |
| 31 } |
| 32 } |
| 33 |
| 34 ServiceEvent::ServiceEvent(const DebuggerEvent* debugger_event) |
| 35 : isolate_(debugger_event->isolate()), |
| 36 type_(TranslateEventType(debugger_event->type())), |
| 37 breakpoint_(NULL), |
| 38 top_frame_(NULL), |
| 39 exception_(NULL) { |
| 40 DebuggerEvent::EventType type = debugger_event->type(); |
| 41 if (type == DebuggerEvent::kBreakpointReached) { |
| 42 set_breakpoint(debugger_event->breakpoint()); |
| 43 } |
| 44 if (type == DebuggerEvent::kExceptionThrown) { |
| 45 set_exception(debugger_event->exception()); |
| 46 } |
| 47 if (type == DebuggerEvent::kBreakpointReached || |
| 48 type == DebuggerEvent::kIsolateInterrupted || |
| 49 type == DebuggerEvent::kExceptionThrown) { |
| 50 set_top_frame(debugger_event->top_frame()); |
| 51 } |
| 52 } |
| 53 |
| 54 |
| 55 const char* ServiceEvent::EventTypeToCString(EventType type) { |
| 56 switch (type) { |
| 57 case kIsolateStart: |
| 58 return "IsolateStart"; |
| 59 case kIsolateExit: |
| 60 return "IsolateExit"; |
| 61 case kPauseStart: |
| 62 return "PauseStart"; |
| 63 case kPauseExit: |
| 64 return "PauseExit"; |
| 65 case kPauseBreakpoint: |
| 66 return "PauseBreakpoint"; |
| 67 case kPauseInterrupted: |
| 68 return "PauseInterrupted"; |
| 69 case kPauseException: |
| 70 return "PauseException"; |
| 71 case kResume: |
| 72 return "Resume"; |
| 73 case kBreakpointAdded: |
| 74 return "BreakpointAdded"; |
| 75 case kBreakpointResolved: |
| 76 return "BreakpointResolved"; |
| 77 case kBreakpointRemoved: |
| 78 return "BreakpointRemoved"; |
| 79 default: |
| 80 UNREACHABLE(); |
| 81 return "Unknown"; |
| 82 } |
| 83 } |
| 84 |
| 85 |
| 86 void ServiceEvent::PrintJSON(JSONStream* js) const { |
| 87 JSONObject jsobj(js); |
| 88 jsobj.AddProperty("type", "ServiceEvent"); |
| 89 jsobj.AddProperty("eventType", EventTypeToCString(type())); |
| 90 jsobj.AddProperty("isolate", isolate()); |
| 91 if (breakpoint() != NULL) { |
| 92 jsobj.AddProperty("breakpoint", breakpoint()); |
| 93 } |
| 94 if (top_frame() != NULL) { |
| 95 JSONObject jsFrame(&jsobj, "topFrame"); |
| 96 top_frame()->PrintToJSONObject(&jsFrame); |
| 97 } |
| 98 if (exception() != NULL) { |
| 99 jsobj.AddProperty("exception", *(exception())); |
| 100 } |
| 101 } |
| 102 |
| 103 } // namespace dart |
OLD | NEW |