Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: runtime/bin/dbg_message.cc

Issue 113513004: Handle vmservice messages while at breakpoint. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/dbg_message.h ('k') | runtime/bin/vmservice/client/deployed/web/index.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "bin/dbg_connection.h" 5 #include "bin/dbg_connection.h"
6 #include "bin/dbg_message.h" 6 #include "bin/dbg_message.h"
7 #include "bin/dartutils.h" 7 #include "bin/dartutils.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 ml.Notify(); 1010 ml.Notify();
1011 } else { 1011 } else {
1012 ASSERT(msglist_tail_ != NULL); 1012 ASSERT(msglist_tail_ != NULL);
1013 msglist_tail_->set_next(msg); 1013 msglist_tail_->set_next(msg);
1014 msglist_tail_ = msg; 1014 msglist_tail_ = msg;
1015 } 1015 }
1016 } 1016 }
1017 } 1017 }
1018 1018
1019 1019
1020 void DbgMsgQueue::HandleMessages() { 1020 void DbgMsgQueue::Notify() {
1021 MonitorLocker ml(&msg_queue_lock_);
1022 ml.Notify();
1023 }
1024
1025
1026 bool DbgMsgQueue::HandlePendingMessages() {
1027 // Handle all available debug messages, up to a resume request.
1021 bool resume_requested = false; 1028 bool resume_requested = false;
1022 MonitorLocker ml(&msg_queue_lock_); 1029 while (msglist_head_ != NULL && !resume_requested) {
1023 is_running_ = false; 1030 ASSERT(msglist_tail_ != NULL);
1024 while (!resume_requested) { 1031 DbgMessage* msg = msglist_head_;
1025 while (msglist_head_ == NULL) { 1032 msglist_head_ = msglist_head_->next();
1026 ASSERT(msglist_tail_ == NULL);
1027 dart::Monitor::WaitResult res = ml.Wait(); // Wait for debugger commands.
1028 ASSERT(res == dart::Monitor::kNotified);
1029 }
1030 while (msglist_head_ != NULL && !resume_requested) {
1031 ASSERT(msglist_tail_ != NULL);
1032 DbgMessage* msg = msglist_head_;
1033 msglist_head_ = msglist_head_->next();
1034 resume_requested = msg->HandleMessage();
1035 delete msg;
1036 }
1037 if (msglist_head_ == NULL) { 1033 if (msglist_head_ == NULL) {
1038 msglist_tail_ = NULL; 1034 msglist_tail_ = NULL;
1039 } 1035 }
1036 resume_requested = msg->HandleMessage();
1037 delete msg;
1040 } 1038 }
1039 return resume_requested;
1040 }
1041
1042
1043 void DbgMsgQueue::MessageLoop() {
1044 MonitorLocker ml(&msg_queue_lock_);
1045 is_running_ = false;
1046
1047 // Request notification on isolate messages. This allows us to
1048 // respond to vm service messages while at breakpoint.
1049 Dart_SetMessageNotifyCallback(DbgMsgQueueList::NotifyIsolate);
1050
1051 while (true) {
1052 // Handle all available vm service messages, up to a resume
1053 // request.
1054 if (Dart_HandleServiceMessages()) {
1055 break;
1056 }
1057
1058 // Handle all available debug messages, up to a resume request.
1059 if (HandlePendingMessages()) {
1060 break;
1061 }
1062
1063 // Wait for more debug or vm service messages.
1064 dart::Monitor::WaitResult res = ml.Wait();
1065 ASSERT(res == dart::Monitor::kNotified);
1066 }
1067 Dart_SetMessageNotifyCallback(NULL);
1041 is_interrupted_ = false; 1068 is_interrupted_ = false;
1042 is_running_ = true; 1069 is_running_ = true;
1043 } 1070 }
1044 1071
1045 1072
1046 void DbgMsgQueue::InterruptIsolate() { 1073 void DbgMsgQueue::InterruptIsolate() {
1047 Dart_Isolate isolate = Dart_GetIsolate(isolate_id_); 1074 Dart_Isolate isolate = Dart_GetIsolate(isolate_id_);
1048 MonitorLocker ml(&msg_queue_lock_); 1075 MonitorLocker ml(&msg_queue_lock_);
1049 if (is_running_ && !is_interrupted_) { 1076 if (is_running_ && !is_interrupted_) {
1050 is_interrupted_ = true; 1077 is_interrupted_ = true;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 MutexLocker ml(msg_queue_list_lock_); 1197 MutexLocker ml(msg_queue_list_lock_);
1171 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id); 1198 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id);
1172 if (queue != NULL) { 1199 if (queue != NULL) {
1173 queue->AddMessage(cmd_idx, start, end, debug_fd); 1200 queue->AddMessage(cmd_idx, start, end, debug_fd);
1174 return true; 1201 return true;
1175 } 1202 }
1176 return false; 1203 return false;
1177 } 1204 }
1178 1205
1179 1206
1207 void DbgMsgQueueList::NotifyIsolate(Dart_Isolate isolate) {
1208 MutexLocker ml(msg_queue_list_lock_);
1209 Dart_IsolateId isolate_id = Dart_GetIsolateId(isolate);
1210 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id);
1211 if (queue != NULL) {
1212 queue->Notify();
1213 }
1214 }
1215
1216
1180 bool DbgMsgQueueList::InterruptIsolate(Dart_IsolateId isolate_id) { 1217 bool DbgMsgQueueList::InterruptIsolate(Dart_IsolateId isolate_id) {
1181 MutexLocker ml(msg_queue_list_lock_); 1218 MutexLocker ml(msg_queue_list_lock_);
1182 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id); 1219 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id);
1183 if (queue != NULL) { 1220 if (queue != NULL) {
1184 queue->InterruptIsolate(); 1221 queue->InterruptIsolate();
1185 return true; 1222 return true;
1186 } 1223 }
1187 return false; 1224 return false;
1188 } 1225 }
1189 1226
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1323
1287 void DbgMsgQueueList::PausedEventHandler(Dart_IsolateId isolate_id, 1324 void DbgMsgQueueList::PausedEventHandler(Dart_IsolateId isolate_id,
1288 intptr_t bp_id, 1325 intptr_t bp_id,
1289 const Dart_CodeLocation& loc) { 1326 const Dart_CodeLocation& loc) {
1290 DebuggerConnectionHandler::WaitForConnection(); 1327 DebuggerConnectionHandler::WaitForConnection();
1291 Dart_EnterScope(); 1328 Dart_EnterScope();
1292 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1329 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1293 ASSERT(msg_queue != NULL); 1330 ASSERT(msg_queue != NULL);
1294 msg_queue->SendQueuedMsgs(); 1331 msg_queue->SendQueuedMsgs();
1295 msg_queue->SendBreakpointEvent(bp_id, loc); 1332 msg_queue->SendBreakpointEvent(bp_id, loc);
1296 msg_queue->HandleMessages(); 1333 msg_queue->MessageLoop();
1297 Dart_ExitScope(); 1334 Dart_ExitScope();
1298 } 1335 }
1299 1336
1300 1337
1301 void DbgMsgQueueList::ExceptionThrownHandler(Dart_IsolateId isolate_id, 1338 void DbgMsgQueueList::ExceptionThrownHandler(Dart_IsolateId isolate_id,
1302 Dart_Handle exception, 1339 Dart_Handle exception,
1303 Dart_StackTrace stack_trace) { 1340 Dart_StackTrace stack_trace) {
1304 DebuggerConnectionHandler::WaitForConnection(); 1341 DebuggerConnectionHandler::WaitForConnection();
1305 Dart_EnterScope(); 1342 Dart_EnterScope();
1306 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1343 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1307 ASSERT(msg_queue != NULL); 1344 ASSERT(msg_queue != NULL);
1308 msg_queue->SendQueuedMsgs(); 1345 msg_queue->SendQueuedMsgs();
1309 msg_queue->SendExceptionEvent(exception, stack_trace); 1346 msg_queue->SendExceptionEvent(exception, stack_trace);
1310 msg_queue->HandleMessages(); 1347 msg_queue->MessageLoop();
1311 Dart_ExitScope(); 1348 Dart_ExitScope();
1312 } 1349 }
1313 1350
1314 1351
1315 void DbgMsgQueueList::IsolateEventHandler(Dart_IsolateId isolate_id, 1352 void DbgMsgQueueList::IsolateEventHandler(Dart_IsolateId isolate_id,
1316 Dart_IsolateEvent kind) { 1353 Dart_IsolateEvent kind) {
1317 DebuggerConnectionHandler::WaitForConnection(); 1354 DebuggerConnectionHandler::WaitForConnection();
1318 Dart_EnterScope(); 1355 Dart_EnterScope();
1319 if (kind == kCreated) { 1356 if (kind == kCreated) {
1320 DbgMsgQueue* msg_queue = AddIsolateMsgQueue(isolate_id); 1357 DbgMsgQueue* msg_queue = AddIsolateMsgQueue(isolate_id);
1321 msg_queue->SendIsolateEvent(isolate_id, kind); 1358 msg_queue->SendIsolateEvent(isolate_id, kind);
1322 } else { 1359 } else {
1323 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1360 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1324 ASSERT(msg_queue != NULL); 1361 ASSERT(msg_queue != NULL);
1325 msg_queue->SendQueuedMsgs(); 1362 msg_queue->SendQueuedMsgs();
1326 msg_queue->SendIsolateEvent(isolate_id, kind); 1363 msg_queue->SendIsolateEvent(isolate_id, kind);
1327 if (kind == kInterrupted) { 1364 if (kind == kInterrupted) {
1328 msg_queue->HandleMessages(); 1365 msg_queue->MessageLoop();
1329 } else { 1366 } else {
1330 ASSERT(kind == kShutdown); 1367 ASSERT(kind == kShutdown);
1331 RemoveIsolateMsgQueue(isolate_id); 1368 RemoveIsolateMsgQueue(isolate_id);
1332 } 1369 }
1333 } 1370 }
1334 Dart_ExitScope(); 1371 Dart_ExitScope();
1335 } 1372 }
1336 1373
1337 } // namespace bin 1374 } // namespace bin
1338 } // namespace dart 1375 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dbg_message.h ('k') | runtime/bin/vmservice/client/deployed/web/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698