Index: runtime/vm/service_event.cc |
diff --git a/runtime/vm/service_event.cc b/runtime/vm/service_event.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9f7c63da614b33a48570369aea68c2d3c929b09f |
--- /dev/null |
+++ b/runtime/vm/service_event.cc |
@@ -0,0 +1,103 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#include "vm/service_event.h" |
+ |
+namespace dart { |
+ |
+// Translate from the legacy DebugEvent to a ServiceEvent. |
+static ServiceEvent::EventType TranslateEventType( |
+ DebuggerEvent::EventType type) { |
+ switch (type) { |
+ case DebuggerEvent::kIsolateCreated: |
+ return ServiceEvent::kIsolateStart; |
+ |
+ case DebuggerEvent::kIsolateShutdown: |
+ return ServiceEvent::kIsolateExit; |
+ |
+ case DebuggerEvent::kBreakpointReached: |
+ return ServiceEvent::kPauseBreakpoint; |
+ |
+ case DebuggerEvent::kIsolateInterrupted: |
+ return ServiceEvent::kPauseInterrupted; |
+ |
+ case DebuggerEvent::kExceptionThrown: |
+ return ServiceEvent::kPauseException; |
+ |
+ default: |
+ UNREACHABLE(); |
+ return ServiceEvent::kIllegal; |
+ } |
+} |
+ |
+ServiceEvent::ServiceEvent(const DebuggerEvent* debugger_event) |
+ : isolate_(debugger_event->isolate()), |
+ type_(TranslateEventType(debugger_event->type())), |
+ breakpoint_(NULL), |
+ top_frame_(NULL), |
+ exception_(NULL) { |
+ DebuggerEvent::EventType type = debugger_event->type(); |
+ if (type == DebuggerEvent::kBreakpointReached) { |
+ set_breakpoint(debugger_event->breakpoint()); |
+ } |
+ if (type == DebuggerEvent::kExceptionThrown) { |
+ set_exception(debugger_event->exception()); |
+ } |
+ if (type == DebuggerEvent::kBreakpointReached || |
+ type == DebuggerEvent::kIsolateInterrupted || |
+ type == DebuggerEvent::kExceptionThrown) { |
+ set_top_frame(debugger_event->top_frame()); |
+ } |
+} |
+ |
+ |
+const char* ServiceEvent::EventTypeToCString(EventType type) { |
+ switch (type) { |
+ case kIsolateStart: |
+ return "IsolateStart"; |
+ case kIsolateExit: |
+ return "IsolateExit"; |
+ case kPauseStart: |
+ return "PauseStart"; |
+ case kPauseExit: |
+ return "PauseExit"; |
+ case kPauseBreakpoint: |
+ return "PauseBreakpoint"; |
+ case kPauseInterrupted: |
+ return "PauseInterrupted"; |
+ case kPauseException: |
+ return "PauseException"; |
+ case kResume: |
+ return "Resume"; |
+ case kBreakpointAdded: |
+ return "BreakpointAdded"; |
+ case kBreakpointResolved: |
+ return "BreakpointResolved"; |
+ case kBreakpointRemoved: |
+ return "BreakpointRemoved"; |
+ default: |
+ UNREACHABLE(); |
+ return "Unknown"; |
+ } |
+} |
+ |
+ |
+void ServiceEvent::PrintJSON(JSONStream* js) const { |
+ JSONObject jsobj(js); |
+ jsobj.AddProperty("type", "ServiceEvent"); |
+ jsobj.AddProperty("eventType", EventTypeToCString(type())); |
+ jsobj.AddProperty("isolate", isolate()); |
+ if (breakpoint() != NULL) { |
+ jsobj.AddProperty("breakpoint", breakpoint()); |
+ } |
+ if (top_frame() != NULL) { |
+ JSONObject jsFrame(&jsobj, "topFrame"); |
+ top_frame()->PrintToJSONObject(&jsFrame); |
+ } |
+ if (exception() != NULL) { |
+ jsobj.AddProperty("exception", *(exception())); |
+ } |
+} |
+ |
+} // namespace dart |