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 #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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 return NULL; | 98 return NULL; |
99 } | 99 } |
100 intptr_t buflen = pr.ValueLen() + 1; | 100 intptr_t buflen = pr.ValueLen() + 1; |
101 char* param_chars = reinterpret_cast<char*>(malloc(buflen)); | 101 char* param_chars = reinterpret_cast<char*>(malloc(buflen)); |
102 pr.GetValueChars(param_chars, buflen); | 102 pr.GetValueChars(param_chars, buflen); |
103 // TODO(hausner): Decode escape sequences. | 103 // TODO(hausner): Decode escape sequences. |
104 return param_chars; | 104 return param_chars; |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) { | 108 static void FormatEncodedChars(dart::TextBuffer* buf, Dart_Handle str) { |
109 intptr_t str_len = 0; | 109 intptr_t str_len = 0; |
110 Dart_Handle res = Dart_StringLength(str, &str_len); | 110 Dart_Handle res = Dart_StringLength(str, &str_len); |
111 ASSERT_NOT_ERROR(res); | 111 ASSERT_NOT_ERROR(res); |
112 uint16_t* codepoints = | 112 uint16_t* codepoints = |
113 reinterpret_cast<uint16_t*>(malloc(str_len * sizeof(uint16_t))); | 113 reinterpret_cast<uint16_t*>(malloc(str_len * sizeof(uint16_t))); |
114 ASSERT(codepoints != NULL); | 114 ASSERT(codepoints != NULL); |
115 intptr_t actual_len = str_len; | 115 intptr_t actual_len = str_len; |
116 res = Dart_StringToUTF16(str, codepoints, &actual_len); | 116 res = Dart_StringToUTF16(str, codepoints, &actual_len); |
117 ASSERT_NOT_ERROR(res); | 117 ASSERT_NOT_ERROR(res); |
118 ASSERT(str_len == actual_len); | 118 ASSERT(str_len == actual_len); |
119 buf->AddChar('\"'); | |
120 for (int i = 0; i < str_len; i++) { | 119 for (int i = 0; i < str_len; i++) { |
121 buf->AddEscapedChar(codepoints[i]); | 120 buf->AddEscapedChar(codepoints[i]); |
122 } | 121 } |
123 buf->AddChar('\"'); | |
124 free(codepoints); | 122 free(codepoints); |
125 } | 123 } |
126 | 124 |
127 | 125 |
128 static void FormatErrorMsg(dart::TextBuffer* buf, Dart_Handle err) { | 126 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) { |
129 ASSERT(Dart_IsError(err)); | 127 buf->AddChar('\"'); |
130 const char* msg = Dart_GetError(err); | 128 FormatEncodedChars(buf, str); |
131 Dart_Handle str = Dart_NewStringFromCString(msg); | 129 buf->AddChar('\"'); |
132 FormatEncodedString(buf, str); | |
133 } | 130 } |
134 | 131 |
135 | 132 |
136 static void FormatTextualValue(dart::TextBuffer* buf, Dart_Handle object) { | 133 static void FormatTextualListElement(dart::TextBuffer* buf, |
137 Dart_Handle text; | 134 Dart_Handle object) { |
138 if (Dart_IsNull(object)) { | 135 if (Dart_IsList(object)) { |
139 text = Dart_Null(); | 136 buf->Printf("[...]"); |
137 } else if (Dart_IsNull(object)) { | |
138 buf->Printf("null"); | |
139 } else if (Dart_IsError(object)) { | |
140 buf->Printf("#ERROR"); | |
140 } else { | 141 } else { |
141 Dart_ExceptionPauseInfo savedState = Dart_GetExceptionPauseInfo(); | 142 const bool need_quotes = Dart_IsString(object); |
142 | 143 Dart_Handle text = Dart_ToString(object); |
143 // TODO(hausner): Check whether recursive/reentrant pauses on exceptions | 144 if (need_quotes) buf->Printf("\\\""); |
144 // should be prevented in Debugger::SignalExceptionThrown() instead. | 145 if (Dart_IsNull(text)) { |
145 if (savedState != kNoPauseOnExceptions) { | 146 buf->Printf("null"); |
146 Dart_Handle res = Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); | 147 } else if (Dart_IsError(text)) { |
147 ASSERT_NOT_ERROR(res); | 148 buf->Printf("#ERROR"); |
149 } else { | |
150 FormatEncodedChars(buf, text); | |
148 } | 151 } |
149 | 152 if (need_quotes) buf->Printf("\\\""); |
150 text = Dart_ToString(object); | |
151 | |
152 if (savedState != kNoPauseOnExceptions) { | |
153 Dart_Handle res = Dart_SetExceptionPauseInfo(savedState); | |
154 ASSERT_NOT_ERROR(res); | |
155 } | |
156 } | |
157 buf->Printf("\"text\":"); | |
158 if (Dart_IsNull(text)) { | |
159 buf->Printf("null"); | |
160 } else if (Dart_IsError(text)) { | |
161 FormatErrorMsg(buf, text); | |
162 } else { | |
163 FormatEncodedString(buf, text); | |
164 } | 153 } |
165 } | 154 } |
166 | 155 |
156 | |
157 static void FormatTextualListValue(dart::TextBuffer* buf, Dart_Handle list) { | |
srdjan
2013/01/23 18:35:45
Do you want to do the same for very long Strings a
| |
158 intptr_t len = 0; | |
159 Dart_Handle res = Dart_ListLength(list, &len); | |
160 ASSERT_NOT_ERROR(res); | |
161 const intptr_t initial_buffer_length = buf->length(); | |
162 // Maximum number of characters we print for array elements. | |
163 const intptr_t max_chars = 256; | |
164 const intptr_t max_buffer_length = initial_buffer_length + max_chars; | |
165 buf->Printf("["); | |
166 for (int i = 0; i < len; i++) { | |
167 if (i > 0) { | |
168 buf->Printf(", "); | |
169 } | |
170 Dart_Handle elem = Dart_ListGetAt(list, i); | |
srdjan
2013/01/23 18:35:45
Instead of adding and checking if buffer exceeded,
| |
171 FormatTextualListElement(buf, elem); | |
172 if (buf->length() > max_buffer_length) { | |
173 buf->Printf(", ..."); | |
174 break; | |
175 } | |
176 } | |
177 buf->Printf("]"); | |
178 } | |
179 | |
180 | |
181 static void FormatTextualValue(dart::TextBuffer* buf, | |
182 Dart_Handle object) { | |
183 if (Dart_IsList(object)) { | |
184 FormatTextualListValue(buf, object); | |
185 } else if (Dart_IsNull(object)) { | |
186 buf->Printf("null"); | |
187 } else { | |
188 Dart_Handle text = Dart_ToString(object); | |
189 if (Dart_IsNull(text)) { | |
190 buf->Printf("null"); | |
191 } else if (Dart_IsError(text)) { | |
192 buf->Printf("#ERROR"); | |
193 } else { | |
194 FormatEncodedChars(buf, text); | |
195 } | |
196 } | |
197 } | |
198 | |
167 | 199 |
168 static void FormatValue(dart::TextBuffer* buf, Dart_Handle object) { | 200 static void FormatValue(dart::TextBuffer* buf, Dart_Handle object) { |
169 if (Dart_IsInteger(object)) { | 201 if (Dart_IsInteger(object)) { |
170 buf->Printf("\"kind\":\"integer\","); | 202 buf->Printf("\"kind\":\"integer\","); |
171 } else if (Dart_IsString(object)) { | 203 } else if (Dart_IsString(object)) { |
172 buf->Printf("\"kind\":\"string\","); | 204 buf->Printf("\"kind\":\"string\","); |
173 } else if (Dart_IsBoolean(object)) { | 205 } else if (Dart_IsBoolean(object)) { |
174 buf->Printf("\"kind\":\"boolean\","); | 206 buf->Printf("\"kind\":\"boolean\","); |
175 } else if (Dart_IsList(object)) { | 207 } else if (Dart_IsList(object)) { |
176 intptr_t len = 0; | 208 intptr_t len = 0; |
177 Dart_Handle res = Dart_ListLength(object, &len); | 209 Dart_Handle res = Dart_ListLength(object, &len); |
178 ASSERT_NOT_ERROR(res); | 210 ASSERT_NOT_ERROR(res); |
179 buf->Printf("\"kind\":\"list\",\"length\":%"Pd",", len); | 211 buf->Printf("\"kind\":\"list\",\"length\":%"Pd",", len); |
180 } else { | 212 } else { |
181 buf->Printf("\"kind\":\"object\","); | 213 buf->Printf("\"kind\":\"object\","); |
182 } | 214 } |
215 buf->Printf("\"text\":\""); | |
183 FormatTextualValue(buf, object); | 216 FormatTextualValue(buf, object); |
217 buf->Printf("\""); | |
184 } | 218 } |
185 | 219 |
186 | 220 |
187 static void FormatValueObj(dart::TextBuffer* buf, Dart_Handle object) { | 221 static void FormatValueObj(dart::TextBuffer* buf, Dart_Handle object) { |
188 buf->Printf("{"); | 222 buf->Printf("{"); |
189 FormatValue(buf, object); | 223 FormatValue(buf, object); |
190 buf->Printf("}"); | 224 buf->Printf("}"); |
191 } | 225 } |
192 | 226 |
193 | 227 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 msg_queue->SendIsolateEvent(isolate_id, kind); | 1125 msg_queue->SendIsolateEvent(isolate_id, kind); |
1092 if (kind == kInterrupted) { | 1126 if (kind == kInterrupted) { |
1093 msg_queue->HandleMessages(); | 1127 msg_queue->HandleMessages(); |
1094 } else { | 1128 } else { |
1095 ASSERT(kind == kShutdown); | 1129 ASSERT(kind == kShutdown); |
1096 RemoveIsolateMsgQueue(isolate_id); | 1130 RemoveIsolateMsgQueue(isolate_id); |
1097 } | 1131 } |
1098 } | 1132 } |
1099 Dart_ExitScope(); | 1133 Dart_ExitScope(); |
1100 } | 1134 } |
OLD | NEW |