| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef BIN_DBG_MESSAGE_H_ | 5 #ifndef BIN_DBG_MESSAGE_H_ |
| 6 #define BIN_DBG_MESSAGE_H_ | 6 #define BIN_DBG_MESSAGE_H_ |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 int32_t cmd_idx_; // Isolate specific debugger command index. | 114 int32_t cmd_idx_; // Isolate specific debugger command index. |
| 115 char* buffer_; // Debugger command message. | 115 char* buffer_; // Debugger command message. |
| 116 int32_t buffer_len_; // Length of the debugger command message. | 116 int32_t buffer_len_; // Length of the debugger command message. |
| 117 int debug_fd_; // Debugger connection on which replies are to be sent. | 117 int debug_fd_; // Debugger connection on which replies are to be sent. |
| 118 | 118 |
| 119 DISALLOW_IMPLICIT_CONSTRUCTORS(DbgMessage); | 119 DISALLOW_IMPLICIT_CONSTRUCTORS(DbgMessage); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 | 122 |
| 123 // Class which represents a queue of debug command messages sent to an isolate. | 123 // Class which represents a queue of debug command messages sent to an isolate. |
| 124 class DbgMessageQueue { | 124 class DbgMsgQueue { |
| 125 public: | 125 public: |
| 126 static const int32_t kInvalidCommand = -1; | 126 DbgMsgQueue(Dart_IsolateId isolate_id, DbgMsgQueue* next) |
| 127 : is_running_(true), |
| 128 is_interrupted_(false), |
| 129 msglist_head_(NULL), |
| 130 msglist_tail_(NULL), |
| 131 queued_output_messages_(64), |
| 132 isolate_id_(isolate_id), |
| 133 next_(next) { |
| 134 } |
| 135 ~DbgMsgQueue() { |
| 136 DbgMessage* msg = msglist_head_; |
| 137 while (msglist_head_ != NULL) { |
| 138 msglist_head_ = msglist_head_->next(); |
| 139 delete msg; |
| 140 msg = msglist_head_; |
| 141 } |
| 142 msglist_tail_ = NULL; |
| 143 isolate_id_ = ILLEGAL_ISOLATE_ID; |
| 144 next_ = NULL; |
| 145 } |
| 127 | 146 |
| 128 DbgMessageQueue() : is_running_(true), | 147 // Accessors. |
| 129 is_interrupted_(false), | 148 Dart_IsolateId isolate_id() const { return isolate_id_; } |
| 130 msglist_head_(NULL), | 149 DbgMsgQueue* next() const { return next_; } |
| 131 msglist_tail_(NULL), | 150 void set_next(DbgMsgQueue* next) { next_ = next; } |
| 132 queued_output_messages_(64) { | |
| 133 } | |
| 134 ~DbgMessageQueue() { | |
| 135 // Cleanup the message queue | |
| 136 } | |
| 137 | 151 |
| 138 // Add specified debug command message to the queue. | 152 // Add specified debug command message to the queue. |
| 139 void AddMessage(int32_t cmd_idx, | 153 void AddMessage(int32_t cmd_idx, |
| 140 const char* start, | 154 const char* start, |
| 141 const char* end, | 155 const char* end, |
| 142 int debug_fd); | 156 int debug_fd); |
| 143 | 157 |
| 144 // Handle all debug command messages in the queue. | 158 // Handle all debug command messages in the queue. |
| 145 void HandleMessages(); | 159 void HandleMessages(); |
| 146 | 160 |
| 161 // Interrupt Isolate. |
| 162 void InterruptIsolate(); |
| 163 |
| 147 // Queue output messages, these are sent out when we hit an event. | 164 // Queue output messages, these are sent out when we hit an event. |
| 148 void QueueOutputMsg(dart::TextBuffer* msg); | 165 void QueueOutputMsg(dart::TextBuffer* msg); |
| 149 | 166 |
| 150 // Send all queued messages over to the debugger. | 167 // Send all queued messages over to the debugger. |
| 151 void SendQueuedMsgs(); | 168 void SendQueuedMsgs(); |
| 152 | 169 |
| 153 // Send breakpoint event message over to the debugger. | 170 // Send breakpoint event message over to the debugger. |
| 154 void SendBreakpointEvent(Dart_StackTrace trace); | 171 void SendBreakpointEvent(Dart_StackTrace trace); |
| 155 | 172 |
| 156 // Send Exception event message over to the debugger. | 173 // Send Exception event message over to the debugger. |
| 157 void SendExceptionEvent(Dart_Handle exception, Dart_StackTrace trace); | 174 void SendExceptionEvent(Dart_Handle exception, Dart_StackTrace trace); |
| 158 | 175 |
| 176 // Send Isolate event message over to the debugger. |
| 177 void SendIsolateEvent(Dart_IsolateId isolate_id, Dart_IsolateEvent kind); |
| 178 |
| 179 private: |
| 180 bool is_running_; // True if isolate is running and not in the debugger loop. |
| 181 bool is_interrupted_; // True if interrupt command is pending. |
| 182 |
| 183 DbgMessage* msglist_head_; // Start of debugger messages list. |
| 184 DbgMessage* msglist_tail_; // End of debugger messages list. |
| 185 |
| 186 // Text buffer that accumulates messages to be output. |
| 187 dart::TextBuffer queued_output_messages_; |
| 188 |
| 189 Dart_IsolateId isolate_id_; // Id of the isolate tied to this queue. |
| 190 |
| 191 DbgMsgQueue* next_; // Used for creating a list of message queues. |
| 192 |
| 193 // The isolate waits on this condition variable when it needs to process |
| 194 // debug messages. |
| 195 dart::Monitor msg_queue_lock_; |
| 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(DbgMsgQueue); |
| 198 }; |
| 199 |
| 200 |
| 201 // Maintains a list of message queues. |
| 202 class DbgMsgQueueList { |
| 203 public: |
| 204 static const int32_t kInvalidCommand = -1; |
| 205 |
| 159 // Initialize the message queue processing by setting up the appropriate | 206 // Initialize the message queue processing by setting up the appropriate |
| 160 // handlers. | 207 // handlers. |
| 161 static void Initialize(); | 208 static void Initialize(); |
| 162 | 209 |
| 163 // Parses the input message and returns the command index if the message | 210 // Parses the input message and returns the command index if the message |
| 164 // contains a valid isolate specific command. | 211 // contains a valid isolate specific command. |
| 165 // It returns kInvalidCommand otherwise. | 212 // It returns kInvalidCommand otherwise. |
| 166 static int32_t LookupIsolateCommand(const char* buf, int32_t buflen); | 213 static int32_t LookupIsolateCommand(const char* buf, int32_t buflen); |
| 167 | 214 |
| 215 // Add Debugger Message Queue corresponding to the Isolate. |
| 216 static DbgMsgQueue* AddIsolateMsgQueue(Dart_IsolateId isolate_id); |
| 217 |
| 168 // Get Debugger Message Queue corresponding to the Isolate. | 218 // Get Debugger Message Queue corresponding to the Isolate. |
| 169 static DbgMessageQueue* GetIsolateMessageQueue(Dart_Isolate isolate); | 219 static DbgMsgQueue* GetIsolateMsgQueue(Dart_IsolateId isolate_id); |
| 220 |
| 221 // Remove Debugger Message Queue corresponding to the Isolate. |
| 222 static void RemoveIsolateMsgQueue(Dart_IsolateId isolate_id); |
| 170 | 223 |
| 171 // Generic handlers for breakpoints, exceptions and delayed breakpoint | 224 // Generic handlers for breakpoints, exceptions and delayed breakpoint |
| 172 // resolution. | 225 // resolution. |
| 173 static void BptResolvedHandler(intptr_t bp_id, | 226 static void BptResolvedHandler(Dart_IsolateId isolate_id, |
| 227 intptr_t bp_id, |
| 174 Dart_Handle url, | 228 Dart_Handle url, |
| 175 intptr_t line_number); | 229 intptr_t line_number); |
| 176 static void BreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace); | 230 static void BreakpointHandler(Dart_IsolateId isolate_id, |
| 177 static void ExceptionThrownHandler(Dart_Handle exception, | 231 Dart_Breakpoint bpt, |
| 232 Dart_StackTrace trace); |
| 233 static void ExceptionThrownHandler(Dart_IsolateId isolate_id, |
| 234 Dart_Handle exception, |
| 178 Dart_StackTrace stack_trace); | 235 Dart_StackTrace stack_trace); |
| 179 static void IsolateEventHandler(Dart_IsolateId isolate_id, | 236 static void IsolateEventHandler(Dart_IsolateId isolate_id, |
| 180 Dart_IsolateEvent kind); | 237 Dart_IsolateEvent kind); |
| 181 | 238 |
| 182 private: | 239 private: |
| 183 bool is_running_; // True if isolate is running and not in the debugger loop. | 240 static DbgMsgQueue* list_; |
| 184 bool is_interrupted_; // True if interrupt command is pending. | 241 static dart::Mutex msg_queue_list_lock_; |
| 185 | 242 |
| 186 DbgMessage* msglist_head_; // Start of debugger messages list. | 243 DISALLOW_ALLOCATION(); |
| 187 DbgMessage* msglist_tail_; // End of debugger messages list. | 244 DISALLOW_IMPLICIT_CONSTRUCTORS(DbgMsgQueueList); |
| 188 | |
| 189 // Text buffer that accumulates messages to be output. | |
| 190 dart::TextBuffer queued_output_messages_; | |
| 191 | |
| 192 // The waits on this condition variable when it needs to process | |
| 193 // debug messages. | |
| 194 dart::Monitor msg_queue_lock_; | |
| 195 | |
| 196 DISALLOW_COPY_AND_ASSIGN(DbgMessageQueue); | |
| 197 }; | 245 }; |
| 198 | 246 |
| 199 #endif // BIN_DBG_MESSAGE_H_ | 247 #endif // BIN_DBG_MESSAGE_H_ |
| OLD | NEW |