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

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

Issue 12040053: More length restrictions in debugger protocol (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | « no previous file | 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 FormatEncodedCharsTrunc(dart::TextBuffer* buf,
109 Dart_Handle str,
110 intptr_t max_chars) {
111 intptr_t str_len = 0;
112 Dart_Handle res = Dart_StringLength(str, &str_len);
113 ASSERT_NOT_ERROR(res);
114 intptr_t num_chars = (str_len > max_chars) ? max_chars : str_len;
115 uint16_t* codepoints =
116 reinterpret_cast<uint16_t*>(malloc(num_chars * sizeof(uint16_t)));
117 ASSERT(codepoints != NULL);
118 intptr_t actual_len = num_chars;
119 res = Dart_StringToUTF16(str, codepoints, &actual_len);
120 ASSERT_NOT_ERROR(res);
121 ASSERT(num_chars == actual_len);
122 for (int i = 0; i < num_chars; i++) {
123 buf->AddEscapedChar(codepoints[i]);
124 }
125 if (str_len > max_chars) {
126 buf->Printf("...");
127 }
128 free(codepoints);
129 }
130
131
108 static void FormatEncodedChars(dart::TextBuffer* buf, Dart_Handle str) { 132 static void FormatEncodedChars(dart::TextBuffer* buf, Dart_Handle str) {
109 intptr_t str_len = 0; 133 intptr_t str_len = 0;
110 Dart_Handle res = Dart_StringLength(str, &str_len); 134 Dart_Handle res = Dart_StringLength(str, &str_len);
111 ASSERT_NOT_ERROR(res); 135 ASSERT_NOT_ERROR(res);
112 uint16_t* codepoints = 136 uint16_t* codepoints =
113 reinterpret_cast<uint16_t*>(malloc(str_len * sizeof(uint16_t))); 137 reinterpret_cast<uint16_t*>(malloc(str_len * sizeof(uint16_t)));
114 ASSERT(codepoints != NULL); 138 ASSERT(codepoints != NULL);
115 intptr_t actual_len = str_len; 139 intptr_t actual_len = str_len;
116 res = Dart_StringToUTF16(str, codepoints, &actual_len); 140 res = Dart_StringToUTF16(str, codepoints, &actual_len);
117 ASSERT_NOT_ERROR(res); 141 ASSERT_NOT_ERROR(res);
118 ASSERT(str_len == actual_len); 142 ASSERT(str_len == actual_len);
119 for (int i = 0; i < str_len; i++) { 143 for (int i = 0; i < str_len; i++) {
120 buf->AddEscapedChar(codepoints[i]); 144 buf->AddEscapedChar(codepoints[i]);
121 } 145 }
122 free(codepoints); 146 free(codepoints);
123 } 147 }
124 148
125 149
126 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) { 150 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) {
127 buf->AddChar('\"'); 151 buf->AddChar('\"');
128 FormatEncodedChars(buf, str); 152 FormatEncodedChars(buf, str);
129 buf->AddChar('\"'); 153 buf->AddChar('\"');
130 } 154 }
131 155
132 156
133 static void FormatTextualListElement(dart::TextBuffer* buf, 157 static void FormatTextualValue(dart::TextBuffer* buf,
134 Dart_Handle object) { 158 Dart_Handle object,
135 if (Dart_IsList(object)) { 159 intptr_t max_chars);
136 buf->Printf("[...]");
137 } else if (Dart_IsNull(object)) {
138 buf->Printf("null");
139 } else if (Dart_IsError(object)) {
140 buf->Printf("#ERROR");
141 } else {
142 const bool need_quotes = Dart_IsString(object);
143 Dart_Handle text = Dart_ToString(object);
144 if (need_quotes) buf->Printf("\\\"");
145 if (Dart_IsNull(text)) {
146 buf->Printf("null");
147 } else if (Dart_IsError(text)) {
148 buf->Printf("#ERROR");
149 } else {
150 FormatEncodedChars(buf, text);
151 }
152 if (need_quotes) buf->Printf("\\\"");
153 }
154 }
155 160
156 161
157 static void FormatTextualListValue(dart::TextBuffer* buf, Dart_Handle list) { 162 static void FormatTextualListValue(dart::TextBuffer* buf,
163 Dart_Handle list,
164 intptr_t max_chars) {
158 intptr_t len = 0; 165 intptr_t len = 0;
159 Dart_Handle res = Dart_ListLength(list, &len); 166 Dart_Handle res = Dart_ListLength(list, &len);
160 ASSERT_NOT_ERROR(res); 167 ASSERT_NOT_ERROR(res);
161 const intptr_t initial_buffer_length = buf->length(); 168 const intptr_t initial_buffer_length = buf->length();
162 // Maximum number of characters we print for array elements. 169 // 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; 170 const intptr_t max_buffer_length = initial_buffer_length + max_chars;
165 buf->Printf("["); 171 buf->Printf("[");
166 for (int i = 0; i < len; i++) { 172 for (int i = 0; i < len; i++) {
167 if (i > 0) { 173 if (i > 0) {
168 buf->Printf(", "); 174 buf->Printf(", ");
169 } 175 }
170 Dart_Handle elem = Dart_ListGetAt(list, i); 176 Dart_Handle elem = Dart_ListGetAt(list, i);
171 FormatTextualListElement(buf, elem); 177 const intptr_t max_element_chars = 50;
178 FormatTextualValue(buf, elem, max_element_chars);
172 if (buf->length() > max_buffer_length) { 179 if (buf->length() > max_buffer_length) {
173 buf->Printf(", ..."); 180 buf->Printf(", ...");
174 break; 181 break;
175 } 182 }
176 } 183 }
177 buf->Printf("]"); 184 buf->Printf("]");
178 } 185 }
179 186
180 187
181 static void FormatTextualValue(dart::TextBuffer* buf, 188 static void FormatTextualValue(dart::TextBuffer* buf,
182 Dart_Handle object) { 189 Dart_Handle object,
190 intptr_t max_chars) {
183 if (Dart_IsList(object)) { 191 if (Dart_IsList(object)) {
184 FormatTextualListValue(buf, object); 192 FormatTextualListValue(buf, object, max_chars);
185 } else if (Dart_IsNull(object)) { 193 } else if (Dart_IsNull(object)) {
186 buf->Printf("null"); 194 buf->Printf("null");
195 } else if (Dart_IsString(object)) {
196 buf->Printf("\\\"");
197 FormatEncodedCharsTrunc(buf, object, max_chars);
198 buf->Printf("\\\"");
187 } else { 199 } else {
188 Dart_Handle text = Dart_ToString(object); 200 Dart_Handle text = Dart_ToString(object);
189 if (Dart_IsNull(text)) { 201 if (Dart_IsNull(text)) {
190 buf->Printf("null"); 202 buf->Printf("null");
191 } else if (Dart_IsError(text)) { 203 } else if (Dart_IsError(text)) {
192 buf->Printf("#ERROR"); 204 buf->Printf("#ERROR");
193 } else { 205 } else {
194 FormatEncodedChars(buf, text); 206 FormatEncodedCharsTrunc(buf, text, max_chars);
195 } 207 }
196 } 208 }
197 } 209 }
198 210
199 211
200 static void FormatValue(dart::TextBuffer* buf, Dart_Handle object) { 212 static void FormatValue(dart::TextBuffer* buf, Dart_Handle object) {
201 if (Dart_IsInteger(object)) { 213 if (Dart_IsInteger(object)) {
202 buf->Printf("\"kind\":\"integer\","); 214 buf->Printf("\"kind\":\"integer\",");
203 } else if (Dart_IsString(object)) { 215 } else if (Dart_IsString(object)) {
204 buf->Printf("\"kind\":\"string\","); 216 buf->Printf("\"kind\":\"string\",");
205 } else if (Dart_IsBoolean(object)) { 217 } else if (Dart_IsBoolean(object)) {
206 buf->Printf("\"kind\":\"boolean\","); 218 buf->Printf("\"kind\":\"boolean\",");
207 } else if (Dart_IsList(object)) { 219 } else if (Dart_IsList(object)) {
208 intptr_t len = 0; 220 intptr_t len = 0;
209 Dart_Handle res = Dart_ListLength(object, &len); 221 Dart_Handle res = Dart_ListLength(object, &len);
210 ASSERT_NOT_ERROR(res); 222 ASSERT_NOT_ERROR(res);
211 buf->Printf("\"kind\":\"list\",\"length\":%"Pd",", len); 223 buf->Printf("\"kind\":\"list\",\"length\":%"Pd",", len);
212 } else { 224 } else {
213 buf->Printf("\"kind\":\"object\","); 225 buf->Printf("\"kind\":\"object\",");
214 } 226 }
215 buf->Printf("\"text\":\""); 227 buf->Printf("\"text\":\"");
216 FormatTextualValue(buf, object); 228 const intptr_t max_chars = 250;
229 FormatTextualValue(buf, object, max_chars);
217 buf->Printf("\""); 230 buf->Printf("\"");
218 } 231 }
219 232
220 233
221 static void FormatValueObj(dart::TextBuffer* buf, Dart_Handle object) { 234 static void FormatValueObj(dart::TextBuffer* buf, Dart_Handle object) {
222 buf->Printf("{"); 235 buf->Printf("{");
223 FormatValue(buf, object); 236 FormatValue(buf, object);
224 buf->Printf("}"); 237 buf->Printf("}");
225 } 238 }
226 239
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 msg_queue->SendIsolateEvent(isolate_id, kind); 1138 msg_queue->SendIsolateEvent(isolate_id, kind);
1126 if (kind == kInterrupted) { 1139 if (kind == kInterrupted) {
1127 msg_queue->HandleMessages(); 1140 msg_queue->HandleMessages();
1128 } else { 1141 } else {
1129 ASSERT(kind == kShutdown); 1142 ASSERT(kind == kShutdown);
1130 RemoveIsolateMsgQueue(isolate_id); 1143 RemoveIsolateMsgQueue(isolate_id);
1131 } 1144 }
1132 } 1145 }
1133 Dart_ExitScope(); 1146 Dart_ExitScope();
1134 } 1147 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698