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 | #ifndef RUNTIME_VM_SERVICE_EVENT_H_ |
6 | #define RUNTIME_VM_SERVICE_EVENT_H_ |
7 | |
8 | #include "vm/globals.h" |
9 | #include "vm/heap/heap.h" |
10 | |
11 | namespace dart { |
12 | |
13 | class ActivationFrame; |
14 | class Breakpoint; |
15 | class Instance; |
16 | class Isolate; |
17 | class Object; |
18 | class StreamInfo; |
19 | class String; |
20 | class TimelineEventBlock; |
21 | |
22 | class ServiceEvent { |
23 | public: |
24 | enum EventKind { |
25 | kVMUpdate, // VM identity information has changed |
26 | kVMFlagUpdate, // VM flags updated |
27 | |
28 | kIsolateStart, // New isolate has started |
29 | kIsolateRunnable, // Isolate is ready to run |
30 | kIsolateExit, // Isolate has exited |
31 | kIsolateUpdate, // Isolate identity information has changed |
32 | kIsolateReload, // Result of a reload request |
33 | kServiceExtensionAdded, // A service extension was registered |
34 | |
35 | kPauseStart, // --pause-isolates-on-start |
36 | kPauseExit, // --pause-isolates-on-exit |
37 | kPauseBreakpoint, |
38 | kPauseInterrupted, |
39 | kPauseException, |
40 | kPausePostRequest, // isolate is paused after a service request. |
41 | kNone, // isolate has not been made runnable yet. |
42 | kResume, |
43 | kBreakpointAdded, |
44 | kBreakpointResolved, |
45 | kBreakpointRemoved, |
46 | kInspect, |
47 | kDebuggerSettingsUpdate, |
48 | |
49 | kGC, |
50 | |
51 | kEmbedder, |
52 | |
53 | kLogging, |
54 | |
55 | kExtension, |
56 | |
57 | kTimelineEvents, |
58 | // Sent when SetVMTimelineFlags is called. |
59 | kTimelineStreamSubscriptionsUpdate, |
60 | |
61 | kIllegal, |
62 | }; |
63 | |
64 | struct LogRecord { |
65 | int64_t sequence_number; |
66 | int64_t timestamp; |
67 | intptr_t level; |
68 | const String* name; |
69 | const String* message; |
70 | const Instance* zone; |
71 | const Object* error; |
72 | const Instance* stack_trace; |
73 | }; |
74 | |
75 | struct ExtensionEvent { |
76 | const String* event_kind; |
77 | const String* event_data; |
78 | }; |
79 | |
80 | ServiceEvent(Isolate* isolate, EventKind event_kind); |
81 | |
82 | Isolate* isolate() const { return isolate_; } |
83 | |
84 | // Used by the C embedding api. |
85 | Dart_Port isolate_id() const { return isolate_->main_port(); } |
86 | |
87 | EventKind kind() const { return kind_; } |
88 | |
89 | bool IsPause() const { |
90 | switch (kind()) { |
91 | case kPauseStart: |
92 | case kPauseExit: |
93 | case kPauseBreakpoint: |
94 | case kPauseInterrupted: |
95 | case kPauseException: |
96 | case kPausePostRequest: |
97 | return true; |
98 | default: |
99 | return false; |
100 | } |
101 | } |
102 | |
103 | const char* flag_name() const { return flag_name_; } |
104 | void set_flag_name(const char* flag) { flag_name_ = flag; } |
105 | |
106 | const char* flag_new_value() const { return flag_new_value_; } |
107 | void set_flag_new_value(const char* value) { flag_new_value_ = value; } |
108 | |
109 | const char* embedder_kind() const { return embedder_kind_; } |
110 | |
111 | const char* KindAsCString() const; |
112 | |
113 | void set_embedder_kind(const char* embedder_kind) { |
114 | embedder_kind_ = embedder_kind; |
115 | } |
116 | |
117 | const StreamInfo* stream_info() const; |
118 | const char* stream_id() const; |
119 | |
120 | void set_embedder_stream_id(const char* stream_id) { |
121 | embedder_stream_id_ = stream_id; |
122 | } |
123 | |
124 | Breakpoint* breakpoint() const { return breakpoint_; } |
125 | void set_breakpoint(Breakpoint* bpt) { |
126 | ASSERT(kind() == kPauseBreakpoint || kind() == kBreakpointAdded || |
127 | kind() == kBreakpointResolved || kind() == kBreakpointRemoved); |
128 | breakpoint_ = bpt; |
129 | } |
130 | |
131 | ActivationFrame* top_frame() const { return top_frame_; } |
132 | void set_top_frame(ActivationFrame* frame) { |
133 | ASSERT(kind() == kPauseBreakpoint || kind() == kPauseInterrupted || |
134 | kind() == kPauseException || kind() == kPausePostRequest || |
135 | kind() == kResume); |
136 | top_frame_ = frame; |
137 | } |
138 | |
139 | const String* extension_rpc() const { return extension_rpc_; } |
140 | void set_extension_rpc(const String* extension_rpc) { |
141 | extension_rpc_ = extension_rpc; |
142 | } |
143 | |
144 | const Object* exception() const { return exception_; } |
145 | void set_exception(const Object* exception) { |
146 | ASSERT(kind_ == kPauseException); |
147 | exception_ = exception; |
148 | } |
149 | |
150 | const Error* reload_error() const { |
151 | ASSERT(kind_ == kIsolateReload); |
152 | return reload_error_; |
153 | } |
154 | void set_reload_error(const Error* error) { |
155 | ASSERT(kind_ == kIsolateReload); |
156 | reload_error_ = error; |
157 | } |
158 | |
159 | bool at_async_jump() const { return at_async_jump_; } |
160 | void set_at_async_jump(bool value) { at_async_jump_ = value; } |
161 | |
162 | const Object* inspectee() const { return inspectee_; } |
163 | void set_inspectee(const Object* inspectee) { |
164 | ASSERT(kind_ == kInspect); |
165 | inspectee_ = inspectee; |
166 | } |
167 | |
168 | const Heap::GCStats* gc_stats() const { return gc_stats_; } |
169 | |
170 | void set_gc_stats(const Heap::GCStats* gc_stats) { gc_stats_ = gc_stats; } |
171 | |
172 | const uint8_t* bytes() const { return bytes_; } |
173 | |
174 | intptr_t bytes_length() const { return bytes_length_; } |
175 | |
176 | void set_bytes(const uint8_t* bytes, intptr_t bytes_length) { |
177 | bytes_ = bytes; |
178 | bytes_length_ = bytes_length; |
179 | } |
180 | |
181 | void set_log_record(const LogRecord& log_record) { log_record_ = log_record; } |
182 | |
183 | void set_extension_event(const ExtensionEvent& extension_event) { |
184 | extension_event_ = extension_event; |
185 | } |
186 | |
187 | void UpdateTimestamp(); |
188 | |
189 | int64_t timestamp() const { return timestamp_; } |
190 | |
191 | const TimelineEventBlock* timeline_event_block() const { |
192 | return timeline_event_block_; |
193 | } |
194 | |
195 | void set_timeline_event_block(const TimelineEventBlock* block) { |
196 | ASSERT(kind() == kTimelineEvents); |
197 | timeline_event_block_ = block; |
198 | } |
199 | |
200 | void PrintJSON(JSONStream* js) const; |
201 | |
202 | void (JSONObject* jsobj) const; |
203 | |
204 | private: |
205 | Isolate* isolate_; |
206 | EventKind kind_; |
207 | const char* flag_name_; |
208 | const char* flag_new_value_; |
209 | const char* embedder_kind_; |
210 | const char* embedder_stream_id_; |
211 | Breakpoint* breakpoint_; |
212 | ActivationFrame* top_frame_; |
213 | const TimelineEventBlock* timeline_event_block_; |
214 | const String* extension_rpc_; |
215 | const Object* exception_; |
216 | const Error* reload_error_; |
217 | const String* spawn_token_; |
218 | const String* spawn_error_; |
219 | bool at_async_jump_; |
220 | const Object* inspectee_; |
221 | const Heap::GCStats* gc_stats_; |
222 | const uint8_t* bytes_; |
223 | intptr_t bytes_length_; |
224 | LogRecord log_record_; |
225 | ExtensionEvent extension_event_; |
226 | int64_t timestamp_; |
227 | }; |
228 | |
229 | } // namespace dart |
230 | |
231 | #endif // RUNTIME_VM_SERVICE_EVENT_H_ |
232 | |