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" |
| 11 #include "vm/metrics.h" |
11 #include "vm/object.h" | 12 #include "vm/object.h" |
12 #include "vm/unicode.h" | 13 #include "vm/unicode.h" |
13 | 14 |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 DECLARE_FLAG(bool, trace_service); | 18 DECLARE_FLAG(bool, trace_service); |
18 | 19 |
19 JSONStream::JSONStream(intptr_t buf_size) | 20 JSONStream::JSONStream(intptr_t buf_size) |
20 : open_objects_(0), | 21 : open_objects_(0), |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 bpt->PrintJSON(this); | 253 bpt->PrintJSON(this); |
253 } | 254 } |
254 | 255 |
255 | 256 |
256 void JSONStream::PrintValue(const DebuggerEvent* event) { | 257 void JSONStream::PrintValue(const DebuggerEvent* event) { |
257 PrintCommaIfNeeded(); | 258 PrintCommaIfNeeded(); |
258 event->PrintJSON(this); | 259 event->PrintJSON(this); |
259 } | 260 } |
260 | 261 |
261 | 262 |
| 263 void JSONStream::PrintValue(Metric* metric) { |
| 264 PrintCommaIfNeeded(); |
| 265 metric->PrintJSON(this); |
| 266 } |
| 267 |
| 268 |
262 void JSONStream::PrintValue(Isolate* isolate, bool ref) { | 269 void JSONStream::PrintValue(Isolate* isolate, bool ref) { |
263 PrintCommaIfNeeded(); | 270 PrintCommaIfNeeded(); |
264 isolate->PrintJSON(this, ref); | 271 isolate->PrintJSON(this, ref); |
265 } | 272 } |
266 | 273 |
267 | 274 |
268 void JSONStream::PrintPropertyBool(const char* name, bool b) { | 275 void JSONStream::PrintPropertyBool(const char* name, bool b) { |
269 PrintPropertyName(name); | 276 PrintPropertyName(name); |
270 PrintValueBool(b); | 277 PrintValueBool(b); |
271 } | 278 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 PrintValue(event); | 313 PrintValue(event); |
307 } | 314 } |
308 | 315 |
309 | 316 |
310 void JSONStream::PrintProperty(const char* name, SourceBreakpoint* bpt) { | 317 void JSONStream::PrintProperty(const char* name, SourceBreakpoint* bpt) { |
311 PrintPropertyName(name); | 318 PrintPropertyName(name); |
312 PrintValue(bpt); | 319 PrintValue(bpt); |
313 } | 320 } |
314 | 321 |
315 | 322 |
| 323 void JSONStream::PrintProperty(const char* name, Metric* metric) { |
| 324 PrintPropertyName(name); |
| 325 PrintValue(metric); |
| 326 } |
| 327 |
316 void JSONStream::PrintProperty(const char* name, Isolate* isolate) { | 328 void JSONStream::PrintProperty(const char* name, Isolate* isolate) { |
317 PrintPropertyName(name); | 329 PrintPropertyName(name); |
318 PrintValue(isolate); | 330 PrintValue(isolate); |
319 } | 331 } |
320 | 332 |
321 | 333 |
322 void JSONStream::PrintfProperty(const char* name, const char* format, ...) { | 334 void JSONStream::PrintfProperty(const char* name, const char* format, ...) { |
323 PrintPropertyName(name); | 335 PrintPropertyName(name); |
324 va_list args; | 336 va_list args; |
325 va_start(args, format); | 337 va_start(args, format); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 intptr_t length = buffer_.length(); | 401 intptr_t length = buffer_.length(); |
390 if (length == 0) { | 402 if (length == 0) { |
391 return false; | 403 return false; |
392 } | 404 } |
393 char ch = buffer[length-1]; | 405 char ch = buffer[length-1]; |
394 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); | 406 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); |
395 } | 407 } |
396 | 408 |
397 | 409 |
398 void JSONStream::AddEscapedUTF8String(const char* s) { | 410 void JSONStream::AddEscapedUTF8String(const char* s) { |
| 411 if (s == NULL) { |
| 412 return; |
| 413 } |
399 intptr_t len = strlen(s); | 414 intptr_t len = strlen(s); |
400 const uint8_t* s8 = reinterpret_cast<const uint8_t*>(s); | 415 const uint8_t* s8 = reinterpret_cast<const uint8_t*>(s); |
401 intptr_t i = 0; | 416 intptr_t i = 0; |
402 for (; i < len; ) { | 417 for (; i < len; ) { |
403 // Extract next UTF8 character. | 418 // Extract next UTF8 character. |
404 int32_t ch = 0; | 419 int32_t ch = 0; |
405 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); | 420 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); |
406 ASSERT(ch_len != 0); | 421 ASSERT(ch_len != 0); |
407 buffer_.AddEscapedChar(ch); | 422 buffer_.AddEscapedChar(ch); |
408 // Move i forward. | 423 // Move i forward. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 462 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
448 va_end(args); | 463 va_end(args); |
449 ASSERT(len == len2); | 464 ASSERT(len == len2); |
450 stream_->buffer_.AddChar('"'); | 465 stream_->buffer_.AddChar('"'); |
451 stream_->AddEscapedUTF8String(p); | 466 stream_->AddEscapedUTF8String(p); |
452 stream_->buffer_.AddChar('"'); | 467 stream_->buffer_.AddChar('"'); |
453 free(p); | 468 free(p); |
454 } | 469 } |
455 | 470 |
456 } // namespace dart | 471 } // namespace dart |
OLD | NEW |