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

Side by Side Diff: bin/dbg_message.cc

Issue 11144027: Fix race condition when posting debugger messages to the message queue (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 months 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 | « bin/dbg_message.h ('k') | no next file » | 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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 msglist_tail_ = NULL; 838 msglist_tail_ = NULL;
839 } 839 }
840 } 840 }
841 is_interrupted_ = false; 841 is_interrupted_ = false;
842 is_running_ = true; 842 is_running_ = true;
843 } 843 }
844 844
845 845
846 void DbgMsgQueue::InterruptIsolate() { 846 void DbgMsgQueue::InterruptIsolate() {
847 Dart_Isolate isolate = Dart_GetIsolate(isolate_id_); 847 Dart_Isolate isolate = Dart_GetIsolate(isolate_id_);
848 ASSERT(DbgMsgQueueList::GetIsolateMsgQueue(isolate_id_) == this);
849 MonitorLocker ml(&msg_queue_lock_); 848 MonitorLocker ml(&msg_queue_lock_);
850 if (is_running_ && !is_interrupted_) { 849 if (is_running_ && !is_interrupted_) {
851 is_interrupted_ = true; 850 is_interrupted_ = true;
852 Dart_InterruptIsolate(isolate); 851 Dart_InterruptIsolate(isolate);
853 } 852 }
854 } 853 }
855 854
856 855
857 void DbgMsgQueue::QueueOutputMsg(dart::TextBuffer* msg) { 856 void DbgMsgQueue::QueueOutputMsg(dart::TextBuffer* msg) {
858 queued_output_messages_.Printf("%s", msg->buf()); 857 queued_output_messages_.Printf("%s", msg->buf());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 while (debugger_commands[i].cmd_string != NULL) { 942 while (debugger_commands[i].cmd_string != NULL) {
944 if (strncmp(buf, debugger_commands[i].cmd_string, buflen) == 0) { 943 if (strncmp(buf, debugger_commands[i].cmd_string, buflen) == 0) {
945 return i; 944 return i;
946 } 945 }
947 i++; 946 i++;
948 } 947 }
949 return kInvalidCommand; 948 return kInvalidCommand;
950 } 949 }
951 950
952 951
952 bool DbgMsgQueueList::AddIsolateMessage(Dart_IsolateId isolate_id,
953 int32_t cmd_idx,
954 const char* start,
955 const char* end,
956 int debug_fd) {
957 MutexLocker ml(&msg_queue_list_lock_);
958 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id);
959 if (queue != NULL) {
960 queue->AddMessage(cmd_idx, start, end, debug_fd);
961 return true;
962 }
963 return false;
964 }
965
966
967 bool DbgMsgQueueList::InterruptIsolate(Dart_IsolateId isolate_id) {
968 MutexLocker ml(&msg_queue_list_lock_);
969 DbgMsgQueue* queue = DbgMsgQueueList::GetIsolateMsgQueueLocked(isolate_id);
970 if (queue != NULL) {
971 queue->InterruptIsolate();
972 return true;
973 }
974 return false;
975 }
976
977
953 DbgMsgQueue* DbgMsgQueueList::AddIsolateMsgQueue(Dart_IsolateId isolate_id) { 978 DbgMsgQueue* DbgMsgQueueList::AddIsolateMsgQueue(Dart_IsolateId isolate_id) {
954 MutexLocker ml(&msg_queue_list_lock_); 979 MutexLocker ml(&msg_queue_list_lock_);
955 980
956 DbgMsgQueue* queue = new DbgMsgQueue(isolate_id, list_); 981 DbgMsgQueue* queue = new DbgMsgQueue(isolate_id, list_);
957 ASSERT(queue != NULL); 982 ASSERT(queue != NULL);
958 list_ = queue; 983 list_ = queue;
959 return queue; 984 return queue;
960 } 985 }
961 986
962 987
963 DbgMsgQueue* DbgMsgQueueList::GetIsolateMsgQueue(Dart_IsolateId isolate_id) { 988 DbgMsgQueue* DbgMsgQueueList::GetIsolateMsgQueue(Dart_IsolateId isolate_id) {
964 MutexLocker ml(&msg_queue_list_lock_); 989 MutexLocker ml(&msg_queue_list_lock_);
990 ASSERT(Dart_GetIsolate(isolate_id) == Dart_CurrentIsolate());
991 return GetIsolateMsgQueueLocked(isolate_id);
992 }
965 993
994
995 DbgMsgQueue* DbgMsgQueueList::GetIsolateMsgQueueLocked(Dart_IsolateId id) {
966 if (list_ == NULL) { 996 if (list_ == NULL) {
967 return NULL; // No items in the list. 997 return NULL; // No items in the list.
968 } 998 }
969 999
970 // TODO(asiva): Remove once debug wire protocol has isolate id. 1000 // TODO(asiva): Remove once debug wire protocol has isolate id.
971 // For now we return the first item in the list as we are only supporting 1001 // For now we return the first item in the list as we are only supporting
972 // debugging of a single isolate. 1002 // debugging of a single isolate.
973 if (isolate_id == ILLEGAL_ISOLATE_ID) { 1003 if (id == ILLEGAL_ISOLATE_ID) {
974 return list_; 1004 return list_;
975 } 1005 }
976 1006
977 // Find message queue corresponding to isolate id. 1007 // Find message queue corresponding to isolate id.
978 DbgMsgQueue* iterator = list_; 1008 DbgMsgQueue* iterator = list_;
979 while (iterator != NULL && iterator->isolate_id() != isolate_id) { 1009 while (iterator != NULL && iterator->isolate_id() != id) {
980 iterator = iterator->next(); 1010 iterator = iterator->next();
981 } 1011 }
982 return iterator; 1012 return iterator;
983 } 1013 }
984 1014
985 1015
986 void DbgMsgQueueList::RemoveIsolateMsgQueue(Dart_IsolateId isolate_id) { 1016 void DbgMsgQueueList::RemoveIsolateMsgQueue(Dart_IsolateId isolate_id) {
987 MutexLocker ml(&msg_queue_list_lock_); 1017 MutexLocker ml(&msg_queue_list_lock_);
988 if (list_ == NULL) { 1018 if (list_ == NULL) {
989 return; // No items in the list. 1019 return; // No items in the list.
(...skipping 17 matching lines...) Expand all
1007 } 1037 }
1008 } 1038 }
1009 UNREACHABLE(); 1039 UNREACHABLE();
1010 } 1040 }
1011 1041
1012 1042
1013 void DbgMsgQueueList::BptResolvedHandler(Dart_IsolateId isolate_id, 1043 void DbgMsgQueueList::BptResolvedHandler(Dart_IsolateId isolate_id,
1014 intptr_t bp_id, 1044 intptr_t bp_id,
1015 Dart_Handle url, 1045 Dart_Handle url,
1016 intptr_t line_number) { 1046 intptr_t line_number) {
1017 ASSERT(Dart_GetIsolate(isolate_id) == Dart_CurrentIsolate());
1018 Dart_EnterScope(); 1047 Dart_EnterScope();
1019 dart::TextBuffer msg(128); 1048 dart::TextBuffer msg(128);
1020 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {"); 1049 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {");
1021 msg.Printf("\"breakpointId\": %"Pd", \"url\":", bp_id); 1050 msg.Printf("\"breakpointId\": %"Pd", \"url\":", bp_id);
1022 FormatEncodedString(&msg, url); 1051 FormatEncodedString(&msg, url);
1023 msg.Printf(",\"line\": %"Pd" }}", line_number); 1052 msg.Printf(",\"line\": %"Pd" }}", line_number);
1024 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1053 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1025 ASSERT(msg_queue != NULL); 1054 ASSERT(msg_queue != NULL);
1026 msg_queue->QueueOutputMsg(&msg); 1055 msg_queue->QueueOutputMsg(&msg);
1027 Dart_ExitScope(); 1056 Dart_ExitScope();
1028 } 1057 }
1029 1058
1030 1059
1031 void DbgMsgQueueList::BreakpointHandler(Dart_IsolateId isolate_id, 1060 void DbgMsgQueueList::BreakpointHandler(Dart_IsolateId isolate_id,
1032 Dart_Breakpoint bpt, 1061 Dart_Breakpoint bpt,
1033 Dart_StackTrace trace) { 1062 Dart_StackTrace trace) {
1034 ASSERT(Dart_GetIsolate(isolate_id) == Dart_CurrentIsolate());
1035 DebuggerConnectionHandler::WaitForConnection(); 1063 DebuggerConnectionHandler::WaitForConnection();
1036 Dart_EnterScope(); 1064 Dart_EnterScope();
1037 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1065 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1038 ASSERT(msg_queue != NULL); 1066 ASSERT(msg_queue != NULL);
1039 msg_queue->SendQueuedMsgs(); 1067 msg_queue->SendQueuedMsgs();
1040 msg_queue->SendBreakpointEvent(trace); 1068 msg_queue->SendBreakpointEvent(trace);
1041 msg_queue->HandleMessages(); 1069 msg_queue->HandleMessages();
1042 Dart_ExitScope(); 1070 Dart_ExitScope();
1043 } 1071 }
1044 1072
1045 1073
1046 void DbgMsgQueueList::ExceptionThrownHandler(Dart_IsolateId isolate_id, 1074 void DbgMsgQueueList::ExceptionThrownHandler(Dart_IsolateId isolate_id,
1047 Dart_Handle exception, 1075 Dart_Handle exception,
1048 Dart_StackTrace stack_trace) { 1076 Dart_StackTrace stack_trace) {
1049 ASSERT(Dart_GetIsolate(isolate_id) == Dart_CurrentIsolate());
1050 DebuggerConnectionHandler::WaitForConnection(); 1077 DebuggerConnectionHandler::WaitForConnection();
1051 Dart_EnterScope(); 1078 Dart_EnterScope();
1052 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1079 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1053 ASSERT(msg_queue != NULL); 1080 ASSERT(msg_queue != NULL);
1054 msg_queue->SendQueuedMsgs(); 1081 msg_queue->SendQueuedMsgs();
1055 msg_queue->SendExceptionEvent(exception, stack_trace); 1082 msg_queue->SendExceptionEvent(exception, stack_trace);
1056 msg_queue->HandleMessages(); 1083 msg_queue->HandleMessages();
1057 Dart_ExitScope(); 1084 Dart_ExitScope();
1058 } 1085 }
1059 1086
1060 1087
1061 void DbgMsgQueueList::IsolateEventHandler(Dart_IsolateId isolate_id, 1088 void DbgMsgQueueList::IsolateEventHandler(Dart_IsolateId isolate_id,
1062 Dart_IsolateEvent kind) { 1089 Dart_IsolateEvent kind) {
1063 DebuggerConnectionHandler::WaitForConnection(); 1090 DebuggerConnectionHandler::WaitForConnection();
1064 Dart_EnterScope(); 1091 Dart_EnterScope();
1065 if (kind == kCreated) { 1092 if (kind == kCreated) {
1066 DbgMsgQueue* msg_queue = AddIsolateMsgQueue(isolate_id); 1093 DbgMsgQueue* msg_queue = AddIsolateMsgQueue(isolate_id);
1067 msg_queue->SendIsolateEvent(isolate_id, kind); 1094 msg_queue->SendIsolateEvent(isolate_id, kind);
1068 } else { 1095 } else {
1069 ASSERT(Dart_GetIsolate(isolate_id) == Dart_CurrentIsolate());
1070 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id); 1096 DbgMsgQueue* msg_queue = GetIsolateMsgQueue(isolate_id);
1071 ASSERT(msg_queue != NULL); 1097 ASSERT(msg_queue != NULL);
1072 msg_queue->SendQueuedMsgs(); 1098 msg_queue->SendQueuedMsgs();
1073 msg_queue->SendIsolateEvent(isolate_id, kind); 1099 msg_queue->SendIsolateEvent(isolate_id, kind);
1074 if (kind == kInterrupted) { 1100 if (kind == kInterrupted) {
1075 msg_queue->HandleMessages(); 1101 msg_queue->HandleMessages();
1076 } else { 1102 } else {
1077 ASSERT(kind == kShutdown); 1103 ASSERT(kind == kShutdown);
1078 RemoveIsolateMsgQueue(isolate_id); 1104 RemoveIsolateMsgQueue(isolate_id);
1079 } 1105 }
1080 } 1106 }
1081 Dart_ExitScope(); 1107 Dart_ExitScope();
1082 } 1108 }
OLDNEW
« no previous file with comments | « bin/dbg_message.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698