| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 | 6 |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 #include "vm/json_stream.h" | 9 #include "vm/json_stream.h" |
| 10 #include "vm/message.h" | 10 #include "vm/message.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 string_iterator ^= option_values.At(i); | 73 string_iterator ^= option_values.At(i); |
| 74 option_values_native[i] = | 74 option_values_native[i] = |
| 75 zone->MakeCopyOfString(string_iterator.ToCString()); | 75 zone->MakeCopyOfString(string_iterator.ToCString()); |
| 76 } | 76 } |
| 77 SetOptions(option_keys_native, option_values_native, option_keys.Length()); | 77 SetOptions(option_keys_native, option_values_native, option_keys.Length()); |
| 78 } | 78 } |
| 79 if (FLAG_trace_service) { | 79 if (FLAG_trace_service) { |
| 80 Isolate* isolate = Isolate::Current(); | 80 Isolate* isolate = Isolate::Current(); |
| 81 ASSERT(isolate != NULL); | 81 ASSERT(isolate != NULL); |
| 82 const char* isolate_name = isolate->name(); | 82 const char* isolate_name = isolate->name(); |
| 83 OS::Print("Isolate %s processing service request /%s\n", | 83 OS::Print("Isolate %s processing service request /%s", |
| 84 isolate_name, command_); | 84 isolate_name, command_); |
| 85 for (intptr_t i = 1; i < num_arguments(); i++) { |
| 86 OS::Print("/%s", GetArgument(i)); |
| 87 } |
| 88 OS::Print("\n"); |
| 85 setup_time_micros_ = OS::GetCurrentTimeMicros(); | 89 setup_time_micros_ = OS::GetCurrentTimeMicros(); |
| 86 } | 90 } |
| 87 } | 91 } |
| 88 | 92 |
| 89 | 93 |
| 90 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 94 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 91 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 95 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 92 return reinterpret_cast<uint8_t*>(new_ptr); | 96 return reinterpret_cast<uint8_t*>(new_ptr); |
| 93 } | 97 } |
| 94 | 98 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 107 uint8_t* data = NULL; | 111 uint8_t* data = NULL; |
| 108 MessageWriter writer(&data, &allocator); | 112 MessageWriter writer(&data, &allocator); |
| 109 writer.WriteMessage(reply); | 113 writer.WriteMessage(reply); |
| 110 PortMap::PostMessage(new Message(port, data, | 114 PortMap::PostMessage(new Message(port, data, |
| 111 writer.BytesWritten(), | 115 writer.BytesWritten(), |
| 112 Message::kNormalPriority)); | 116 Message::kNormalPriority)); |
| 113 if (FLAG_trace_service) { | 117 if (FLAG_trace_service) { |
| 114 Isolate* isolate = Isolate::Current(); | 118 Isolate* isolate = Isolate::Current(); |
| 115 ASSERT(isolate != NULL); | 119 ASSERT(isolate != NULL); |
| 116 const char* isolate_name = isolate->name(); | 120 const char* isolate_name = isolate->name(); |
| 117 OS::Print("Isolate %s processed service request /%s in %" Pd64" us.\n", | 121 OS::Print("Isolate %s processed service request /%s", |
| 118 isolate_name, command_, process_delta_micros); | 122 isolate_name, command_); |
| 123 for (intptr_t i = 1; i < num_arguments(); i++) { |
| 124 OS::Print("/%s", GetArgument(i)); |
| 125 } |
| 126 OS::Print(" in %" Pd64" us.\n", process_delta_micros); |
| 119 } | 127 } |
| 120 } | 128 } |
| 121 | 129 |
| 122 | 130 |
| 123 const char* JSONStream::LookupOption(const char* key) const { | 131 const char* JSONStream::LookupOption(const char* key) const { |
| 124 for (int i = 0; i < num_options(); i++) { | 132 for (int i = 0; i < num_options(); i++) { |
| 125 if (!strcmp(key, option_keys_[i])) { | 133 if (!strcmp(key, option_keys_[i])) { |
| 126 return option_values_[i]; | 134 return option_values_[i]; |
| 127 } | 135 } |
| 128 } | 136 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 198 |
| 191 void JSONStream::PrintValue(double d) { | 199 void JSONStream::PrintValue(double d) { |
| 192 PrintCommaIfNeeded(); | 200 PrintCommaIfNeeded(); |
| 193 buffer_.Printf("%f", d); | 201 buffer_.Printf("%f", d); |
| 194 } | 202 } |
| 195 | 203 |
| 196 | 204 |
| 197 void JSONStream::PrintValue(const char* s) { | 205 void JSONStream::PrintValue(const char* s) { |
| 198 PrintCommaIfNeeded(); | 206 PrintCommaIfNeeded(); |
| 199 buffer_.AddChar('"'); | 207 buffer_.AddChar('"'); |
| 200 buffer_.AddEscapedString(s); | 208 buffer_.AddEscapedUTF8String(s); |
| 201 buffer_.AddChar('"'); | 209 buffer_.AddChar('"'); |
| 202 } | 210 } |
| 203 | 211 |
| 204 | 212 |
| 205 void JSONStream::PrintfValue(const char* format, ...) { | 213 void JSONStream::PrintfValue(const char* format, ...) { |
| 206 PrintCommaIfNeeded(); | 214 PrintCommaIfNeeded(); |
| 207 | 215 |
| 208 va_list args; | 216 va_list args; |
| 209 va_start(args, format); | 217 va_start(args, format); |
| 210 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 218 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 211 va_end(args); | 219 va_end(args); |
| 212 char* p = reinterpret_cast<char*>(malloc(len+1)); | 220 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 213 va_start(args, format); | 221 va_start(args, format); |
| 214 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 222 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 215 va_end(args); | 223 va_end(args); |
| 216 ASSERT(len == len2); | 224 ASSERT(len == len2); |
| 217 buffer_.AddChar('"'); | 225 buffer_.AddChar('"'); |
| 218 buffer_.AddEscapedString(p); | 226 buffer_.AddEscapedUTF8String(p); |
| 219 buffer_.AddChar('"'); | 227 buffer_.AddChar('"'); |
| 220 free(p); | 228 free(p); |
| 221 } | 229 } |
| 222 | 230 |
| 223 | 231 |
| 224 void JSONStream::PrintValue(const Object& o, bool ref) { | 232 void JSONStream::PrintValue(const Object& o, bool ref) { |
| 225 PrintCommaIfNeeded(); | 233 PrintCommaIfNeeded(); |
| 226 o.PrintToJSONStream(this, ref); | 234 o.PrintToJSONStream(this, ref); |
| 227 } | 235 } |
| 228 | 236 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 va_list args; | 276 va_list args; |
| 269 va_start(args, format); | 277 va_start(args, format); |
| 270 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 278 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 271 va_end(args); | 279 va_end(args); |
| 272 char* p = reinterpret_cast<char*>(malloc(len+1)); | 280 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 273 va_start(args, format); | 281 va_start(args, format); |
| 274 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 282 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 275 va_end(args); | 283 va_end(args); |
| 276 ASSERT(len == len2); | 284 ASSERT(len == len2); |
| 277 buffer_.AddChar('"'); | 285 buffer_.AddChar('"'); |
| 278 buffer_.AddEscapedString(p); | 286 buffer_.AddEscapedUTF8String(p); |
| 279 buffer_.AddChar('"'); | 287 buffer_.AddChar('"'); |
| 280 free(p); | 288 free(p); |
| 281 } | 289 } |
| 282 | 290 |
| 283 | 291 |
| 284 void JSONStream::set_reply_port(Dart_Port port) { | 292 void JSONStream::set_reply_port(Dart_Port port) { |
| 285 reply_port_ = port; | 293 reply_port_ = port; |
| 286 } | 294 } |
| 287 | 295 |
| 288 | 296 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 304 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { | 312 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { |
| 305 PrintPropertyName(name); | 313 PrintPropertyName(name); |
| 306 PrintValue(o, ref); | 314 PrintValue(o, ref); |
| 307 } | 315 } |
| 308 | 316 |
| 309 | 317 |
| 310 void JSONStream::PrintPropertyName(const char* name) { | 318 void JSONStream::PrintPropertyName(const char* name) { |
| 311 ASSERT(name != NULL); | 319 ASSERT(name != NULL); |
| 312 PrintCommaIfNeeded(); | 320 PrintCommaIfNeeded(); |
| 313 buffer_.AddChar('"'); | 321 buffer_.AddChar('"'); |
| 314 buffer_.AddEscapedString(name); | 322 buffer_.AddEscapedUTF8String(name); |
| 315 buffer_.AddChar('"'); | 323 buffer_.AddChar('"'); |
| 316 buffer_.AddChar(':'); | 324 buffer_.AddChar(':'); |
| 317 } | 325 } |
| 318 | 326 |
| 319 | 327 |
| 320 void JSONStream::PrintCommaIfNeeded() { | 328 void JSONStream::PrintCommaIfNeeded() { |
| 321 if (NeedComma()) { | 329 if (NeedComma()) { |
| 322 buffer_.AddChar(','); | 330 buffer_.AddChar(','); |
| 323 } | 331 } |
| 324 } | 332 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 346 va_list args; | 354 va_list args; |
| 347 va_start(args, format); | 355 va_start(args, format); |
| 348 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 356 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 349 va_end(args); | 357 va_end(args); |
| 350 char* p = reinterpret_cast<char*>(malloc(len+1)); | 358 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 351 va_start(args, format); | 359 va_start(args, format); |
| 352 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 360 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 353 va_end(args); | 361 va_end(args); |
| 354 ASSERT(len == len2); | 362 ASSERT(len == len2); |
| 355 stream_->buffer_.AddChar('"'); | 363 stream_->buffer_.AddChar('"'); |
| 356 stream_->buffer_.AddEscapedString(p); | 364 stream_->buffer_.AddEscapedUTF8String(p); |
| 357 stream_->buffer_.AddChar('"'); | 365 stream_->buffer_.AddChar('"'); |
| 358 free(p); | 366 free(p); |
| 359 } | 367 } |
| 360 | 368 |
| 361 | 369 |
| 362 void JSONArray::AddValueF(const char* format, ...) const { | 370 void JSONArray::AddValueF(const char* format, ...) const { |
| 363 stream_->PrintCommaIfNeeded(); | 371 stream_->PrintCommaIfNeeded(); |
| 364 va_list args; | 372 va_list args; |
| 365 va_start(args, format); | 373 va_start(args, format); |
| 366 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 374 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 367 va_end(args); | 375 va_end(args); |
| 368 char* p = reinterpret_cast<char*>(malloc(len+1)); | 376 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 369 va_start(args, format); | 377 va_start(args, format); |
| 370 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 378 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 371 va_end(args); | 379 va_end(args); |
| 372 ASSERT(len == len2); | 380 ASSERT(len == len2); |
| 373 stream_->buffer_.AddChar('"'); | 381 stream_->buffer_.AddChar('"'); |
| 374 stream_->buffer_.AddEscapedString(p); | 382 stream_->buffer_.AddEscapedUTF8String(p); |
| 375 stream_->buffer_.AddChar('"'); | 383 stream_->buffer_.AddChar('"'); |
| 376 free(p); | 384 free(p); |
| 377 } | 385 } |
| 378 | 386 |
| 379 } // namespace dart | 387 } // namespace dart |
| OLD | NEW |