Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index f17949f6a51ea77d23933e04b62fc7a82e94c6f7..ae7a10c84e0332f615ec1145f358f514fe5c156b 100644 |
--- a/runtime/vm/service.cc |
+++ b/runtime/vm/service.cc |
@@ -50,81 +50,23 @@ static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
return reinterpret_cast<uint8_t*>(new_ptr); |
} |
-static void PrintRequest(const JSONObject& obj, JSONStream* js) { |
- JSONObject jsobj(&obj, "request"); |
- jsobj.AddProperty("method", js->method()); |
- { |
- JSONObject params(&jsobj, "params"); |
- for (intptr_t i = 0; i < js->num_params(); i++) { |
- params.AddProperty(js->GetParamKey(i), js->GetParamValue(i)); |
- } |
- } |
-} |
- |
- |
-static void PrintError(JSONStream* js, |
- const char* format, ...) { |
- Isolate* isolate = Isolate::Current(); |
- |
- va_list args; |
- va_start(args, format); |
- intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
- va_end(args); |
- |
- char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
- va_list args2; |
- va_start(args2, format); |
- OS::VSNPrint(buffer, (len + 1), format, args2); |
- va_end(args2); |
- |
- JSONObject jsobj(js); |
- jsobj.AddProperty("type", "Error"); |
- jsobj.AddProperty("message", buffer); |
- PrintRequest(jsobj, js); |
-} |
- |
- |
static void PrintMissingParamError(JSONStream* js, |
const char* param) { |
- PrintError(js, "%s expects the '%s' parameter", |
- js->method(), param); |
+ js->PrintError(kInvalidParams, |
+ "%s expects the '%s' parameter", js->method(), param); |
} |
static void PrintInvalidParamError(JSONStream* js, |
const char* param) { |
- PrintError(js, "%s: invalid '%s' parameter: %s", |
- js->method(), param, js->LookupParam(param)); |
+ js->PrintError(kInvalidParams, |
+ "%s: invalid '%s' parameter: %s", |
+ js->method(), param, js->LookupParam(param)); |
} |
static void PrintUnrecognizedMethodError(JSONStream* js) { |
- PrintError(js, "unrecognized method: %s", js->method()); |
-} |
- |
- |
-static void PrintErrorWithKind(JSONStream* js, |
- const char* kind, |
- const char* format, ...) { |
- Isolate* isolate = Isolate::Current(); |
- |
- va_list args; |
- va_start(args, format); |
- intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
- va_end(args); |
- |
- char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
- va_list args2; |
- va_start(args2, format); |
- OS::VSNPrint(buffer, (len + 1), format, args2); |
- va_end(args2); |
- |
- JSONObject jsobj(js); |
- jsobj.AddProperty("type", "Error"); |
- jsobj.AddProperty("id", ""); |
- jsobj.AddProperty("kind", kind); |
- jsobj.AddProperty("message", buffer); |
- PrintRequest(jsobj, js); |
+ js->PrintError(kMethodNotFound, NULL); |
} |
@@ -1202,9 +1144,10 @@ static bool PrintMessage(JSONStream* js, Isolate* isolate, const char* id) { |
isolate->message_handler()->AcquireQueues(&aq); |
Message* message = aq.queue()->FindMessageById(message_id); |
if (message == NULL) { |
- printf("Could not find message %" Px "\n", message_id); |
- // Not found. |
- return false; |
+ // The user may try to load an expired message, so we treat |
+ // unrecognized ids as if they are expired. |
+ PrintSentinel(js, "objects/expired", "<expired>"); |
Cutch
2015/05/13 17:50:10
Should PrintSentinel take an enum and handle setti
turnidge
2015/05/14 17:53:43
Done.
|
+ return true; |
} |
SnapshotReader reader(message->data(), |
message->len(), |
@@ -1214,8 +1157,6 @@ static bool PrintMessage(JSONStream* js, Isolate* isolate, const char* id) { |
const Object& msg_obj = Object::Handle(reader.ReadObject()); |
msg_obj.PrintJSON(js); |
return true; |
- } else { |
- printf("Could not get id from %s\n", rest); |
} |
} |
return false; |
@@ -1283,7 +1224,7 @@ static bool GetInboundReferences(Isolate* isolate, JSONStream* js) { |
return true; |
} |
const char* limit_cstr = js->LookupParam("limit"); |
- if (target_id == NULL) { |
+ if (limit_cstr == NULL) { |
PrintMissingParamError(js, "limit"); |
return true; |
} |
@@ -1301,17 +1242,12 @@ static bool GetInboundReferences(Isolate* isolate, JSONStream* js) { |
} |
if (obj.raw() == Object::sentinel().raw()) { |
if (lookup_result == ObjectIdRing::kCollected) { |
- PrintErrorWithKind( |
- js, "InboundReferencesCollected", |
- "attempt to find a retaining path for a collected object\n"); |
- return true; |
+ PrintSentinel(js, "objects/collected", "<collected>"); |
} else if (lookup_result == ObjectIdRing::kExpired) { |
- PrintErrorWithKind( |
- js, "InboundReferencesExpired", |
- "attempt to find a retaining path for an expired object\n"); |
- return true; |
+ PrintSentinel(js, "objects/expired", "<expired>"); |
+ } else { |
+ PrintInvalidParamError(js, "targetId"); |
} |
- PrintInvalidParamError(js, "targetId"); |
return true; |
} |
return PrintInboundReferences(isolate, &obj, limit, js); |
@@ -1387,7 +1323,7 @@ static bool GetRetainingPath(Isolate* isolate, JSONStream* js) { |
return true; |
} |
const char* limit_cstr = js->LookupParam("limit"); |
- if (target_id == NULL) { |
+ if (limit_cstr == NULL) { |
PrintMissingParamError(js, "limit"); |
return true; |
} |
@@ -1405,17 +1341,12 @@ static bool GetRetainingPath(Isolate* isolate, JSONStream* js) { |
} |
if (obj.raw() == Object::sentinel().raw()) { |
if (lookup_result == ObjectIdRing::kCollected) { |
- PrintErrorWithKind( |
- js, "RetainingPathCollected", |
- "attempt to find a retaining path for a collected object\n"); |
- return true; |
+ PrintSentinel(js, "objects/collected", "<collected>"); |
} else if (lookup_result == ObjectIdRing::kExpired) { |
- PrintErrorWithKind( |
- js, "RetainingPathExpired", |
- "attempt to find a retaining path for an expired object\n"); |
- return true; |
+ PrintSentinel(js, "objects/expired", "<expired>"); |
+ } else { |
+ PrintInvalidParamError(js, "targetId"); |
} |
- PrintInvalidParamError(js, "targetId"); |
return true; |
} |
return PrintRetainingPath(isolate, &obj, limit, js); |
@@ -1439,17 +1370,12 @@ static bool GetRetainedSize(Isolate* isolate, JSONStream* js) { |
&lookup_result)); |
if (obj.raw() == Object::sentinel().raw()) { |
if (lookup_result == ObjectIdRing::kCollected) { |
- PrintErrorWithKind( |
- js, "RetainedCollected", |
- "attempt to calculate size retained by a collected object\n"); |
- return true; |
+ PrintSentinel(js, "objects/collected", "<collected>"); |
} else if (lookup_result == ObjectIdRing::kExpired) { |
- PrintErrorWithKind( |
- js, "RetainedExpired", |
- "attempt to calculate size retained by an expired object\n"); |
- return true; |
+ PrintSentinel(js, "objects/expired", "<expired>"); |
+ } else { |
+ PrintInvalidParamError(js, "targetId"); |
} |
- PrintInvalidParamError(js, "targetId"); |
return true; |
} |
if (obj.IsClass()) { |
@@ -1468,9 +1394,10 @@ static bool GetRetainedSize(Isolate* isolate, JSONStream* js) { |
result.PrintJSON(js, true); |
return true; |
} |
- PrintError(js, "%s: Invalid 'targetId' parameter value: " |
- "id '%s' does not correspond to a " |
- "library, class, or instance", js->method(), target_id); |
+ js->PrintError(kInvalidParams, |
+ "%s: invalid 'targetId' parameter: " |
+ "id '%s' does not correspond to a " |
+ "library, class, or instance", js->method(), target_id); |
return true; |
} |
@@ -1534,9 +1461,10 @@ static bool Eval(Isolate* isolate, JSONStream* js) { |
result.PrintJSON(js, true); |
return true; |
} |
- PrintError(js, "%s: Invalid 'targetId' parameter value: " |
- "id '%s' does not correspond to a " |
- "library, class, or instance", js->method(), target_id); |
+ js->PrintError(kInvalidParams, |
+ "%s: invalid 'targetId' parameter: " |
+ "id '%s' does not correspond to a " |
+ "library, class, or instance", js->method(), target_id); |
return true; |
} |
@@ -1612,7 +1540,7 @@ static bool GetInstances(Isolate* isolate, JSONStream* js) { |
return true; |
} |
const char* limit_cstr = js->LookupParam("limit"); |
- if (target_id == NULL) { |
+ if (limit_cstr == NULL) { |
PrintMissingParamError(js, "limit"); |
return true; |
} |
@@ -1743,9 +1671,11 @@ static bool GetHitsOrSites(Isolate* isolate, JSONStream* js, bool as_sites) { |
CodeCoverage::PrintJSON(isolate, js, &ff, as_sites); |
return true; |
} |
- PrintError(js, "%s: Invalid 'targetId' parameter value: " |
- "id '%s' does not correspond to a " |
- "script, library, class, or function", js->method(), target_id); |
+ js->PrintError(kInvalidParams, |
+ "%s: invalid 'targetId' parameter: " |
+ "id '%s' does not correspond to a " |
+ "script, library, class, or function", |
+ js->method(), target_id); |
return true; |
} |
@@ -1796,7 +1726,7 @@ static bool AddBreakpoint(Isolate* isolate, JSONStream* js) { |
SourceBreakpoint* bpt = |
isolate->debugger()->SetBreakpointAtLine(script_url, line); |
if (bpt == NULL) { |
- PrintError(js, "Unable to set breakpoint at line %s", line_param); |
+ js->PrintError(kNoBreakAtLine, NULL); |
return true; |
} |
bpt->PrintJSON(js); |
@@ -1822,9 +1752,7 @@ static bool AddBreakpointAtEntry(Isolate* isolate, JSONStream* js) { |
SourceBreakpoint* bpt = |
isolate->debugger()->SetBreakpointAtEntry(function); |
if (bpt == NULL) { |
- const String& funcName = String::Handle(function.PrettyName()); |
- PrintError(js, "Unable to set breakpoint at function '%s'", |
- funcName.ToCString()); |
+ js->PrintError(kNoBreakAtFunction, NULL); |
return true; |
} |
bpt->PrintJSON(js); |
@@ -1902,7 +1830,7 @@ static bool HandleNativeMetric(Isolate* isolate, |
} |
current = current->next(); |
} |
- PrintError(js, "Native Metric %s not found\n", id); |
+ PrintInvalidParamError(js, "metricId"); |
return true; |
} |
@@ -1949,7 +1877,7 @@ static bool HandleDartMetric(Isolate* isolate, JSONStream* js, const char* id) { |
buffer->AddString(String::Cast(result).ToCString()); |
return true; |
} |
- PrintError(js, "Dart Metric %s not found\n", id); |
+ PrintInvalidParamError(js, "metricId"); |
return true; |
} |
@@ -1998,7 +1926,8 @@ static bool GetIsolateMetric(Isolate* isolate, JSONStream* js) { |
static const char* kMetricIdPrefix = "metrics/"; |
static intptr_t kMetricIdPrefixLen = strlen(kMetricIdPrefix); |
if (strncmp(metric_id, kMetricIdPrefix, kMetricIdPrefixLen) != 0) { |
- PrintError(js, "Metric %s not found\n", metric_id); |
+ PrintInvalidParamError(js, "metricId"); |
+ return true; |
} |
// Check if id begins with "metrics/native/". |
static const char* kNativeMetricIdPrefix = "metrics/native/"; |
@@ -2084,7 +2013,7 @@ static bool Resume(Isolate* isolate, JSONStream* js) { |
return true; |
} |
- PrintError(js, "VM was not paused"); |
+ js->PrintError(kVMMustBePaused, NULL); |
return true; |
} |
@@ -2380,7 +2309,7 @@ static bool GetObject(Isolate* isolate, JSONStream* js) { |
return true; |
} |
- PrintError(js, "Unrecognized object id: %s\n", id); |
+ PrintInvalidParamError(js, "objectId"); |
return true; |
} |