Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 buffer_.Printf("{\"result\":"); | 72 buffer_.Printf("{\"result\":"); |
| 73 } | 73 } |
| 74 | 74 |
| 75 | 75 |
| 76 void JSONStream::SetupError() { | 76 void JSONStream::SetupError() { |
| 77 buffer_.Clear(); | 77 buffer_.Clear(); |
| 78 buffer_.Printf("{\"error\":"); | 78 buffer_.Printf("{\"error\":"); |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 static const char* GetJSONRpcErrorMessage(intptr_t code) { | |
| 83 switch (code) { | |
| 84 case kParseError: | |
| 85 return "Parse error"; | |
| 86 case kInvalidRequest: | |
| 87 return "Invalid Request"; | |
| 88 case kMethodNotFound: | |
| 89 return "Method not found"; | |
| 90 case kInvalidParams: | |
| 91 return "Invalid params"; | |
| 92 case kInternalError: | |
| 93 return "Internal error"; | |
| 94 case kVMMustBePaused: | |
| 95 return "VM must be paused"; | |
| 96 case kNoBreakAtLine: | |
| 97 return "Cannot set breakpoint at line"; | |
| 98 case kNoBreakAtFunction: | |
| 99 return "Cannot set breakpoint at function"; | |
| 100 case kProfilingDisabled: | |
| 101 return "Profiling is disabled"; | |
| 102 default: | |
| 103 UNIMPLEMENTED(); | |
| 104 return "Unexpected rpc error code"; | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 | |
| 109 static void PrintRequest(JSONObject* obj, JSONStream* js) { | |
| 110 JSONObject jsobj(obj, "request"); | |
| 111 jsobj.AddProperty("method", js->method()); | |
| 112 { | |
| 113 JSONObject params(&jsobj, "params"); | |
| 114 for (intptr_t i = 0; i < js->num_params(); i++) { | |
| 115 params.AddProperty(js->GetParamKey(i), js->GetParamValue(i)); | |
| 116 } | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 | |
| 121 void JSONStream::PrintError(intptr_t code, | |
| 122 const char* details_format, ...) { | |
| 123 SetupError(); | |
| 124 JSONObject jsobj(this); | |
| 125 jsobj.AddProperty("code", code); | |
| 126 jsobj.AddProperty("message", GetJSONRpcErrorMessage(code)); | |
| 127 { | |
| 128 JSONObject data(&jsobj, "data"); | |
| 129 PrintRequest(&data, this); | |
| 130 if (details_format != NULL) { | |
| 131 Isolate* isolate = Isolate::Current(); | |
| 132 | |
| 133 va_list args; | |
| 134 va_start(args, details_format); | |
| 135 intptr_t len = OS::VSNPrint(NULL, 0, details_format, args); | |
| 136 va_end(args); | |
| 137 | |
| 138 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
|
Cutch
2015/05/13 17:50:10
zone->PrintToString ?
turnidge
2015/05/14 17:53:43
We would need to add a new version of zone->PrintT
| |
| 139 va_list args2; | |
| 140 va_start(args2, details_format); | |
| 141 OS::VSNPrint(buffer, (len + 1), details_format, args2); | |
| 142 va_end(args2); | |
| 143 | |
| 144 data.AddProperty("details", buffer); | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 | |
| 82 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 150 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 83 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 151 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 84 return reinterpret_cast<uint8_t*>(new_ptr); | 152 return reinterpret_cast<uint8_t*>(new_ptr); |
| 85 } | 153 } |
| 86 | 154 |
| 87 | 155 |
| 88 void JSONStream::PostReply() { | 156 void JSONStream::PostReply() { |
| 89 Dart_Port port = reply_port(); | 157 Dart_Port port = reply_port(); |
| 90 ASSERT(port != ILLEGAL_PORT); | 158 ASSERT(port != ILLEGAL_PORT); |
| 91 set_reply_port(ILLEGAL_PORT); // Prevent double replies. | 159 set_reply_port(ILLEGAL_PORT); // Prevent double replies. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 578 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 511 va_end(args); | 579 va_end(args); |
| 512 ASSERT(len == len2); | 580 ASSERT(len == len2); |
| 513 stream_->buffer_.AddChar('"'); | 581 stream_->buffer_.AddChar('"'); |
| 514 stream_->AddEscapedUTF8String(p); | 582 stream_->AddEscapedUTF8String(p); |
| 515 stream_->buffer_.AddChar('"'); | 583 stream_->buffer_.AddChar('"'); |
| 516 free(p); | 584 free(p); |
| 517 } | 585 } |
| 518 | 586 |
| 519 } // namespace dart | 587 } // namespace dart |
| OLD | NEW |